Update .forgejo/workflows/deploy.yml
Some checks failed
Deploy server-up / deploy (push) Has been cancelled

Push image tag
Push version tag
Push latest
This commit is contained in:
bes-r 2026-05-11 23:33:57 +02:00
parent 29b123d133
commit 60bf1a92f7

View file

@ -1,21 +1,22 @@
name: Deploy to production name: Deploy server-up
on: on:
push: push:
branches: [main] branches: [main]
tags: ['v*']
workflow_dispatch: workflow_dispatch:
concurrency: concurrency:
group: production-deploy group: server-up-deploy
cancel-in-progress: false # niet cancelen — laat lopende deploys afmaken cancel-in-progress: false
jobs: jobs:
deploy: deploy:
runs-on: self-hosted # host-mode op je app-server runs-on: self-hosted
timeout-minutes: 15 timeout-minutes: 20
env: env:
DEPLOY_DIR: /opt/myapp DEPLOY_DIR: /opt/server-up
steps: steps:
- name: Checkout - name: Checkout
@ -23,7 +24,22 @@ jobs:
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Sync naar deploy-directory - name: Bepaal versie
id: version
run: |
set -euo pipefail
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME}"
CHANNEL="release"
else
VERSION="dev-${GITHUB_SHA:0:8}"
CHANNEL="dev"
fi
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "CHANNEL=${CHANNEL}" >> "$GITHUB_ENV"
echo "Deploying version: ${VERSION} (${CHANNEL})"
- name: Sync code naar deploy-directory
run: | run: |
set -euo pipefail set -euo pipefail
rsync -a --delete \ rsync -a --delete \
@ -31,55 +47,47 @@ jobs:
--exclude='.forgejo/' \ --exclude='.forgejo/' \
./ "$DEPLOY_DIR/" ./ "$DEPLOY_DIR/"
- name: Schrijf .env vanuit secrets - name: Schrijf VERSION-bestand
working-directory: ${{ env.DEPLOY_DIR }} working-directory: ${{ env.DEPLOY_DIR }}
env: run: echo "${VERSION}" > VERSION
DATABASE_URL: ${{ secrets.DATABASE_URL }}
API_KEY: ${{ secrets.API_KEY }}
NODE_ENV: production
run: |
set -euo pipefail
umask 077
cat > .env <<EOF
DATABASE_URL=${DATABASE_URL}
API_KEY=${API_KEY}
NODE_ENV=${NODE_ENV}
EOF
- name: Build image - name: Build image
working-directory: ${{ env.DEPLOY_DIR }} working-directory: ${{ env.DEPLOY_DIR }}
env:
GIT_SHA: ${{ github.sha }}
run: | run: |
set -euo pipefail
docker compose build --pull docker compose build --pull
# Extra tags zodat 'latest' altijd op de laatste deploy wijst
docker tag "server-up:${VERSION}" server-up:latest
docker tag "server-up:${VERSION}" "server-up:${CHANNEL}"
- name: Deploy (zero-downtime waar mogelijk) - name: Deploy
working-directory: ${{ env.DEPLOY_DIR }} working-directory: ${{ env.DEPLOY_DIR }}
env:
GIT_SHA: ${{ github.sha }}
run: | run: |
set -euo pipefail set -euo pipefail
docker compose up -d --remove-orphans docker compose up -d --remove-orphans
docker compose ps docker compose ps
- name: Wachten op healthcheck - name: Wachten op healthcheck
working-directory: ${{ env.DEPLOY_DIR }}
run: | run: |
set -euo pipefail set -euo pipefail
for i in {1..30}; do for i in {1..40}; do
status=$(docker compose ps --format json app | grep -o '"Health":"[^"]*"' || true) status=$(docker inspect --format '{{.State.Health.Status}}' server-up 2>/dev/null || echo "starting")
echo "poll $i: $status" echo "poll $i: $status"
if echo "$status" | grep -q '"Health":"healthy"'; then if [ "$status" = "healthy" ]; then
echo "App is healthy" echo "server-up is healthy als versie ${VERSION}"
exit 0 exit 0
fi fi
sleep 2 sleep 3
done done
echo "App werd niet healthy in tijd — logs:" echo "server-up werd niet healthy in tijd — logs:"
docker compose logs --tail=200 cd "$DEPLOY_DIR" && docker compose logs --tail=200
exit 1 exit 1
- name: Oude images opruimen - name: Oude images opruimen (behoud laatste 5)
if: success() if: success()
run: docker image prune -f run: |
docker images server-up --format '{{.Tag}} {{.ID}}' \
| grep -vE '^(latest|release|dev) ' \
| tail -n +6 \
| awk '{print $2}' \
| xargs -r docker rmi -f || true
docker image prune -f