Skip to content

Commit 05e8b58

Browse files
committed
Use docker/login-action to do the GHCR login
1 parent 3877093 commit 05e8b58

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.github/workflows/publish.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v2
1111

12+
- name: Login to GitHub Container Registry
13+
uses: docker/login-action@v1
14+
with:
15+
registry: ghcr.io
16+
username: ${{ github.actor }}
17+
password: ${{ secrets.GITHUB_TOKEN }}
18+
1219
- name: Build the hello-world Docker image
1320
run: |
14-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u jonashackt --password-stdin
1521
docker build . --tag ghcr.io/jonashackt/hello-world:latest
1622
docker run ghcr.io/jonashackt/hello-world:latest
1723
docker push ghcr.io/jonashackt/hello-world:latest

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,22 @@ jobs:
132132

133133
- name: Build the hello-world Docker image
134134
run: |
135-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u jonashackt --password-stdin
135+
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
136136
137137
```
138138
139+
or Alternatively we can also use the [docker/login-action](https://github.com/docker/login-action) to to the login:
140+
141+
```yaml
142+
- name: Login to GitHub Container Registry
143+
uses: docker/login-action@v1
144+
with:
145+
registry: ghcr.io
146+
username: ${{ github.actor }}
147+
password: ${{ secrets.GITHUB_TOKEN }}
148+
```
149+
150+
139151
#### Publish (Push) Container image to GHCR
140152
141153
The final step now is to push our container image to the GitHub Container Registry. Therefore we need to tag our image correctly while building it using `ghcr.io/OWNER/IMAGE_NAME:latest`. After that we can push it:

0 commit comments

Comments
 (0)