Skip to content

Commit aa376a7

Browse files
committed
chore: 自动构建镜像并推送到 docker hub
1 parent 7df6fb0 commit aa376a7

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

.github/workflows/dockerbuild.yml

+14-21
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,34 @@ name: Create and publish a Docker image
22

33
on:
44
push:
5-
tags:
6-
- '*'
7-
8-
env:
9-
REGISTRY: ghcr.io
10-
IMAGE_NAME: ${{ github.repository }}
5+
branches: ["master"]
116

127
jobs:
13-
build-and-push-image:
8+
push_to_registry:
9+
name: Push Docker image to Docker Hub
10+
environment: production
1411
runs-on: ubuntu-latest
15-
permissions:
16-
contents: read
17-
packages: write
18-
1912
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@v3
13+
- name: Check out the repo
14+
uses: actions/checkout@v4
2215

23-
- name: Log in to the Container registry
24-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
16+
- name: Login to Docker Hub
17+
uses: docker/login-action@v3.0.0
2518
with:
26-
registry: ${{ env.REGISTRY }}
27-
username: ${{ github.actor }}
28-
password: ${{ secrets.GITHUB_TOKEN }}
19+
username: ${{ secrets.DOCKERHUB_USERNAME }}
20+
password: ${{ secrets.DOCKERHUB_TOKEN }}
2921

3022
- name: Extract metadata (tags, labels) for Docker
3123
id: meta
32-
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
24+
uses: docker/metadata-action@v5.5.1
3325
with:
34-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
26+
images: dedicatus545/github-cors-server
3527

3628
- name: Build and push Docker image
37-
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
29+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
3830
with:
3931
context: .
32+
file: ./Dockerfile
4033
push: true
4134
tags: ${{ steps.meta.outputs.tags }}
4235
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)