51 lines
2.3 KiB
YAML
51 lines
2.3 KiB
YAML
name: 'build docker image and push to registry (default: code)'
|
|
|
|
inputs:
|
|
docker_registry:
|
|
description: 'Docker registry URL'
|
|
required: true
|
|
default: '${{ vars.DOCKER_REGISTRY }}' # 使用原 vars 值作为默认值
|
|
docker_user:
|
|
description: 'Docker registry username'
|
|
required: true
|
|
default: '${{ vars.DOCKER_USER }}' # 使用原 vars 值作为默认值
|
|
docker_pass:
|
|
description: 'Docker registry password'
|
|
required: true
|
|
default: '${{ vars.DOCKER_PASS }}' # 使用原 vars 值作为默认值
|
|
docker_image_name:
|
|
description: 'Docker image name'
|
|
required: true
|
|
default: '${{ github.repository }}' # 使用 GitHub 仓库名称作为默认值
|
|
docker_tag:
|
|
description: 'Docker image tag (default: main)'
|
|
required: false
|
|
default: '${{ github.ref_name }}' # 使用 GitHub 分支名称作为默认值
|
|
docker_build_args:
|
|
description: 'Additional build arguments for Docker build'
|
|
required: false
|
|
default: ''
|
|
build_platform:
|
|
description: 'Build platform (default: linux/amd64)'
|
|
required: false
|
|
default: 'linux/amd64' # 默认构建平台为 x86
|
|
dockerfile:
|
|
description: 'Path to the Dockerfile (default: Dockerfile)'
|
|
required: false
|
|
default: 'Dockerfile' # 默认 Dockerfile 名称
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: build docker image
|
|
uses: docker://docker:git
|
|
with:
|
|
entrypoint: "/bin/sh"
|
|
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 }} . && \
|
|
echo ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} 已经构建完了 && \
|
|
echo ${{ inputs.docker_registry }} && \
|
|
docker login ${{ inputs.docker_registry }} -u ${{ inputs.docker_user }} -p ${{ inputs.docker_pass }} && \
|
|
docker push ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} && \
|
|
echo ${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_tag }} 推送成功'
|