Chore: Add a optional input to determine whether putting the latest tag on docker image (#30)

This commit is contained in:
Pao Sheng
2024-03-21 18:15:11 +08:00
committed by GitHub
parent 7e0b340c68
commit e456677fa2
+24 -9
View File
@@ -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