From f09bdd70ddd8eaad8f3386b91a7a28f8a5af9d96 Mon Sep 17 00:00:00 2001 From: MohamadAli Date: Fri, 3 May 2024 02:26:52 +0330 Subject: [PATCH] enhancement: Add container image action --- .github/workflows/container-image.yaml | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/container-image.yaml diff --git a/.github/workflows/container-image.yaml b/.github/workflows/container-image.yaml new file mode 100644 index 000000000..81fd49b94 --- /dev/null +++ b/.github/workflows/container-image.yaml @@ -0,0 +1,52 @@ +name: Container Image + +on: + push: + branches: + - master + - main + tags: + - v** + release: + types: [published] + workflow_dispatch: + +jobs: + build-publish: + name: Build and publish container image + runs-on: ubuntu-latest + env: + CGO_ENABLED: 0 + PLATFORMS: linux/arm/v7,linux/arm64,linux/amd64 + steps: + - name: Checkout codebase + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + + - name: Setup `ko` + # The latest (@v0.6) version of this workflow has bug if there are uppercase letters in repo name + uses: ko-build/setup-ko@main + + - name: Extract metadata + uses: docker/metadata-action@v5 + id: meta + with: + # The images doesn't required, as only tags needed for the ko build step. + images: "" + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + type=sha,format=long + + - name: Build and push image + env: + TAGS: ${{ steps.meta.outputs.tags }} + run: ko build --platform "${PLATFORMS}" --bare --tags $(echo $TAGS | tr ' ' ',')