From 1baea43e9ef0f3d4bae1c784dd24ad06e57af5ff Mon Sep 17 00:00:00 2001 From: Ben Peachey Date: Thu, 23 May 2024 13:16:20 +0200 Subject: [PATCH] Create build.yml for building docker images --- .github/workflows/build.yml | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..57f1b27 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,54 @@ +--- +name: Build Docker Image + +# yamllint disable-line rule:truthy +on: + push: + branches: [ main ] + tags: + - '*' + pull_request: + branches: [ main ] + # Allow manually triggering the workflow. + workflow_dispatch: + +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-docker: + runs-on: ubuntu-latest + steps: + - name: Create docker tag (from git reference) + # A tag name may only contain lower- and uppercase letters, digits, underscores, periods and dashes. + run: | + echo "TAG=$(echo -n "${{ github.ref_name }}" \ + | tr --complement --squeeze-repeats '[:alnum:]._-' '_')" \ + >> "${GITHUB_ENV}" + # Image name must only contain lowercase letters + - run: | + echo "IMAGE=$(echo -n "${{ github.repository }}" \ + | tr '[:upper:]' '[:lower:]' )" \ + >> "${GITHUB_ENV}" + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: "ghcr.io/${{ env.IMAGE }}:${{ env.TAG }}"