teach/.forgejo/workflows/release.yaml
bes-r 516a048ce7
Some checks are pending
dev - build & deploy naar test / build-and-deploy (push) Waiting to run
Initiële opzet: Fastify + static, Docker, Postgres, Forgejo Actions
2026-07-07 22:41:05 +02:00

63 lines
2.1 KiB
YAML

name: release - build & deploy naar productie
# Draait wanneer je in Forgejo een release publiceert.
# De release-tag (bv. v1.2.0) wordt de image-tag op productie.
on:
release:
types: [published]
concurrency:
group: deploy-prod
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest # pas aan naar het label van jouw Forgejo-runner
env:
REGISTRY: ${{ vars.REGISTRY }}
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
- name: Image-tags bepalen
id: meta
run: |
IMAGE="${REGISTRY}/${IMAGE_NAME}"
VERSION="${GITHUB_REF_NAME}" # de release-/tagnaam, bv. v1.2.0
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
echo "version_tag=${IMAGE}:${VERSION}" >> "$GITHUB_OUTPUT"
echo "latest_tag=${IMAGE}:latest" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Login bij Forgejo registry
uses: docker/login-action@v3
with:
registry: ${{ vars.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build & push
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
APP_VERSION=${{ steps.meta.outputs.version }}
tags: |
${{ steps.meta.outputs.version_tag }}
${{ steps.meta.outputs.latest_tag }}
- name: Deploy naar productie-VM
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
script: |
set -e
cd ${{ secrets.PROD_DEPLOY_PATH }}
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ vars.REGISTRY }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin
sed -i "s|^IMAGE=.*|IMAGE=${{ steps.meta.outputs.version_tag }}|" .env
docker compose -f compose.deploy.yaml pull
docker compose -f compose.deploy.yaml up -d
docker image prune -f