Some checks failed
Deploy to Phoenix / validate (push) Successful in 1m3s
Deploy to Phoenix / deploy (push) Successful in 42s
Deploy to Phoenix / deploy-atomic-swap-dapp (push) Successful in 2m27s
phoenix-deploy Deploy failed: Command failed: bash scripts/deployment/gitea-cloudflare-sync.sh
bash: scripts/deployment/gitea-cloudflare-sync.sh: No s
Deploy to Phoenix / cloudflare (push) Successful in 2m45s
100 lines
3.0 KiB
Bash
100 lines
3.0 KiB
Bash
#!/usr/bin/env bash
|
|
# Install Phoenix Deploy API to /opt/phoenix-deploy-api and enable systemd service.
|
|
# Run with: sudo ./scripts/install-systemd.sh
|
|
# Or from repo root: sudo phoenix-deploy-api/scripts/install-systemd.sh
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
APP_DIR="$SCRIPT_DIR/.."
|
|
TARGET="/opt/phoenix-deploy-api"
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo "Run with sudo to install to $TARGET and install systemd unit."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing Phoenix Deploy API to $TARGET ..."
|
|
mkdir -p "$TARGET"
|
|
cp -a "$APP_DIR/server.js" "$APP_DIR/package.json" "$APP_DIR/package-lock.json" "$TARGET/" 2>/dev/null || cp -a "$APP_DIR/server.js" "$APP_DIR/package.json" "$TARGET/"
|
|
# Program manifest for GET /api/v1/public-sector/programs (server loads from cwd-adjacent copy on /opt)
|
|
if [[ -f "$REPO_ROOT/config/public-sector-program-manifest.json" ]]; then
|
|
cp -a "$REPO_ROOT/config/public-sector-program-manifest.json" "$TARGET/public-sector-program-manifest.json"
|
|
echo "Installed public-sector-program-manifest.json"
|
|
else
|
|
echo "WARN: $REPO_ROOT/config/public-sector-program-manifest.json missing — set PUBLIC_SECTOR_MANIFEST_PATH in .env"
|
|
fi
|
|
if [[ -f "$TARGET/.env" ]]; then
|
|
echo "Preserving existing $TARGET/.env"
|
|
elif [[ -f "$APP_DIR/.env" ]]; then
|
|
cp "$APP_DIR/.env" "$TARGET/.env"
|
|
elif [[ -f "$APP_DIR/.env.example" ]]; then
|
|
cp "$APP_DIR/.env.example" "$TARGET/.env"
|
|
fi
|
|
|
|
ensure_env_value() {
|
|
local key="$1"
|
|
local value="$2"
|
|
local file="$TARGET/.env"
|
|
[[ -n "$value" && -f "$file" ]] || return 0
|
|
|
|
local current=""
|
|
if grep -qE "^${key}=" "$file"; then
|
|
current="$(grep -E "^${key}=" "$file" | tail -n 1 | cut -d= -f2-)"
|
|
fi
|
|
[[ -z "$current" ]] || return 0
|
|
|
|
local tmp
|
|
tmp="$(mktemp)"
|
|
awk -v key="$key" -v value="$value" '
|
|
BEGIN { found = 0 }
|
|
$0 ~ "^" key "=" {
|
|
print key "=" value
|
|
found = 1
|
|
next
|
|
}
|
|
{ print }
|
|
END {
|
|
if (!found) print key "=" value
|
|
}
|
|
' "$file" > "$tmp"
|
|
cat "$tmp" > "$file"
|
|
rm -f "$tmp"
|
|
}
|
|
|
|
repo_env_value() {
|
|
local key="$1"
|
|
local file="$REPO_ROOT/.env"
|
|
[[ -f "$file" ]] || return 0
|
|
grep -E "^${key}=" "$file" | tail -n 1 | cut -d= -f2-
|
|
}
|
|
|
|
if [[ -f "$TARGET/.env" ]]; then
|
|
ensure_env_value PHOENIX_REPO_ROOT "$REPO_ROOT"
|
|
for key in \
|
|
GITEA_TOKEN \
|
|
PHOENIX_DEPLOY_SECRET \
|
|
PROXMOX_HOST \
|
|
PROXMOX_PORT \
|
|
PROXMOX_USER \
|
|
PROXMOX_TOKEN_NAME \
|
|
PROXMOX_TOKEN_VALUE \
|
|
PROXMOX_TLS_VERIFY \
|
|
PUBLIC_IP \
|
|
CLOUDFLARE_API_TOKEN \
|
|
CLOUDFLARE_GITEA_SYNC_ZONE \
|
|
PHOENIX_CLOUDFLARE_SYNC
|
|
do
|
|
ensure_env_value "$key" "$(repo_env_value "$key")"
|
|
done
|
|
fi
|
|
chown -R root:root "$TARGET"
|
|
cd "$TARGET" && npm install --omit=dev
|
|
cp "$APP_DIR/phoenix-deploy-api.service" /etc/systemd/system/
|
|
systemctl daemon-reload
|
|
systemctl enable phoenix-deploy-api
|
|
systemctl start phoenix-deploy-api
|
|
echo "Done. Status: $(systemctl is-active phoenix-deploy-api)"
|
|
echo "Edit $TARGET/.env (GITEA_TOKEN, etc.) and run: systemctl restart phoenix-deploy-api"
|