From e456677fa22efc82adee975f11269cb6d95311be Mon Sep 17 00:00:00 2001 From: Pao Sheng Date: Thu, 21 Mar 2024 18:15:11 +0800 Subject: [PATCH] Chore: Add a optional input to determine whether putting the latest tag on docker image (#30) --- .github/workflows/ai-service-build-image.yaml | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ai-service-build-image.yaml b/.github/workflows/ai-service-build-image.yaml index e81322fa4..89721d54e 100644 --- a/.github/workflows/ai-service-build-image.yaml +++ b/.github/workflows/ai-service-build-image.yaml @@ -4,8 +4,13 @@ on: workflow_dispatch: inputs: docker_image_tag_name: - type: string description: Docker image tag name (Optional) + type: string + is_latest: + description: Is latest (Optional) + type: boolean + required: false + default: false defaults: run: @@ -27,19 +32,29 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Prepare tag name - id: prepare_tag + id: tag-preparation run: | if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then tag_name=${{ github.event.inputs.docker_image_tag_name }} else tag_name=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')-$(git log -1 --pretty=%h) fi - echo ::set-output name=tag_name::$tag_name + echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT - name: Build and push image + env: + TAG_NAME: ${{ steps.tag-preparation.outputs.TAG_NAME }} run: | - docker buildx build \ - --platform linux/amd64,linux/arm64 \ - --tag ghcr.io/canner/wren-ai-service:${{ steps.prepare_tag.outputs.tag_name }} \ - --tag ghcr.io/canner/wren-ai-service:latest \ - --file ./docker/Dockerfile \ - --push . + if [ ${{ github.event.inputs.is_latest }} == true ]; then + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/canner/wren-ai-service:$TAG_NAME \ + --tag ghcr.io/canner/wren-ai-service:latest \ + --file ./docker/Dockerfile \ + --push . + else + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/canner/wren-ai-service:$TAG_NAME \ + --file ./docker/Dockerfile \ + --push . + fi