From 0c7c80cb3adf6c7d25f0bbee7ac049a44fba1670 Mon Sep 17 00:00:00 2001 From: Ruben Nijveld Date: Sun, 7 Apr 2024 12:35:02 +0200 Subject: [PATCH] Split up docker image building for re-use --- .github/workflows/docker-image.yml | 66 ++++++++++++++++++++++++++++++ .github/workflows/docker.yml | 38 ++++------------- 2 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..e08b61d --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,66 @@ +name: Docker Image + +on: + workflow_call: + inputs: + tags: + description: "List of image tags (newline separated) for the resulting docker image" + required: true + type: string + push: + description: "If true, the image will be pushed to the registry" + required: false + default: false + type: boolean + platforms: + description: "Comma separated list of platforms to build the image for" + required: false + default: "linux/amd64,linux/arm64" + type: string + context: + description: "Context directory for the docker build" + required: false + default: "." + type: string + build-args: + description: "List of build arguments (newline separated) to be inserted in the docker build" + required: false + default: "" + type: string + file: + description: "Name of the dockerfile to build" + required: false + default: "Dockerfile" + type: string + +jobs: + image: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build${{ inputs.push && ' and push' || ''}} + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 + with: + context: "${{ inputs.context }}" + file: "${{ inputs.file }}" + platforms: "${{ inputs.platforms }}" + no-cache: true + pull: true + build-args: "${{ inputs.build-args }}" + push: ${{ inputs.push }} + tags: "${{ inputs.tags }}" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 99c52c1..6413a46 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,11 +1,10 @@ name: Docker on: - workflow_call: {} + workflow_call: jobs: - build: - runs-on: ubuntu-latest + docker: strategy: matrix: include: @@ -18,34 +17,13 @@ jobs: - version: bullseye latest: false alt: oldstable - steps: - - name: Checkout sources - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 - - - name: Login to GitHub Container Registry - uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 - with: - context: . - platforms: linux/amd64,linux/arm64 - no-cache: true - pull: true - build-args: | + uses: "./.github/workflows/docker-image.yml" + secrets: inherit + with: + push: ${{ github.ref == 'refs/heads/main' }} + build-args: | DEBIAN_VERSION=${{matrix.version}} - push: ${{ github.ref == 'refs/heads/main' }} - tags: | + tags: | ghcr.io/tweedegolf/debian:${{matrix.version}} ghcr.io/tweedegolf/debian:${{matrix.alt}} ${{ matrix.latest && 'ghcr.io/tweedegolf/debian:latest' || '' }}