Some checks failed
dev - build & deploy naar test / build-and-deploy (push) Failing after 4s
63 lines
2.8 KiB
YAML
63 lines
2.8 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: Dependencies en securitytests
|
|
run: |
|
|
npm ci
|
|
npm test
|
|
npm audit --omit=dev --audit-level=moderate
|
|
|
|
- name: Image-tags bepalen
|
|
id: meta
|
|
run: |
|
|
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
|
VERSION="$(tr -d '[:space:]' < VERSION)"
|
|
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
|
|
echo "sha_tag=${IMAGE}:dev-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
|
echo "dev_tag=${IMAGE}:dev" >> "$GITHUB_OUTPUT"
|
|
echo "app_version=${VERSION}" >> "$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="${{ steps.meta.outputs.app_version }}" \
|
|
--build-arg GIT_SHA="${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
|
|
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o ConnectTimeout=15 \
|
|
-i deploy_key deploy/compose.deploy.yaml deploy/nginx.conf \
|
|
${{ secrets.TEST_USER }}@${{ secrets.TEST_HOST }}:${{ secrets.TEST_DEPLOY_PATH }}/
|
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o ConnectTimeout=15 \
|
|
-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 app && docker compose -f compose.deploy.yaml up -d --force-recreate app web && docker image prune -f"
|
|
rm -f deploy_key
|