fix: deploy-now without heredocs — Gitea 1.26.3 compat
CI - Build & Test / Backend (.NET) (push) Successful in 26s
CI - Build & Test / Frontend (Vue/TS) (push) Successful in 17s
CI - Build & Test / Security Check (push) Successful in 3s

This commit is contained in:
2026-06-21 21:38:09 +02:00
parent cf10ca3ed8
commit 5dc00c1142
+63 -70
View File
@@ -40,7 +40,7 @@ jobs:
echo "Deploy version: v${VERSION} git:${GIT_REF}" echo "Deploy version: v${VERSION} git:${GIT_REF}"
echo "version=${VERSION}" >> "$GITEA_OUTPUT" echo "version=${VERSION}" >> "$GITEA_OUTPUT"
- name: Prepare .env (secrets + host .env → temp file) - name: Prepare .env
run: | run: |
set -euo pipefail set -euo pipefail
HOST_OWNER_PASSWORD="" HOST_OWNER_PASSWORD=""
@@ -51,22 +51,20 @@ jobs:
echo "ERROR: OWNER_PASSWORD not found in ${DEPLOY_PATH}/.env" echo "ERROR: OWNER_PASSWORD not found in ${DEPLOY_PATH}/.env"
exit 1 exit 1
fi fi
cat > "${ENV_TMPFILE}" <<ENVEOF printf 'POSTGRES_DB=nexus\n' > "${ENV_TMPFILE}"
POSTGRES_DB=nexus printf 'POSTGRES_USER=nexus\n' >> "${ENV_TMPFILE}"
POSTGRES_USER=nexus printf 'POSTGRES_PASSWORD=%s\n' "${ENV_POSTGRES_PASSWORD}" >> "${ENV_TMPFILE}"
POSTGRES_PASSWORD=${ENV_POSTGRES_PASSWORD} printf 'JWT_KEY=%s\n' "${ENV_JWT_KEY}" >> "${ENV_TMPFILE}"
JWT_KEY=${ENV_JWT_KEY} printf 'JWT_ISSUER=nexus\n' >> "${ENV_TMPFILE}"
JWT_ISSUER=nexus printf 'JWT_AUDIENCE=nexus-web\n' >> "${ENV_TMPFILE}"
JWT_AUDIENCE=nexus-web printf 'OWNER_EMAIL=vmbao62@hotmail.de\n' >> "${ENV_TMPFILE}"
OWNER_EMAIL=vmbao62@hotmail.de printf 'OWNER_PASSWORD=%s\n' "${HOST_OWNER_PASSWORD}" >> "${ENV_TMPFILE}"
OWNER_PASSWORD=${HOST_OWNER_PASSWORD} printf 'OWNER_DISPLAY_NAME=\n' >> "${ENV_TMPFILE}"
OWNER_DISPLAY_NAME= printf 'OPENCLAW_BASE_URL=http://host.docker.internal:18789\n' >> "${ENV_TMPFILE}"
OPENCLAW_BASE_URL=http://host.docker.internal:18789 printf 'OPENCLAW_GATEWAY_TOKEN=%s\n' "${ENV_OPENCLAW_TOKEN}" >> "${ENV_TMPFILE}"
OPENCLAW_GATEWAY_TOKEN=${ENV_OPENCLAW_TOKEN} printf 'OPENCLAW_GATEWAY_PASSWORD=\n' >> "${ENV_TMPFILE}"
OPENCLAW_GATEWAY_PASSWORD=
ENVEOF
chmod 600 "${ENV_TMPFILE}" chmod 600 "${ENV_TMPFILE}"
echo "OK .env written" echo "OK .env written to ${ENV_TMPFILE}"
- name: Sync code to host - name: Sync code to host
run: | run: |
@@ -76,65 +74,65 @@ ENVEOF
-v "${DEPLOY_PATH}:/dest" \ -v "${DEPLOY_PATH}:/dest" \
alpine:latest \ alpine:latest \
sh -c "cd /src && find . -mindepth 1 -maxdepth 1 ! -name .git -exec cp -r {} /dest/ \; && DEST_OWNER=\$(stat -c '%u:%g' /dest) && chown -R \"\$DEST_OWNER\" /dest" sh -c "cd /src && find . -mindepth 1 -maxdepth 1 ! -name .git -exec cp -r {} /dest/ \; && DEST_OWNER=\$(stat -c '%u:%g' /dest) && chown -R \"\$DEST_OWNER\" /dest"
echo "OK synced" echo "OK synced to ${DEPLOY_PATH}"
- name: Build and Deploy - name: Build and Deploy
run: | run: |
set -euo pipefail set -euo pipefail
cat > /tmp/nexus-deploy-script.sh << 'DEPLOYSCRIPT' SCRIPT=/tmp/nexus-deploy-script.sh
#!/bin/sh printf '#!/bin/sh\n' > "$SCRIPT"
set -e printf 'set -e\n' >> "$SCRIPT"
trap 'rm -f /tmp/nexus-deploy-env' EXIT printf 'trap "rm -f /tmp/nexus-deploy-env" EXIT\n' >> "$SCRIPT"
cat > /tmp/nexus-deploy-env printf 'cat > /tmp/nexus-deploy-env\n' >> "$SCRIPT"
printf '\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env down --remove-orphans 2>/dev/null || true printf 'docker compose --env-file /tmp/nexus-deploy-env down --remove-orphans 2>/dev/null || true\n' >> "$SCRIPT"
docker rm -f nexus-postgres-1 nexus-api-1 nexus-web-1 2>/dev/null || true printf 'docker rm -f nexus-postgres-1 nexus-api-1 nexus-web-1 2>/dev/null || true\n' >> "$SCRIPT"
printf '\n' >> "$SCRIPT"
PG_VOL=$(docker volume ls -q --filter name=nexus-postgres 2>/dev/null | head -1) printf 'PG_VOL=$(docker volume ls -q --filter name=nexus-postgres 2>/dev/null | head -1)\n' >> "$SCRIPT"
if [ -n "$PG_VOL" ]; then printf 'if [ -n "$PG_VOL" ]; then\n' >> "$SCRIPT"
echo "Checking postgres WAL integrity..." printf ' echo "Checking postgres WAL integrity..."\n' >> "$SCRIPT"
docker run --rm -v "$PG_VOL:/var/lib/postgresql/data" --entrypoint sh postgres:17-alpine -c "pg_resetwal -f /var/lib/postgresql/data && echo WAL reset OK" 2>&1 || echo "pg_resetwal failed (may be benign)" printf ' docker run --rm -v "$PG_VOL:/var/lib/postgresql/data" --entrypoint sh postgres:17-alpine -c "pg_resetwal -f /var/lib/postgresql/data && echo WAL reset OK" 2>&1 || echo "pg_resetwal failed (may be benign)"\n' >> "$SCRIPT"
else printf 'else\n' >> "$SCRIPT"
echo "Postgres volume not found - will be created fresh" printf ' echo "Postgres volume not found - will be created fresh"\n' >> "$SCRIPT"
fi printf 'fi\n' >> "$SCRIPT"
printf '\n' >> "$SCRIPT"
echo "Deploying all services" printf 'echo "Deploying all services"\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env build printf 'docker compose --env-file /tmp/nexus-deploy-env build\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env up -d --force-recreate printf 'docker compose --env-file /tmp/nexus-deploy-env up -d --force-recreate\n' >> "$SCRIPT"
printf '\n' >> "$SCRIPT"
echo "Waiting for services to become healthy (up to 180s)..." printf 'echo "Waiting for services to become healthy (up to 180s)..."\n' >> "$SCRIPT"
for i in $(seq 1 36); do printf 'for i in $(seq 1 36); do\n' >> "$SCRIPT"
STATUS=$(docker compose --env-file /tmp/nexus-deploy-env ps -a 2>/dev/null | tail -n +2) printf ' STATUS=$(docker compose --env-file /tmp/nexus-deploy-env ps -a 2>/dev/null | tail -n +2)\n' >> "$SCRIPT"
if echo "$STATUS" | grep -q 'unhealthy'; then printf ' if echo "$STATUS" | grep -q unhealthy; then\n' >> "$SCRIPT"
echo " [$i/36] Unhealthy containers - failing fast" printf ' echo " [$i/36] Unhealthy containers - failing fast"\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env ps -a printf ' docker compose --env-file /tmp/nexus-deploy-env ps -a\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env logs --tail=30 printf ' docker compose --env-file /tmp/nexus-deploy-env logs --tail=30\n' >> "$SCRIPT"
exit 1 printf ' exit 1\n' >> "$SCRIPT"
elif echo "$STATUS" | grep -q 'starting'; then printf ' elif echo "$STATUS" | grep -q starting; then\n' >> "$SCRIPT"
echo " [$i/36] Still starting..." printf ' echo " [$i/36] Still starting..."\n' >> "$SCRIPT"
sleep 5 printf ' sleep 5\n' >> "$SCRIPT"
else printf ' else\n' >> "$SCRIPT"
echo "All containers healthy" printf ' echo "All containers healthy"\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env ps -a printf ' docker compose --env-file /tmp/nexus-deploy-env ps -a\n' >> "$SCRIPT"
exit 0 printf ' exit 0\n' >> "$SCRIPT"
fi printf ' fi\n' >> "$SCRIPT"
done printf 'done\n' >> "$SCRIPT"
echo "Timeout waiting for services" printf 'echo "Timeout waiting for services"\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env ps -a printf 'docker compose --env-file /tmp/nexus-deploy-env ps -a\n' >> "$SCRIPT"
docker compose --env-file /tmp/nexus-deploy-env logs --tail=20 printf 'docker compose --env-file /tmp/nexus-deploy-env logs --tail=20\n' >> "$SCRIPT"
exit 1 printf 'exit 1\n' >> "$SCRIPT"
DEPLOYSCRIPT chmod +x "$SCRIPT"
docker run --rm \ docker run --rm \
-v "${DEPLOY_PATH}:/workspace/nexus" \ -v "${DEPLOY_PATH}:/workspace/nexus" \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/nexus-deploy-script.sh:/deploy.sh:ro \ -v "${SCRIPT}:/deploy.sh:ro" \
-w /workspace/nexus \ -w /workspace/nexus \
-i \ -i \
docker:cli \ docker:cli \
sh /deploy.sh < "${ENV_TMPFILE}" sh /deploy.sh < "${ENV_TMPFILE}"
rm -f /tmp/nexus-deploy-script.sh rm -f "$SCRIPT"
echo "OK deployed" echo "OK deployed"
- name: Clean up temp .env - name: Clean up temp .env
@@ -148,9 +146,7 @@ DEPLOYSCRIPT
- name: Health Check - name: Health Check
run: | run: |
echo "Health check..." echo "Health check..."
RETRY=0 RETRY=0; MAX=6; WAIT=1
MAX=6
WAIT=1
while [ $RETRY -lt $MAX ]; do while [ $RETRY -lt $MAX ]; do
RETRY=$((RETRY + 1)) RETRY=$((RETRY + 1))
if curl -sf --max-time 10 https://nexus.noveria.net/health; then if curl -sf --max-time 10 https://nexus.noveria.net/health; then
@@ -168,9 +164,7 @@ DEPLOYSCRIPT
- name: Smoke Test - name: Smoke Test
run: | run: |
PASS=0 PASS=0; FAIL=0; BASE="https://nexus.noveria.net"
FAIL=0
BASE="https://nexus.noveria.net"
check() { check() {
local path="$1" label="$2" expected="${3:-200}" local path="$1" label="$2" expected="${3:-200}"
local code local code
@@ -187,7 +181,6 @@ DEPLOYSCRIPT
check "/dashboard" "Dashboard" 200 check "/dashboard" "Dashboard" 200
check "/health" "Health API" 200 check "/health" "Health API" 200
check "/api/v1/operations/snapshot" "Operations API (auth)" 401 check "/api/v1/operations/snapshot" "Operations API (auth)" 401
echo ""
echo "Results: $PASS passed, $FAIL failed" echo "Results: $PASS passed, $FAIL failed"
if [ "$FAIL" -gt 0 ]; then if [ "$FAIL" -gt 0 ]; then
echo "ERROR Smoke test failed" echo "ERROR Smoke test failed"