diff --git a/.github/workflows/docker-build-and-push-backend.yml b/.github/workflows/docker-build-and-push-backend.yml new file mode 100644 index 0000000..631a9f3 --- /dev/null +++ b/.github/workflows/docker-build-and-push-backend.yml @@ -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 + + +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