From 133026f5dfb284cfdf35ba4ebc34400b3d900aab Mon Sep 17 00:00:00 2001 From: toras9000 Date: Mon, 22 Aug 2022 22:31:12 +0900 Subject: [PATCH] Image build workflow --- .github/workflows/docker-publish.yml | 73 ++++++++++++++++++++++++++++ docker-bake.hcl | 36 ++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 docker-bake.hcl diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..bbaa487 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,73 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: +# - 'main' + - 'v*.*.*' + workflow_dispatch: + inputs: + with_latest: + type: boolean + description: 'With latest tag' + required: false + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get repository info + id: repo-info + run: | + git fetch --no-tags --prune --depth=1 origin latest || true + echo "latest-hash=$(git show --quiet --format=%H origin/latest || echo '')" >> "$GITHUB_OUTPUT" + echo "trigger-hash=$(git show --quiet --format=%H ${{ github.ref }})" >> "$GITHUB_OUTPUT" + + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: toras9000 + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Log into registry ghcr.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + id: bake-image + uses: docker/bake-action@v4 + with: + files: ./docker-bake.hcl + pull: true + push: true + set: | + *.cache-from=type=gha + *.cache-to=type=gha + env: + WORKFLOW_GITHUB_REF: ${{ github.ref }} + WITH_LATEST_TAG: ${{ steps.repo-info.outputs.trigger-hash == steps.repo-info.outputs.latest-hash }} diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..612a516 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,36 @@ +variable "WITH_LATEST_TAG" { + default = false +} + +variable "KALLITHEA_IMAGE_VER" { + default = "x.x.x" +} + +variable "KALLITHEA_FLAVOR" { + default = [""] +} + +group "default" { + targets = ["kallithea"] +} + +variable "flavor_tags" { + default = [for f in KALLITHEA_FLAVOR : f == "" ? KALLITHEA_IMAGE_VER : "${KALLITHEA_IMAGE_VER}-${f}"] +} + +target "kallithea" { + context = "./build" + args = { + KALLITHEA_VER = "${KALLITHEA_IMAGE_VER}" + } + platforms = [ + "linux/amd64", + "linux/arm64", + "linux/arm/v7", + ] + tags = concat( + formatlist("toras9000/kallithea-mp:%s", flavor_tags), + formatlist("ghcr.io/toras9000/docker-kallithea:%s", flavor_tags), + WITH_LATEST_TAG ? ["toras9000/kallithea-mp:latest", "ghcr.io/toras9000/docker-kallithea:latest"] : [] + ) +}