From 57ebf45456983314ada9318350576c93bcbda6a6 Mon Sep 17 00:00:00 2001 From: Toni Corvera Date: Sat, 20 Apr 2024 11:41:45 +0200 Subject: [PATCH] Split workflow into CI and Deploy --- .github/workflows/ci.yaml | 62 +++++++++++++++++++++++++++ .github/workflows/deploy-to-ghcr.yaml | 13 +++--- 2 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e4190d1 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,62 @@ +--- +# Based on video "GitHub Packages. Containers in a GitHub repo?"" +# TODO: DockerHub integration, see e.g. https://github.com/docker/metadata-action + +# Builds for the current architecture on each push + +name: Build on push + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Login to container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # FIXME: :latest isn't added by default althought it should??? https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag + # adding a raw tag as a workaround + tags: | + type=raw,value=latest + type=sha + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=ref,event=tag + type=ref,event=branch,suffix=-branch + + # Standard build action: + #- name: Build and push Docker image + # uses: docker/build-push-action@v5 + # with: + # context: . + # push: true + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} + # Non-standard using the makefile: + - name: Build + # IMAGE_NAME must match the github repository name + run: make REGISTRY=${{ env.REGISTRY }} IMAGE_NAME=${{ env.IMAGE_NAME }} diff --git a/.github/workflows/deploy-to-ghcr.yaml b/.github/workflows/deploy-to-ghcr.yaml index 7c0898e..a35a79e 100644 --- a/.github/workflows/deploy-to-ghcr.yaml +++ b/.github/workflows/deploy-to-ghcr.yaml @@ -2,18 +2,15 @@ # Based on video "GitHub Packages. Containers in a GitHub repo?"" # TODO: DockerHub integration, see e.g. https://github.com/docker/metadata-action +# Deploy to GHCR a multi-arch image when tagged + name: Deploy image to GHCR -# Runs on all pushes, all branches included -# on: [push] on: push: - # Note these are supposed to be OR'ed, i.e. when branch is main or a tag like v* is pushed - branches: - - 'master' -# tags: -# # This doesn't work: - 'v?[0-9]+.[0-9]+.[0-9]+([0-9]+)?' -# - 'v*.*' + tags: + # This doesn't work: - 'v?[0-9]+.[0-9]+.[0-9]+([0-9]+)?' + - '*.*' env: REGISTRY: ghcr.io