Skip to content

Commit 538d417

Browse files
authored
Update publish-image-ghcr.yml
1 parent 2b6bec1 commit 538d417

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

.github/workflows/publish-image-ghcr.yml

+23-20
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,37 @@ on:
66
pull_request:
77
branches: [main]
88

9-
jobs:
10-
build_container:
11-
name: Build Docker image
12-
if: github.event_name == 'pull_request'
9+
jobs:
10+
build_docker:
11+
name: Build and push Docker image to Github Container Registry
1312
runs-on: ubuntu-20.04
13+
permissions:
14+
packages: write
15+
contents: read
1416
steps:
15-
- name: Build the image
16-
uses: docker/build-push-action@v3
17-
with:
18-
context: .
19-
tags: user/app:latest
20-
21-
push_to_registry:
22-
name: Push Docker image to Github Container Registry
23-
if: github.event_name == 'release'
24-
runs-on: ubuntu-20.04
25-
needs: [build_container]
26-
steps:
17+
- name: Checkout project
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
2723
- name: Login to GHCR
2824
uses: docker/login-action@v2
2925
with:
3026
registry: ghcr.io
3127
username: ${{ github.actor }}
3228
password: ${{ secrets.GITHUB_TOKEN }}
33-
34-
- name: Build and push image to GHCR
29+
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/[email protected]
33+
with:
34+
images: ghcr.io/${{ github.repository }}
35+
36+
- name: Build and push (if release) image to GHCR
3537
uses: docker/build-push-action@v3
3638
with:
3739
context: .
38-
push: true
39-
tags: user/app:latest
40+
push: ${{ github.event_name == 'release' }}
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)