Skip to content

Commit 4d9f346

Browse files
committed
ci(docker): 将仓库名转为小写以避免Docker镜像构建问题
为确保Docker镜像名称的一致性,将仓库名转换为小写。这解决了某些环境下由于大小写敏感导致的镜像构建失败问题。
1 parent d0e0ead commit 4d9f346

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

.github/workflows/docker-publish.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ jobs:
1313
contents: read
1414
packages: write
1515

16+
env:
17+
REPOSITORY_LOWER: ${{ github.repository }}
18+
1619
steps:
1720
- name: 检出代码
1821
uses: actions/checkout@v4
1922

23+
- name: 将仓库名转为小写
24+
id: lowercase
25+
run: echo "REPOSITORY_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
26+
2027
- name: 设置 Docker Buildx
2128
uses: docker/setup-buildx-action@v3
2229

@@ -32,8 +39,8 @@ jobs:
3239
uses: docker/metadata-action@v5
3340
with:
3441
images: |
35-
ghcr.io/${{ github.repository }}/backend
36-
ghcr.io/${{ github.repository }}/frontend
42+
ghcr.io/${{ env.REPOSITORY_LOWER }}/backend
43+
ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend
3744
tags: |
3845
type=semver,pattern={{version}}
3946
type=semver,pattern={{major}}.{{minor}}
@@ -45,7 +52,7 @@ jobs:
4552
with:
4653
context: ./backend
4754
push: true
48-
tags: ghcr.io/${{ github.repository }}/backend:${{ steps.meta.outputs.version }},ghcr.io/${{ github.repository }}/backend:latest
55+
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:${{ steps.meta.outputs.version }},ghcr.io/${{ env.REPOSITORY_LOWER }}/backend:latest
4956
cache-from: type=gha
5057
cache-to: type=gha,mode=max
5158

@@ -54,7 +61,7 @@ jobs:
5461
with:
5562
context: ./blog-web
5663
push: true
57-
tags: ghcr.io/${{ github.repository }}/frontend:${{ steps.meta.outputs.version }},ghcr.io/${{ github.repository }}/frontend:latest
64+
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:${{ steps.meta.outputs.version }},ghcr.io/${{ env.REPOSITORY_LOWER }}/frontend:latest
5865
cache-from: type=gha
5966
cache-to: type=gha,mode=max
6067
build-args: |
@@ -64,15 +71,16 @@ jobs:
6471
- name: 更新 Docker Compose 文件
6572
run: |
6673
VERSION=${{ steps.meta.outputs.version }}
67-
sed -i "s|build:\s*context: ./backend|image: ghcr.io/${{ github.repository }}/backend:${VERSION}|g" docker-compose.yml
68-
sed -i "s|build:\s*context: ./blog-web|image: ghcr.io/${{ github.repository }}/frontend:${VERSION}|g" docker-compose.yml
74+
sed -i "s|build:\s*context: ./backend|image: ghcr.io/${REPOSITORY_LOWER}/backend:${VERSION}|g" docker-compose.yml
75+
sed -i "s|build:\s*context: ./blog-web|image: ghcr.io/${REPOSITORY_LOWER}/frontend:${VERSION}|g" docker-compose.yml
76+
env:
77+
REPOSITORY_LOWER: ${{ env.REPOSITORY_LOWER }}
6978

7079
- name: 创建 Docker Compose 发布文件
71-
run: |
72-
cp docker-compose.yml docker-compose.release.yml
80+
run: cp docker-compose.yml docker-compose.release.yml
7381

7482
- name: 上传 Docker Compose 文件作为发布资产
7583
uses: softprops/action-gh-release@v1
7684
with:
7785
files: docker-compose.release.yml
78-
token: ${{ secrets.TOKEN }}
86+
token: ${{ secrets.TOKEN }}

0 commit comments

Comments
 (0)