frp/.github/workflows/docker.yml
2024-11-15 17:05:30 +08:00

93 lines
3.7 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: Build Image and Publish to Dockerhub & GPR
# 定义触发工作流的事件
on:
release:
types: [ published ] # 当发布新的GitHub release时触发
workflow_dispatch:
inputs:
tag:
description: 'Image tag' # 手动触发时输入的标签描述
required: true # 必须输入
default: 'test' # 默认标签为'test'
permissions:
contents: read # 工作流需要读取仓库内容的权限
jobs:
image:
name: Build Image from Dockerfile and binaries # 工作流作业名称
runs-on: ubuntu-latest # 在最新的Ubuntu环境中运行
steps:
# 检出代码
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0' # 检出所有分支的历史记录
# 设置QEMU用于构建多平台镜像
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# 设置Docker Buildx用于构建和推送多平台镜像
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 获取镜像标签名称
- name: Get Image Tag Name
run: |
if [ x${{ github.event.inputs.tag }} == x"" ]; then
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # 如果没有提供标签则使用GitHub Ref作为标签
else
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV # 如果提供了标签,则使用提供的标签
fi
# 登录到Docker Hub
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }} # Docker Hub用户名
password: ${{ secrets.DOCKERHUB_PASSWORD }} # Docker Hub密码
# 登录到GitHub Package Registry
- name: Login to the GPR
uses: docker/login-action@v3
with:
registry: ghcr.io # GPR的地址
username: ${{ github.repository_owner }} # GitHub仓库所有者
password: ${{ secrets.GPR_TOKEN }} # GPR的访问令牌
# 准备镜像标签
- name: Prepare Image Tags
run: |
echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV # 设置frpc的Dockerfile路径
echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV # 设置frps的Dockerfile路径
echo "TAG_FRPC=fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV # 设置frpc的镜像标签
echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV # 设置frps的镜像标签
echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV # 设置GPR上frpc的镜像标签
echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV # 设置GPR上frps的镜像标签
# 构建并推送frpc镜像
- name: Build and push frpc
uses: docker/build-push-action@v5
with:
context: . # 构建上下文
file: ./dockerfiles/Dockerfile-for-frpc # frpc的Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x # 构建的平台
push: true # 推送到仓库
tags: |
${{ env.TAG_FRPC }} # frpc的镜像标签
${{ env.TAG_FRPC_GPR }} # GPR上frpc的镜像标签
# 构建并推送frps镜像
- name: Build and push frps
uses: docker/build-push-action@v5
with:
context: . # 构建上下文
file: ./dockerfiles/Dockerfile-for-frps # frps的Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x # 构建的平台
push: true # 推送到仓库
tags: |
${{ env.TAG_FRPS }} # frps的镜像标签
${{ env.TAG_FRPS_GPR }} # GPR上frps的镜像标签