mirror of
https://github.com/yanhao98/composite-actions.git
synced 2025-07-13 23:00:48 +08:00
70 lines
2.1 KiB
YAML
70 lines
2.1 KiB
YAML
name: "打包推送 Docker 镜像"
|
|
description: "打包 Docker 镜像并推送到 Docker Hub"
|
|
inputs:
|
|
build_file:
|
|
description: "Dockerfile 文件路径"
|
|
default: "./Dockerfile"
|
|
required: false
|
|
build_context:
|
|
description: "Docker 构建上下文路径"
|
|
default: "."
|
|
required: false
|
|
build_platforms:
|
|
description: "Docker 构建平台"
|
|
default: "linux/amd64,linux/arm64"
|
|
required: false
|
|
build_push:
|
|
description: "是否推送 Docker 镜像"
|
|
required: false
|
|
build_load:
|
|
description: "是否加载 Docker 镜像"
|
|
default: "false"
|
|
required: false
|
|
metadata_images:
|
|
description: "docker/metadata-action 的 images 参数"
|
|
required: false
|
|
metadata_tags:
|
|
description: "docker/metadata-action 的 tags 参数"
|
|
required: false
|
|
outputs:
|
|
imageid:
|
|
description: "Docker 镜像 ID"
|
|
value: ${{ steps.build.outputs.imageid }}
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- uses: actions/checkout@main
|
|
with:
|
|
filter: blob:none
|
|
show-progress: false
|
|
# https://docs.docker.com/build/ci/github-actions/push-multi-registries/
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5 # https://github.com/docker/metadata-action
|
|
with:
|
|
context: git
|
|
# flavor
|
|
images: ${{ inputs.metadata_images }}
|
|
tags: ${{ inputs.metadata_tags }}
|
|
# sep-tags: ','
|
|
# sep-labels: ','
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Build and push
|
|
id: build
|
|
uses: docker/build-push-action@v6 # https://github.com/docker/build-push-action
|
|
with:
|
|
file: ${{ inputs.build_file }}
|
|
context: ${{ inputs.build_context }}
|
|
platforms: ${{ inputs.build_platforms }}
|
|
push: ${{ inputs.build_push }}
|
|
load: ${{ inputs.build_load }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
# cache-from: type=local,src=/tmp/.buildx-cache
|
|
# cache-to: type=local,dest=/tmp/.buildx-cache
|