77
88jobs :
99 build-and-push :
10- name : 构建并推送 Docker 镜像
1110 runs-on : ubuntu-latest
1211 permissions :
1312 contents : read
1413 packages : write
1514
1615 steps :
17- - name : 检出代码
18- uses : actions/checkout@v4
16+ - uses : actions/checkout@v4
1917
20- - name : 将仓库名转为小写,设置环境变量
18+ - name : 设置小写仓库名变量
2119 run : echo "REPOSITORY_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
2220
23- - name : 设置 Docker Buildx
24- uses : docker/setup-buildx-action@v3
21+ - uses : docker/setup-buildx-action@v3
2522
26- - name : 登录到 GitHub Container Registry
27- uses : docker/login-action@v3
23+ - uses : docker/login-action@v3
2824 with :
2925 registry : ghcr.io
3026 username : ${{ github.actor }}
4642 with :
4743 context : ./backend
4844 push : true
49- tags : |
50- ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:${{ steps.meta.outputs.tags }}
51- ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:latest
45+ tags : ${{ steps.meta.outputs.tags }},ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:latest
5246 cache-from : type=gha
5347 cache-to : type=gha,mode=max
5448
5751 with :
5852 context : ./blog-web
5953 push : true
60- tags : |
61- ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:${{ steps.meta.outputs.tags }}
62- ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:latest
54+ tags : ${{ steps.meta.outputs.tags }},ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:latest
6355 cache-from : type=gha
6456 cache-to : type=gha,mode=max
6557 build-args : |
@@ -68,18 +60,15 @@ jobs:
6860
6961 - name : 更新 Docker Compose 文件
7062 run : |
71- # 取第一个标签(通常是 branch 或 sha 短哈希)
7263 VERSION=$(echo "${{ steps.meta.outputs.tags }}" | cut -d',' -f1)
7364 sed -i "s|build:\s*context: ./backend|image: ghcr.io/${REPOSITORY_LOWER}/backend:${VERSION}|g" docker-compose.yml
7465 sed -i "s|build:\s*context: ./blog-web|image: ghcr.io/${REPOSITORY_LOWER}/frontend:${VERSION}|g" docker-compose.yml
7566 env :
7667 REPOSITORY_LOWER : ${{ env.REPOSITORY_LOWER }}
7768
78- - name : 创建 Docker Compose 发布文件
79- run : cp docker-compose.yml docker-compose.release.yml
69+ - run : cp docker-compose.yml docker-compose.release.yml
8070
81- - name : 上传 Docker Compose 文件作为发布资产
82- uses : softprops/action-gh-release@v1
71+ - uses : softprops/action-gh-release@v1
8372 with :
8473 files : docker-compose.release.yml
8574 token : ${{ secrets.TOKEN }}
0 commit comments