Fix nginx issues #2
Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Has been skipped
Podman Rootless Demo / deploy-prod (push) Failing after 1m31s

This commit is contained in:
continuist 2025-09-20 22:06:10 -04:00
parent 8e2a5236ac
commit 795d83c81a

View file

@ -240,50 +240,42 @@ jobs:
--password-stdin \ --password-stdin \
"${{ secrets.REGISTRY_HOST }}" "${{ secrets.REGISTRY_HOST }}"
- name: Pull production images (optional but faster on play) - name: (Optional) Pre-pull images to speed up play
run: | run: |
podman --remote pull "$REGISTRY_HOST/$APP_NAME/sharenet-backend-api-postgres:$IMAGE_TAG" podman --remote pull "$REGISTRY_HOST/$APP_NAME/sharenet-backend-api-postgres:$IMAGE_TAG"
podman --remote pull "$REGISTRY_HOST/$APP_NAME/sharenet-frontend:$IMAGE_TAG" podman --remote pull "$REGISTRY_HOST/$APP_NAME/sharenet-frontend:$IMAGE_TAG"
# RENDER nginx.conf FROM REPO AND COPY TO HOST (no unshare) # 1) Render nginx.conf from repo and copy to host (no unshare)
- name: Render nginx.conf and write to host - name: Render nginx.conf and write to host
run: | run: |
set -euo pipefail set -euo pipefail
apk add --no-cache gettext >/dev/null # provides envsubst apk add --no-cache gettext >/dev/null
# Render with your CI env (PROD_* vars)
envsubst < nginx/nginx.conf > /tmp/nginx.conf envsubst < nginx/nginx.conf > /tmp/nginx.conf
# Copy to host via remote Podman bind-mount; keep prod-service uid/gid
podman --remote run --rm -i \ podman --remote run --rm -i \
--userns=keep-id \ --userns=keep-id \
-v /opt/sharenet/nginx:/host-nginx:rw \ -v /opt/sharenet/nginx:/host-nginx:rw \
alpine:3.20 sh -c 'install -D -m 0644 /dev/stdin /host-nginx/nginx.conf' \ alpine:3.20 sh -c 'install -D -m 0644 /dev/stdin /host-nginx/nginx.conf' \
< /tmp/nginx.conf < /tmp/nginx.conf
# TRY ZERO-DOWNTIME RELOAD FIRST # 2) Lint nginx.conf BEFORE restarting the pod (avoids crash loops)
- name: Reload in-pod Nginx (or restart on failure) - name: Validate nginx.conf with throwaway container
continue-on-error: true
run: | run: |
set -euo pipefail set -euo pipefail
podman --remote exec sharenet-production-pod-nginx nginx -t podman --remote run --rm \
podman --remote exec sharenet-production-pod-nginx nginx -s reload -v /opt/sharenet/nginx:/etc/nginx:ro \
docker.io/nginx:alpine \
sh -lc 'nginx -t -c /etc/nginx/nginx.conf'
- name: Fallback restart Nginx container if reload failed # 3) Recreate the pod (down → play). This ensures new images/ports/env + the validated conf.
if: failure() - name: Recreate pod
run: |
set -euo pipefail
podman --remote restart sharenet-production-pod-nginx
# (Re)APPLY THE POD (ensures new images/config picked up)
- name: Recreate pod (down & play)
run: | run: |
set -euo pipefail set -euo pipefail
podman --remote kube down sharenet-production-pod || true podman --remote kube down sharenet-production-pod || true
# Render your pod manifest (uses same $ENV as before)
envsubst < deploy/prod-pod.yml | podman --remote kube play - envsubst < deploy/prod-pod.yml | podman --remote kube play -
# VERIFY # 4) Verify health on the prod host
- name: Verify in-pod nginx is healthy - name: Verify in-pod Nginx
run: | run: |
set -euo pipefail set -euo pipefail
curl -sS -D- http://127.0.0.1:18080/healthz curl -sS -D- http://127.0.0.1:18080/healthz