@netwerk-digitaal-erfgoed/[email protected] #594
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build app and update Docker image | |
on: | |
# Use the release event because push events are not triggered for commits tagged with more than three tags: | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push. | |
release: | |
types: [created] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref_name, '@netwerk-digitaal-erfgoed/network-of-terms-graphql') || startsWith(github.ref_name, '@netwerk-digitaal-erfgoed/network-of-terms-reconciliation') | |
steps: | |
- uses: actions/checkout@v4 | |
# https://github.com/dhoulb/multi-semantic-release#git-tags tags packages `@scope/package-name@version`. | |
- uses: actions-ecosystem/[email protected] | |
id: parse-tag | |
with: | |
text: ${{ github.ref_name }} | |
regex: '^@netwerk-digitaal-erfgoed/(.+)@(.+)$' | |
# See https://github.com/docker/build-push-action#complete-workflow. | |
- name: Set variables | |
id: vars | |
run: | | |
VERSION_TAG=${GITHUB_REF#refs/tags/} | |
echo "package_name=${{steps.parse-tag.outputs.group1}}" >> $GITHUB_OUTPUT | |
echo "version_tag=${{steps.parse-tag.outputs.group2}}" >> $GITHUB_OUTPUT | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
echo "docker_image=ghcr.io/netwerk-digitaal-erfgoed/${{steps.parse-tag.outputs.group1}}" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Log in to Docker registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} | |
- name: Build and push image to registry | |
uses: docker/[email protected] | |
with: | |
context: . | |
push: true | |
build-args: PACKAGE_DIR=packages/${{ steps.vars.outputs.package_name }} | |
tags: | | |
${{ steps.vars.outputs.docker_image }}:${{ steps.vars.outputs.sha_short }} | |
${{ steps.vars.outputs.docker_image }}:${{ steps.vars.outputs.version_tag }} | |
${{ steps.vars.outputs.docker_image }}:latest | |
- uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Store DigitalOcean credentials | |
run: doctl kubernetes cluster kubeconfig save nde | |
# See https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment | |
- name: Update deployment | |
run: | | |
kubectl set image deployment/${{ steps.vars.outputs.package_name }} app=${{ steps.vars.outputs.docker_image }}:${{ steps.vars.outputs.sha_short }} | |
- name: Verify deployment | |
run: kubectl rollout status deployment/${{ steps.vars.outputs.package_name }} --timeout=120s |