Skip to content

Merge pull request #668 from openstad/feat/customizable-topbar #2366

Merge pull request #668 from openstad/feat/customizable-topbar

Merge pull request #668 from openstad/feat/customizable-topbar #2366

name: Build and Publish Docker Image
on:
push:
paths-ignore:
- 'operations/deployments/openstad-headless/environments/acc/images.yml'
branches:
- '**'
tags:
- "v*"
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
strategy:
matrix:
app: [admin-server, api-server, auth-server, image-server, cms-server]
include:
- app: api-server
build-target: release-with-packages
name: '[${{ matrix.app }}] Build & push image'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.image_output.outputs.image_tag }}
env:
IMAGE: '${{ github.repository_owner }}/${{ matrix.app }}'
APP: ${{ matrix.app }}
BUILD_TARGET: release
steps:
- name: Checkout code
uses: actions/checkout@v3
- if: ${{ matrix.build-target }}
name: Set correct build target
run: echo "BUILD_TARGET=${{ matrix.build-target}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
# branch event
type=ref,event=branch,suffix=-{{sha}}
# tag event
type=ref,event=tag
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to GitHub Container Registry
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: 'ghcr.io/${{ steps.meta.outputs.tags }}'
build-args: |
APP=${{ matrix.app }}
- name: Add image output
id: image_output
run: echo "image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
set-images-in-yaml-and-commit:
name: Set images in yaml and commit
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-and-push-docker-image
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
SOPS_AGE_KEY_FILE: headless.agekey
SOPS_AGE_RECIPIENTS: age1pnz2leuqnfhyt9qpxjjcjs9xe9ys8xjkjn9m656wygy3ndfxya0q6kthy8
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install yq
run: sudo snap install yq --channel=v4/stable
- name: Set images and commit
run: |
git config --global user.email [email protected] && \
git config --global user.name "Github action" && \
git remote set-url origin https://${{ secrets.GH_COMMIT_PAT }}@github.com/${{ github.repository }}.git && \
/snap/bin/yq -i '.admin.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.api.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.cms.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.auth.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.image.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
git add operations/deployments/openstad-headless/environments/acc/images.yml && \
git commit -m "ci: release ${{ needs.build-and-push-docker-image.outputs.image_tag }}" && \
git push origin main
- name: Display images in Github Action
run: |
echo "**New images 🐳**
| App | Image |
|---|---|
| admin-server | \`ghcr.io/${{ github.repository_owner}}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| api-server | \`ghcr.io/${{ github.repository_owner}}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| cms-server | \`ghcr.io/${{ github.repository_owner}}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| auth-server | \`ghcr.io/${{ github.repository_owner}}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| image-server | \`ghcr.io/${{ github.repository_owner}}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |" >> $GITHUB_STEP_SUMMARY