Skip to content

Commit bd7cfbe

Browse files
ed rep ghrc
1 parent e6c2def commit bd7cfbe

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

.github/workflows/docker.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,43 @@ name: powerdns
22

33
on:
44
push:
5-
branches:
6-
-
7-
"master"
85

96
env:
10-
IMAGE_NAME: "powerdns"
11-
VERSION: "latest"
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: ${{ github.repository }}
9+
1210
jobs:
13-
push:
14-
name: Build and push to Docker Hub
11+
build:
12+
1513
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
1618
steps:
17-
-
18-
name: Checkout repository
19-
uses: actions/checkout@v3
20-
-
21-
name: Build image
22-
run: DOCKER_BUILDKIT=1 docker build . --file Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
23-
-
24-
name: Login to Docker Hub
25-
uses: docker/login-action@v2
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Log into registry ${{ env.REGISTRY }}
23+
if: github.event_name != 'pull_request'
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract Docker metadata
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=raw,value=latest,enable={{is_default_branch}}
37+
38+
- name: Build and push Docker image
39+
uses: docker/build-push-action@v5
2640
with:
27-
username: ${{ secrets.DOCKERHUB_USERNAME }}
28-
password: ${{ secrets.DOCKERHUB_TOKEN }}
29-
-
30-
name: Push Image to Docker Hub
31-
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
32-
-
33-
name: Tag image
34-
run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:$(date +%Y%m%d)
35-
-
36-
name: Push tag Image to Docker Hub
37-
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:$(date +%Y%m%d)
41+
context: docker
42+
push: ${{ github.event_name != 'pull_request' }}
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)