|
1 | | -name: Build and Push Docker Image |
| 1 | +name: Publish Docker Image |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | | - - develop |
8 | 7 | tags: |
9 | | - - 'v*.*.*' |
| 8 | + - '*' |
10 | 9 | paths: |
11 | 10 | - 'api-service/**' |
12 | 11 | - '.github/workflows/docker-image.yml' |
13 | | - pull_request: |
14 | | - branches: |
15 | | - - main |
16 | | - paths: |
17 | | - - 'api-service/**' |
18 | 12 | 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' |
19 | 22 |
|
20 | 23 | 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 |
23 | 26 |
|
24 | 27 | jobs: |
25 | | - build-and-push: |
| 28 | + main: |
26 | 29 | runs-on: ubuntu-latest |
27 | | - permissions: |
28 | | - contents: read |
29 | | - packages: write |
30 | | - |
31 | 30 | steps: |
32 | | - - name: Checkout repository |
| 31 | + # git checkout 代码 |
| 32 | + - name: Checkout |
33 | 33 | uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 # 获取完整的 git 历史,以便 git describe 工作 |
34 | 36 |
|
| 37 | + # 设置 QEMU, 后面 docker buildx 依赖此 |
35 | 38 | - name: Set up QEMU |
36 | 39 | uses: docker/setup-qemu-action@v3 |
37 | 40 |
|
| 41 | + # 设置 Docker buildx, 方便构建 Multi platform 镜像 |
38 | 42 | - name: Set up Docker Buildx |
39 | 43 | uses: docker/setup-buildx-action@v3 |
40 | 44 |
|
41 | | - - name: Log in to Docker Hub |
42 | | - if: github.event_name != 'pull_request' |
| 45 | + # 登录 docker hub |
| 46 | + - name: Login to DockerHub |
43 | 47 | uses: docker/login-action@v3 |
44 | 48 | with: |
45 | 49 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
46 | 50 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
47 | 51 |
|
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 |
61 | 55 |
|
62 | | - - name: Build and push Docker image |
| 56 | + # 构建 Docker 并推送到 Docker hub |
| 57 | + - name: Build and push |
| 58 | + id: docker_build |
63 | 59 | uses: docker/build-push-action@v5 |
64 | 60 | with: |
65 | 61 | context: ./api-service |
66 | 62 | 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 }} |
71 | 76 | cache-from: type=gha |
72 | 77 | cache-to: type=gha,mode=max |
73 | 78 |
|
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