Files
WebDrop/scripts/wsl-podman-update.sh

70 lines
2.2 KiB
Bash

#!/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