build(deploy): switch hosting to Podman Quadlet
This commit is contained in:
1 parent
10aa0304e4
commit
019b15041a
15 files changed
+312
-134
No files matched your search
@@ -0,0 +1,39 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function ConvertTo-WslPath([string]$Path) {
|
||||
$fullPath = [IO.Path]::GetFullPath($Path)
|
||||
if ($fullPath -notmatch '^([A-Za-z]):\\(.*)$') { throw "Workspace must be on a Windows drive: $fullPath" }
|
||||
$drive = $Matches[1].ToLowerInvariant()
|
||||
$relative = $Matches[2].Replace('\', '/')
|
||||
return "/mnt/$drive/$relative"
|
||||
}
|
||||
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
$repoWsl = ConvertTo-WslPath $repoRoot
|
||||
|
||||
$unitPath = (Resolve-Path (Join-Path $PSScriptRoot '..\deploy\webdrop.container')).Path
|
||||
$unitWsl = ConvertTo-WslPath $unitPath
|
||||
|
||||
$updatePath = (Resolve-Path (Join-Path $PSScriptRoot 'wsl-podman-update.sh')).Path
|
||||
$updateWsl = ConvertTo-WslPath $updatePath
|
||||
|
||||
$commit = (& git -C $repoRoot rev-parse --short=12 HEAD).Trim()
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not read the current Git commit.' }
|
||||
$tagOutput = & git -C $repoRoot describe --tags --exact-match HEAD 2>$null
|
||||
$tag = if ($tagOutput) { "$tagOutput".Trim() } else { 'dev' }
|
||||
$buildTime = [TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTimeOffset]::UtcNow, 'China Standard Time').ToString('yyyy-MM-dd HH:mm')
|
||||
|
||||
$deployHome = '/home/justme/podman/webdrop'
|
||||
$configDir = '/home/justme/.config/containers/systemd'
|
||||
& wsl.exe -d Debian -- mkdir -p $deployHome $configDir
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not create the WSL deployment directories.' }
|
||||
|
||||
& wsl.exe -d Debian -- install -D -m 755 $updateWsl "$deployHome/update.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not install the WSL update script.' }
|
||||
& wsl.exe -d Debian -- install -D -m 644 $unitWsl "$deployHome/webdrop.container"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not install the WebDrop Quadlet.' }
|
||||
& wsl.exe -d Debian -- ln -sfn "$deployHome/webdrop.container" "$configDir/webdrop.container"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not link the Quadlet into the user systemd directory.' }
|
||||
|
||||
& wsl.exe -d Debian -- bash "$deployHome/update.sh" $repoWsl $commit $tag $buildTime
|
||||
if ($LASTEXITCODE -ne 0) { throw 'The WSL Podman build or service update failed.' }
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
source_dir="${1:?Pass the workspace path in WSL format}"
|
||||
frontend_commit="${2:-unknown}"
|
||||
frontend_tag="${3:-dev}"
|
||||
build_time="${4:-unknown}"
|
||||
deploy_dir="$HOME/podman/webdrop"
|
||||
source_dir="$(realpath "$source_dir")"
|
||||
|
||||
# The WSL proxy exports lowercase names; containers/image reads the uppercase names.
|
||||
export HTTP_PROXY="${HTTP_PROXY:-${http_proxy:-}}"
|
||||
export HTTPS_PROXY="${HTTPS_PROXY:-${https_proxy:-}}"
|
||||
export NO_PROXY="${NO_PROXY:-${no_proxy:-}}"
|
||||
|
||||
if [[ ! -f "$source_dir/server/Containerfile" ]]; then
|
||||
echo "Not a WebDrop source tree: $source_dir" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
mkdir -p "$deploy_dir/src" "$deploy_dir/data"
|
||||
|
||||
# Seed the WSL data directory once; later updates leave runtime data untouched.
|
||||
if [[ -d "$source_dir/data" ]] && [[ -z "$(find "$deploy_dir/data" -mindepth 1 -print -quit)" ]]; then
|
||||
rsync -a "$source_dir/data/" "$deploy_dir/data/"
|
||||
fi
|
||||
|
||||
# Keep build inputs on WSL's Linux filesystem, not the slower /mnt/c mount.
|
||||
rsync -a --delete \
|
||||
--exclude='/.git/' \
|
||||
--exclude='/.env' --exclude='/.env.*' \
|
||||
--exclude='/data/' \
|
||||
--exclude='**/node_modules/' --exclude='**/dist/' \
|
||||
--exclude='**/bin/' --exclude='**/obj/' \
|
||||
--exclude='**/*.tsbuildinfo' \
|
||||
"$source_dir/" "$deploy_dir/src/"
|
||||
|
||||
podman build \
|
||||
--layers \
|
||||
--platform linux/amd64 \
|
||||
--format oci \
|
||||
--file "$deploy_dir/src/server/Containerfile" \
|
||||
--tag localhost/webdrop:local \
|
||||
--build-arg "WEBDROP_FRONTEND_COMMIT=$frontend_commit" \
|
||||
--build-arg "WEBDROP_FRONTEND_TAG=$frontend_tag" \
|
||||
--build-arg "WEBDROP_BACKEND_COMMIT=$frontend_commit" \
|
||||
--build-arg "WEBDROP_BACKEND_TAG=$frontend_tag" \
|
||||
--build-arg "WEBDROP_BUILD_TIME=$build_time" \
|
||||
"$deploy_dir/src"
|
||||
|
||||
systemctl --user daemon-reload
|
||||
if systemctl --user is-active --quiet webdrop.service; then
|
||||
systemctl --user restart webdrop.service
|
||||
else
|
||||
systemctl --user start webdrop.service
|
||||
fi
|
||||
|
||||
for attempt in {1..30}; do
|
||||
if curl --fail --silent http://127.0.0.1:5000/api/v1/info >/dev/null; then
|
||||
echo "WebDrop updated and responding at http://127.0.0.1:5000"
|
||||
podman ps --filter name=webdrop --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
systemctl --user status webdrop.service --no-pager || true
|
||||
journalctl --user -u webdrop.service -n 80 --no-pager || true
|
||||
exit 1
|
||||
Reference in new issue
Block a user