docker-build-push/action.yml

60 lines
2.1 KiB
YAML
Raw Permalink Normal View History

2024-12-10 22:31:12 +00:00
name: 'build docker image and push to registry (default: code)'
inputs:
2024-12-10 22:43:50 +00:00
registry:
2024-12-10 22:31:12 +00:00
description: 'Docker registry URL'
required: true
2024-12-10 22:58:45 +00:00
default: '${{ vars.DOCKER_REGISTRY }}'
2024-12-10 22:43:50 +00:00
user:
2024-12-10 22:31:12 +00:00
description: 'Docker registry username'
required: true
2024-12-10 22:58:45 +00:00
default: '${{ vars.DOCKER_USER }}'
2024-12-10 22:43:50 +00:00
pass:
2024-12-10 22:31:12 +00:00
description: 'Docker registry password'
required: true
2024-12-10 22:58:45 +00:00
default: '${{ vars.DOCKER_PASS }}'
2024-12-10 22:43:50 +00:00
image:
2024-12-10 22:31:12 +00:00
description: 'Docker image name'
required: true
2024-12-10 22:58:45 +00:00
default: '${{ github.repository }}'
2024-12-10 22:43:50 +00:00
tag:
2024-12-10 22:31:12 +00:00
description: 'Docker image tag (default: main)'
required: false
2024-12-10 22:58:45 +00:00
default: '${{ github.ref_name }}'
2024-12-10 22:43:50 +00:00
platform:
2024-12-10 22:31:12 +00:00
description: 'Build platform (default: linux/amd64)'
required: false
2024-12-10 22:58:45 +00:00
default: 'linux/amd64'
2024-12-10 22:31:12 +00:00
dockerfile:
description: 'Path to the Dockerfile (default: Dockerfile)'
required: false
2024-12-10 22:58:45 +00:00
default: 'Dockerfile'
proxy:
description: 'Proxy URL'
required: false
default: 'http://100.100.13.14:8118' # 默认代理
no_proxy:
description: 'No proxy addresses'
required: false
default: '192.168.0.0/24,192.168.1.0/24,*.simcu.com,*.coce.ink,*.coce.cc' # 默认不使用代理的地址
2024-12-10 22:31:12 +00:00
runs:
using: 'composite'
steps:
- name: build docker image
uses: docker://docker:git
2024-12-10 22:49:42 +00:00
env:
DOCKER_BUILDKIT: 1
2024-12-10 22:58:45 +00:00
HTTPS_PROXY: ${{ inputs.proxy }} # 设置 HTTPS 代理
HTTP_PROXY: ${{ inputs.proxy }} # 设置 HTTPS 代理
NO_PROXY: ${{ inputs.no_proxy }} # 设置不使用代理的地址
2024-12-10 22:31:12 +00:00
with:
entrypoint: "/bin/sh"
args: |
2024-12-10 22:43:50 +00:00
-c 'docker ps && docker info && docker build --platform ${{ inputs.platform }} \
-t ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} -f ${{ inputs.dockerfile }} . && \
echo ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} 已经构建完了 && \
docker login ${{ inputs.registry }} -u ${{ inputs.user }} -p ${{ inputs.pass }} && \
docker push ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} && \
echo ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} 推送成功'