deploy: remote build scripts (build-remote.sh, install-buildkey.ps1) + self-hosted build machine setup

This commit is contained in:
Yun Chan 2026-08-15 13:33:44 +09:00
parent 9e637f09df
commit a206270c3b
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,43 @@
#!/usr/bin/env bash
# 빌드머신(ChanpacaLaptop=linux-x64 / Mac mini=osx-arm64)에서
# git HEAD 소스를 전송해 Cli + Avalonia 셸을 RID별 self-contained publish 하고
# 산출물을 로컬 out/remote/<rid>/ 로 수집한다.
#
# 사용 (Windows Git Bash): bash build/remote/build-remote.sh [linux|mac|all]
# 사전 조건: ssh 별칭 vd-linux / vd-mac (키 인증), 각 머신 ~/.dotnet SDK 8
set -euo pipefail
cd "$(dirname "$0")/../.."
TARGET="${1:-all}"
REMOTE_DIR="build/videodownloader"
push_src() { # $1 = ssh 대상
git archive HEAD | ssh -o BatchMode=yes "$1" "rm -rf $REMOTE_DIR && mkdir -p $REMOTE_DIR && tar -x -C $REMOTE_DIR"
}
build_on() { # $1 = ssh 대상, $2 = RID
echo "==> [$1] publish $2"
ssh -o BatchMode=yes "$1" "cd $REMOTE_DIR && export DOTNET_ROOT=\$HOME/.dotnet && export PATH=\$HOME/.dotnet:\$PATH && \
dotnet publish VideoDownloader.Cli -c Release -r $2 --self-contained -o out/cli-$2 && \
dotnet publish VideoDownloader.Avalonia -c Release -r $2 --self-contained -o out/avalonia-$2 && \
cd out && tar -czf artifacts-$2.tar.gz cli-$2 avalonia-$2"
}
collect() { # $1 = ssh 대상, $2 = RID
mkdir -p "out/remote/$2"
scp -o BatchMode=yes "$1:$REMOTE_DIR/out/artifacts-$2.tar.gz" "out/remote/$2/" && \
tar -xzf "out/remote/$2/artifacts-$2.tar.gz" -C "out/remote/$2" && \
echo " 수집: out/remote/$2/{cli-$2,avalonia-$2}"
}
if [[ "$TARGET" == "linux" || "$TARGET" == "all" ]]; then
push_src vd-linux
build_on vd-linux linux-x64
collect vd-linux linux-x64
fi
if [[ "$TARGET" == "mac" || "$TARGET" == "all" ]]; then
push_src vd-mac
build_on vd-mac osx-arm64
collect vd-mac osx-arm64
fi
echo "완료."

View file

@ -0,0 +1,27 @@
# 빌드머신에 vd-build 공개키 (재)설치 — .env 자격증명으로 접속해 authorized_keys 정리.
# 사용: pwsh -File build\remote\install-buildkey.ps1
$ErrorActionPreference = 'Stop'
$repo = Split-Path $PSScriptRoot -Parent | Split-Path -Parent
$cfg = @{}
Get-Content (Join-Path $repo '.env') | ForEach-Object {
$line = $_.TrimEnd("`r")
if ($line -match '^([A-Z_]+)=(.*)$') { $cfg[$matches[1]] = $matches[2] }
}
$pubkey = (Get-Content "$env:USERPROFILE\.ssh\id_ed25519_vd.pub" -Raw).Trim()
$machines = @(
@{ Name = 'MAC'; Host = $cfg['MAC_OS_HOST']; User = $cfg['MAC_OS_USER']; Pw = $cfg['MAC_OS_PASSWORD'] },
@{ Name = 'LINUX'; Host = $cfg['LINUX_OS_HOST']; User = $cfg['LINUX_OS_USER']; Pw = $cfg['LINUX_OS_PASSWORD'] }
)
foreach ($m in $machines) {
$sec = ConvertTo-SecureString $m.Pw -AsPlainText -Force
$cred = [Management.Automation.PSCredential]::new($m.User, $sec)
$s = New-SSHSession -ComputerName $m.Host -Credential $cred -AcceptKey -ConnectionTimeout 15 -ErrorAction Stop
$cmds = @(
'mkdir -p ~/.ssh && chmod 700 ~/.ssh',
"sed -i '/ vd-build$/d' ~/.ssh/authorized_keys 2>/dev/null; echo '$pubkey' >> ~/.ssh/authorized_keys",
'chmod 600 ~/.ssh/authorized_keys'
)
foreach ($c in $cmds) { Invoke-SSHCommand -SessionId $s.SessionId -Command $c -TimeOut 10 | Out-Null }
Remove-SSHSession -SessionId $s.SessionId | Out-Null
Write-Output "$($m.Name) ($($m.Host)): build key installed"
}