This commit is contained in:
xRain 2024-12-11 06:43:50 +08:00
parent acf2adc625
commit 75d7c316e4

View File

@ -1,31 +1,27 @@
name: 'build docker image and push to registry (default: code)' name: 'build docker image and push to registry (default: code)'
inputs: inputs:
docker_registry: registry:
description: 'Docker registry URL' description: 'Docker registry URL'
required: true required: true
default: '${{ vars.DOCKER_REGISTRY }}' # 使用原 vars 值作为默认值 default: '${{ vars.DOCKER_REGISTRY }}' # 使用原 vars 值作为默认值
docker_user: user:
description: 'Docker registry username' description: 'Docker registry username'
required: true required: true
default: '${{ vars.DOCKER_USER }}' # 使用原 vars 值作为默认值 default: '${{ vars.DOCKER_USER }}' # 使用原 vars 值作为默认值
docker_pass: pass:
description: 'Docker registry password' description: 'Docker registry password'
required: true required: true
default: '${{ vars.DOCKER_PASS }}' # 使用原 vars 值作为默认值 default: '${{ vars.DOCKER_PASS }}' # 使用原 vars 值作为默认值
docker_image_name: image:
description: 'Docker image name' description: 'Docker image name'
required: true required: true
default: '${{ github.repository }}' # 使用 GitHub 仓库名称作为默认值 default: '${{ github.repository }}' # 使用 GitHub 仓库名称作为默认值
docker_tag: tag:
description: 'Docker image tag (default: main)' description: 'Docker image tag (default: main)'
required: false required: false
default: '${{ github.ref_name }}' # 使用 GitHub 分支名称作为默认值 default: '${{ github.ref_name }}' # 使用 GitHub 分支名称作为默认值
docker_build_args: platform:
description: 'Additional build arguments for Docker build'
required: false
default: ''
build_platform:
description: 'Build platform (default: linux/amd64)' description: 'Build platform (default: linux/amd64)'
required: false required: false
default: 'linux/amd64' # 默认构建平台为 x86 default: 'linux/amd64' # 默认构建平台为 x86
@ -42,9 +38,9 @@ runs:
with: with:
entrypoint: "/bin/sh" entrypoint: "/bin/sh"
args: | args: |
-c 'docker ps && docker info && docker build --platform ${{ inputs.build_platform }} ${ { inputs.docker_build_args } } -t ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} -f ${{ inputs.dockerfile }} . && \ -c 'docker ps && docker info && docker build --platform ${{ inputs.platform }} \
echo ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} 已经构建完了 && \ -t ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} -f ${{ inputs.dockerfile }} . && \
echo ${{ inputs.docker_registry }} && \ echo ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} 已经构建完了 && \
docker login ${{ inputs.docker_registry }} -u ${{ inputs.docker_user }} -p ${{ inputs.docker_pass }} && \ docker login ${{ inputs.registry }} -u ${{ inputs.user }} -p ${{ inputs.pass }} && \
docker push ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} && \ docker push ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} && \
echo ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} 推送成功' echo ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} 推送成功'