frp/.github/workflows/docker.yml
2024-11-15 19:51:20 +08:00

82 lines
2.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 编译Docker镜像 # Actions名称
# 定义触发工作流的事件
on:
release:
types: [ published ] # 当发布新的GitHub release时触发
workflow_dispatch:
inputs:
tag:
description: 'Image tag' # 手动触发时输入的标签描述
required: true # 必须输入
default: 'test' # 默认标签为'test'
workflow_run:
workflows: ["GoReleaser Workflow"] # 指定工作流完成时触发
types: [completed] # 当goreleaser工作流完成时触发
permissions:
contents: read # 工作流需要读取仓库内容的权限
jobs:
image:
name: 从 Dockerfile 构建映像 # 工作流作业名称
runs-on: ubuntu-latest # 在最新的Ubuntu环境中运行
steps:
# 检出代码
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0' # 检出所有分支的历史记录
# 设置QEMU用于构建多平台镜像
- name: 设置 QEMU
uses: docker/setup-qemu-action@v3
# 设置Docker Buildx用于构建和推送多平台镜像
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
# 获取镜像标签名称
- name: 获取 Image Tag
# 注意 | 后注释会有问题故放在这
# 如果没有提供标签则使用GitHub Ref作为标签
# 如果提供了标签,则使用提供的标签
run: |
if [ x${{ github.event.inputs.tag }} == x"" ]; then
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
else
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
fi
# 登录到Docker Hub
- name: 登录 DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }} # Docker Hub用户名
password: ${{ secrets.DOCKERHUB_PASSWORD }} # Docker Hub密码
# 准备镜像标签
- name: 设置 Image Tags
# 注意 | 后注释会有问题故放在这
# 设置frp的Dockerfile路径
# 设置frp的镜像标签
run: |
echo "DOCKERFILE_FRP_PATH=dockerfiles/Dockerfile-for-frp" >> $GITHUB_ENV
echo "TAG_FRP=918178/frp:${{ env.TAG_NAME }}" >> $GITHUB_ENV
echo "TAG_FRP_LATEST=918178/frp:latest" >> $GITHUB_ENV
# 构建并推送frp镜像
- name: 编译并推送 Frp镜像
uses: docker/build-push-action@v5
with:
context: . # 构建上下文
file: ./dockerfiles/Dockerfile-for-frp # frp的Dockerfile
# platforms: linux/amd64 # 构建的平台(测试构建,少一些快一点)
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/mips64 # 构建的平台(正式构建)
push: true # 推送到仓库
# 注意 | 后注释会有问题故放在这
# frpc的镜像标签(版本标签+latest)
tags: |
${{ env.TAG_FRP }}
${{ env.TAG_FRP_LATEST }}