Skip to content

Commit ffb9eeb

Browse files
committed
ci: 更新 Docker 镜像标签生成逻辑
移除旧的 semver 标签模式,改为使用分支和短哈希作为标签。同时优化了 Docker Compose 文件的更新逻辑,确保使用正确的镜像版本。
1 parent 59fc795 commit ffb9eeb

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
ghcr.io/${{ env.REPOSITORY_LOWER }}/backend
3939
ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend
4040
tags: |
41-
type=semver,pattern={{version}}
42-
type=semver,pattern={{major}}.{{minor}}
4341
type=ref,event=branch
4442
type=sha,format=short
4543
@@ -48,7 +46,9 @@ jobs:
4846
with:
4947
context: ./backend
5048
push: true
51-
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:${{ steps.meta.outputs.version }},ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:latest
49+
tags: |
50+
ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:${{ steps.meta.outputs.tags }}
51+
ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:latest
5252
cache-from: type=gha
5353
cache-to: type=gha,mode=max
5454

@@ -57,7 +57,9 @@ jobs:
5757
with:
5858
context: ./blog-web
5959
push: true
60-
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:${{ steps.meta.outputs.version }},ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:latest
60+
tags: |
61+
ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:${{ steps.meta.outputs.tags }}
62+
ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:latest
6163
cache-from: type=gha
6264
cache-to: type=gha,mode=max
6365
build-args: |
@@ -66,7 +68,8 @@ jobs:
6668
6769
- name: 更新 Docker Compose 文件
6870
run: |
69-
VERSION=${{ steps.meta.outputs.version }}
71+
# 取第一个标签(通常是 branch 或 sha 短哈希)
72+
VERSION=$(echo "${{ steps.meta.outputs.tags }}" | cut -d',' -f1)
7073
sed -i "s|build:\s*context: ./backend|image: ghcr.io/${REPOSITORY_LOWER}/backend:${VERSION}|g" docker-compose.yml
7174
sed -i "s|build:\s*context: ./blog-web|image: ghcr.io/${REPOSITORY_LOWER}/frontend:${VERSION}|g" docker-compose.yml
7275
env:

0 commit comments

Comments
 (0)