Skip to content

Commit 8d74439

Browse files
committed
Add GitHub workflow files
1 parent 8f9b069 commit 8d74439

1 file changed

Lines changed: 50 additions & 46 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,87 @@
1-
name: Build and Push Docker Image
1+
name: Publish Docker Image
22

33
on:
44
push:
55
branches:
66
- main
7-
- develop
87
tags:
9-
- 'v*.*.*'
8+
- '*'
109
paths:
1110
- 'api-service/**'
1211
- '.github/workflows/docker-image.yml'
13-
pull_request:
14-
branches:
15-
- main
16-
paths:
17-
- 'api-service/**'
1812
workflow_dispatch:
13+
inputs:
14+
name:
15+
description: 'Person to greet'
16+
required: true
17+
default: 'Mona the Octocat'
18+
home:
19+
description: 'location'
20+
required: false
21+
default: 'The Octoverse'
1922

2023
env:
21-
REGISTRY: docker.io
22-
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/wechat-decrypt-api
24+
APP_NAME: wechat-decrypt-api
25+
DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_USERNAME }}/wechat-decrypt-api
2326

2427
jobs:
25-
build-and-push:
28+
main:
2629
runs-on: ubuntu-latest
27-
permissions:
28-
contents: read
29-
packages: write
30-
3130
steps:
32-
- name: Checkout repository
31+
# git checkout 代码
32+
- name: Checkout
3333
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0 # 获取完整的 git 历史,以便 git describe 工作
3436

37+
# 设置 QEMU, 后面 docker buildx 依赖此
3538
- name: Set up QEMU
3639
uses: docker/setup-qemu-action@v3
3740

41+
# 设置 Docker buildx, 方便构建 Multi platform 镜像
3842
- name: Set up Docker Buildx
3943
uses: docker/setup-buildx-action@v3
4044

41-
- name: Log in to Docker Hub
42-
if: github.event_name != 'pull_request'
45+
# 登录 docker hub
46+
- name: Login to DockerHub
4347
uses: docker/login-action@v3
4448
with:
4549
username: ${{ secrets.DOCKERHUB_USERNAME }}
4650
password: ${{ secrets.DOCKERHUB_TOKEN }}
4751

48-
- name: Extract metadata (tags, labels)
49-
id: meta
50-
uses: docker/metadata-action@v5
51-
with:
52-
images: ${{ env.IMAGE_NAME }}
53-
tags: |
54-
type=ref,event=branch
55-
type=ref,event=pr
56-
type=semver,pattern={{version}}
57-
type=semver,pattern={{major}}.{{minor}}
58-
type=semver,pattern={{major}}
59-
type=raw,value=latest,enable={{is_default_branch}}
60-
type=sha,prefix={{branch}}-
52+
# 通过 git 命令获取当前 tag 信息, 存入环境变量 APP_VERSION
53+
- name: Generate App Version
54+
run: echo APP_VERSION=`git describe --tags --always` >> $GITHUB_ENV
6155

62-
- name: Build and push Docker image
56+
# 构建 Docker 并推送到 Docker hub
57+
- name: Build and push
58+
id: docker_build
6359
uses: docker/build-push-action@v5
6460
with:
6561
context: ./api-service
6662
file: ./api-service/Dockerfile
67-
platforms: linux/amd64,linux/arm64
68-
push: ${{ github.event_name != 'pull_request' }}
69-
tags: ${{ steps.meta.outputs.tags }}
70-
labels: ${{ steps.meta.outputs.labels }}
63+
push: true
64+
# 生成多平台镜像
65+
platforms: |
66+
linux/amd64
67+
linux/arm64
68+
# docker build arg, 注入 APP_NAME/APP_VERSION
69+
build-args: |
70+
APP_NAME=${{ env.APP_NAME }}
71+
APP_VERSION=${{ env.APP_VERSION }}
72+
# 生成两个 docker tag: ${APP_VERSION} 和 latest
73+
tags: |
74+
${{ env.DOCKERHUB_REPO }}:latest
75+
${{ env.DOCKERHUB_REPO }}:${{ env.APP_VERSION }}
7176
cache-from: type=gha
7277
cache-to: type=gha,mode=max
7378

74-
# 注意: 如果需要自动更新 Docker Hub 描述,请确保 DOCKERHUB_TOKEN 具有 "Read, Write & Delete" 权限
75-
# 或者手动在 Docker Hub 上更新仓库描述
76-
# - name: Docker Hub Description
77-
# if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
78-
# uses: peter-evans/dockerhub-description@v4
79-
# with:
80-
# username: ${{ secrets.DOCKERHUB_USERNAME }}
81-
# password: ${{ secrets.DOCKERHUB_TOKEN }}
82-
# repository: ${{ env.IMAGE_NAME }}
83-
# readme-filepath: ./api-service/README.md
79+
# 自动更新 Docker Hub 描述(从 README.md 同步到 overview)
80+
- name: Update Docker Hub Description
81+
uses: peter-evans/dockerhub-description@v4
82+
with:
83+
username: ${{ secrets.DOCKERHUB_USERNAME }}
84+
password: ${{ secrets.DOCKERHUB_TOKEN }}
85+
repository: ${{ env.DOCKERHUB_REPO }}
86+
readme-filepath: ./README.md
87+
short-description: "微信视频号解密工具 API 服务 - 基于 Isaac64 PRNG 算法的视频解密服务"

0 commit comments

Comments
 (0)