Skip to content

Commit ac3d130

Browse files
夏一飞夏一飞
authored andcommitted
ci: add Docker Hub login and push to workflow
1 parent ce8d643 commit ac3d130

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

.github/workflows/docker-publish.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
env:
1010
REGISTRY: ghcr.io
1111
IMAGE_NAME: ${{ github.repository }}
12+
DOCKERHUB_REGISTRY: docker.io
13+
DOCKERHUB_IMAGE_NAME: your_dockerhub_username/your_image_name
1214

1315
jobs:
1416
build:
@@ -39,13 +41,23 @@ jobs:
3941
username: ${{ github.actor }}
4042
password: ${{ secrets.GITHUB_TOKEN }}
4143

44+
# 登录到 Docker Hub
45+
- name: Log into Docker Hub
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.DOCKERHUB_REGISTRY }}
50+
username: ${{ secrets.DOCKERHUB_USERNAME }}
51+
password: ${{ secrets.DOCKERHUB_TOKEN }}
52+
4253
# 提取 Docker 元数据
4354
- name: Extract Docker metadata
4455
id: meta
4556
uses: docker/metadata-action@v5
4657
with:
4758
images: |
4859
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60+
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}
4961
tags: |
5062
type=ref,event=branch
5163
type=ref,event=pr
@@ -54,7 +66,7 @@ jobs:
5466
type=sha
5567
type=raw,value=latest,enable={{is_default_branch}}
5668
57-
# 构建并推送到 GHCR
69+
# 构建并推送到 GHCR 和 Docker Hub
5870
- name: Build and push Docker image
5971
uses: docker/build-push-action@v5
6072
with:

0 commit comments

Comments
 (0)