Rework deploy script to SSH directly into Unraid
Replace Portainer-based redeployment with direct SSH approach: - Auto-detect podman/docker for local builds - SCP compose file to Unraid - Generate Postgres password in .env if missing - Pull images and (re)start containers via SSH Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
# nuzlocke-tracker-lhls
|
||||||
|
title: Add compose file sync to deploy script
|
||||||
|
status: completed
|
||||||
|
type: task
|
||||||
|
priority: normal
|
||||||
|
created_at: 2026-02-10T08:19:57Z
|
||||||
|
updated_at: 2026-02-10T08:20:13Z
|
||||||
|
parent: nuzlocke-tracker-ahza
|
||||||
|
---
|
||||||
|
|
||||||
|
Update deploy.sh to SCP docker-compose.prod.yml to the Unraid server at /mnt/user/appdata/nuzlocke-tracker/ before triggering the Portainer redeployment. SSH target: root@192.168.1.10 (port 22).
|
||||||
67
deploy.sh
67
deploy.sh
@@ -8,10 +8,16 @@ IMAGES=("nuzlocke-tracker-api" "nuzlocke-tracker-frontend")
|
|||||||
DOCKERFILES=("backend/Dockerfile.prod" "frontend/Dockerfile.prod")
|
DOCKERFILES=("backend/Dockerfile.prod" "frontend/Dockerfile.prod")
|
||||||
CONTEXTS=("./backend" "./frontend")
|
CONTEXTS=("./backend" "./frontend")
|
||||||
|
|
||||||
PORTAINER_URL="${PORTAINER_URL:-https://portainer.nerdboden.de}"
|
if command -v podman &>/dev/null; then
|
||||||
PORTAINER_API_KEY="${PORTAINER_API_KEY:-}"
|
CONTAINER_CMD="podman"
|
||||||
PORTAINER_STACK_ID="${PORTAINER_STACK_ID:-}"
|
elif command -v docker &>/dev/null; then
|
||||||
PORTAINER_ENDPOINT_ID="${PORTAINER_ENDPOINT_ID:-1}"
|
CONTAINER_CMD="docker"
|
||||||
|
else
|
||||||
|
echo "Neither podman nor docker found." >&2; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
UNRAID_SSH="root@192.168.1.10"
|
||||||
|
UNRAID_DEPLOY_DIR="/mnt/user/appdata/nuzlocke-tracker"
|
||||||
|
|
||||||
# ── Helpers ────────────────────────────────────────────────────
|
# ── Helpers ────────────────────────────────────────────────────
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@@ -41,41 +47,34 @@ fi
|
|||||||
for i in "${!IMAGES[@]}"; do
|
for i in "${!IMAGES[@]}"; do
|
||||||
IMAGE="${REGISTRY}/${OWNER}/${IMAGES[$i]}:latest"
|
IMAGE="${REGISTRY}/${OWNER}/${IMAGES[$i]}:latest"
|
||||||
info "Building ${IMAGES[$i]}..."
|
info "Building ${IMAGES[$i]}..."
|
||||||
docker build -t "$IMAGE" -f "${DOCKERFILES[$i]}" "${CONTEXTS[$i]}"
|
$CONTAINER_CMD build -t "$IMAGE" -f "${DOCKERFILES[$i]}" "${CONTEXTS[$i]}"
|
||||||
info "Pushing ${IMAGES[$i]}..."
|
info "Pushing ${IMAGES[$i]}..."
|
||||||
docker push "$IMAGE"
|
$CONTAINER_CMD push "$IMAGE"
|
||||||
done
|
done
|
||||||
|
|
||||||
info "All images built and pushed."
|
info "All images built and pushed."
|
||||||
|
|
||||||
# ── Trigger Portainer redeployment ─────────────────────────────
|
# ── Sync compose file to Unraid ──────────────────────────────────
|
||||||
if [[ -z "$PORTAINER_API_KEY" ]]; then
|
info "Copying docker-compose.prod.yml to Unraid..."
|
||||||
warn "PORTAINER_API_KEY not set — skipping Portainer redeployment."
|
scp docker-compose.prod.yml "${UNRAID_SSH}:${UNRAID_DEPLOY_DIR}/docker-compose.yml" \
|
||||||
warn "Set it in your environment or .env.deploy file to enable auto-redeploy."
|
|| error "Failed to copy compose file to Unraid."
|
||||||
exit 0
|
info "Compose file synced."
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z "$PORTAINER_STACK_ID" ]]; then
|
# ── Ensure .env with Postgres password exists ────────────────────
|
||||||
warn "PORTAINER_STACK_ID not set — skipping Portainer redeployment."
|
info "Checking for .env on Unraid..."
|
||||||
warn "Find your stack ID in Portainer and set it in your environment."
|
ssh "${UNRAID_SSH}" "
|
||||||
exit 0
|
if [ ! -f '${UNRAID_DEPLOY_DIR}/.env' ]; then
|
||||||
fi
|
PASS=\$(head -c 32 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' | head -c 32)
|
||||||
|
echo \"POSTGRES_PASSWORD=\${PASS}\" > '${UNRAID_DEPLOY_DIR}/.env'
|
||||||
|
echo 'Generated new .env with POSTGRES_PASSWORD'
|
||||||
|
else
|
||||||
|
echo '.env already exists, skipping'
|
||||||
|
fi
|
||||||
|
" || error "Failed to check/create .env on Unraid."
|
||||||
|
|
||||||
info "Fetching stack file from Portainer..."
|
# ── Pull images and (re)start on Unraid ──────────────────────────
|
||||||
STACK_FILE=$(curl -sf \
|
info "Pulling images and starting containers on Unraid..."
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
ssh "${UNRAID_SSH}" "cd '${UNRAID_DEPLOY_DIR}' && docker compose pull && docker compose up -d" \
|
||||||
"${PORTAINER_URL}/api/stacks/${PORTAINER_STACK_ID}/file") \
|
|| error "Failed to start containers on Unraid."
|
||||||
|| error "Failed to fetch stack file from Portainer."
|
|
||||||
|
|
||||||
STACK_CONTENT=$(echo "$STACK_FILE" | jq -r '.StackFileContent')
|
info "Deploy complete!"
|
||||||
|
|
||||||
info "Triggering stack redeployment..."
|
|
||||||
curl -sf -X PUT \
|
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$(jq -n --arg content "$STACK_CONTENT" '{"pullImage": true, "stackFileContent": $content}')" \
|
|
||||||
"${PORTAINER_URL}/api/stacks/${PORTAINER_STACK_ID}?endpointId=${PORTAINER_ENDPOINT_ID}" \
|
|
||||||
> /dev/null \
|
|
||||||
|| error "Failed to trigger Portainer redeployment."
|
|
||||||
|
|
||||||
info "Stack redeployment triggered successfully!"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user