Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/docker-build-and-push-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build and Push Docker Image of Backend

on:
push:
branches: [ main, development ]
paths:
- '.github/workflows/docker-build-and-push-backend.yml'
- 'backend/**'
- '!backend/README.md'

workflow_dispatch: # Allow manual trigger


env:
REGISTRY: ghcr.io
NAMESPACE: ${{ github.repository_owner }}
IMAGE_NAME: committee-clash-backend
IMAGE_TAG: "latest${{ github.ref == 'refs/heads/main' && '' || '-dev' }}" # TODO does not support versioning as of yet
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misschien branch-(pipelineid/pipeline-hash) (ik weet even niet hoe github dat doet, maar in gitlab is het $CI_PIPELINE_ID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

een hash is niet incremental, maar zolang we aas gebruijken in de pipeline en de versie doorsturen is dat denk ik prima. Lijkt me wel goed om versies immutable te houden, en dus iets ever changing met lage kans op collissie als een hash of incrementing pipelime id te pakken



concurrency:
group: "docker-backend"
cancel-in-progress: false


jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Downcase NAMESPACE
run: |
echo "NAMESPACE=${NAMESPACE,,}" >>${GITHUB_ENV}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./backend/
file: ./backend/Dockerfile
push: true
tags: ${{ env.REGISTRY}}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Generate deployment info
run: |
echo "## Deployment Information" >> $GITHUB_STEP_SUMMARY
echo "**Image**: \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY
echo "**Registry**: GitHub Container Registry" >> $GITHUB_STEP_SUMMARY
echo "**Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY

# - name: Trigger watchtower
# run: |
# curl -fH "Authorization: Bearer ${{ secrets.WATCHTOWER_TOKEN }}" ${{ secrets.API_URL }}:8080/v1/update