Some checks failed
dev - build & deploy naar test / build-and-deploy (push) Has been cancelled
51 lines
2.2 KiB
YAML
51 lines
2.2 KiB
YAML
name: dev - build & deploy naar test
|
|
|
|
# Elke push naar dev bouwt een image en zet die op de test-VM.
|
|
on:
|
|
push:
|
|
branches: [dev]
|
|
|
|
concurrency:
|
|
group: deploy-test
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: dev # jouw dev-runner (test-server)
|
|
env:
|
|
# 10.0.20.22:3000 - host van je Forgejo (= container registry host)
|
|
REGISTRY: ${{ vars.REGISTRY }}
|
|
IMAGE_NAME: ${{ github.repository }} # bes-r/teach
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Image-tags bepalen
|
|
id: meta
|
|
run: |
|
|
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
|
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
|
|
echo "sha_tag=${IMAGE}:dev-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
|
echo "dev_tag=${IMAGE}:dev" >> "$GITHUB_OUTPUT"
|
|
|
|
# Platte docker build/push i.p.v. buildx: betrouwbaarder tegen een
|
|
# HTTP-registry. De runner-host moet 10.0.20.22:3000 als
|
|
# insecure-registry hebben (zie README).
|
|
- name: Login, build & push
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
docker build \
|
|
--build-arg APP_VERSION="dev-${GITHUB_SHA::7}" \
|
|
-t "${{ steps.meta.outputs.sha_tag }}" \
|
|
-t "${{ steps.meta.outputs.dev_tag }}" .
|
|
docker push "${{ steps.meta.outputs.sha_tag }}"
|
|
docker push "${{ steps.meta.outputs.dev_tag }}"
|
|
|
|
# Deploy via gewone ssh (geen externe action nodig).
|
|
- name: Deploy naar test-VM
|
|
run: |
|
|
echo "${{ secrets.TEST_SSH_KEY }}" > deploy_key
|
|
chmod 600 deploy_key
|
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
|
-i deploy_key ${{ secrets.TEST_USER }}@${{ secrets.TEST_HOST }} \
|
|
"set -e && cd ${{ secrets.TEST_DEPLOY_PATH }} && echo '${{ secrets.REGISTRY_TOKEN }}' | docker login ${{ vars.REGISTRY }} -u '${{ secrets.REGISTRY_USER }}' --password-stdin && sed -i 's|^IMAGE=.*|IMAGE=${{ steps.meta.outputs.dev_tag }}|' .env && docker compose -f compose.deploy.yaml pull && docker compose -f compose.deploy.yaml up -d && docker image prune -f"
|
|
rm -f deploy_key
|