Skip to content

Commit d06422e

Browse files
committed
Add action for docker image push
1 parent 29ea09a commit d06422e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push
5+
6+
env:
7+
REGISTRY: index.docker.io
8+
# github.repository as <account>/<repo>
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
push_to_registry:
13+
name: Push Docker image to Docker Hub
14+
runs-on: ubuntu-latest
15+
permissions:
16+
packages: write
17+
contents: read
18+
attestations: write
19+
id-token: write
20+
steps:
21+
- name: Check out the repo
22+
uses: actions/checkout@v4
23+
24+
- name: Log in to Docker Hub
25+
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
26+
with:
27+
username: ${{ secrets.DOCKER_USERNAME }}
28+
password: ${{ secrets.DOCKER_PASSWORD }}
29+
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
33+
with:
34+
images: ${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=raw,value={{date 'YYYYMMDD'}}
37+
38+
- name: Build and push Docker image
39+
id: push
40+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
41+
with:
42+
context: .
43+
file: ./Dockerfile
44+
push: true
45+
tags: ${{ steps.meta.outputs.tags }}
46+
labels: ${{ steps.meta.outputs.labels }}
47+
48+
- name: Retag image with latest
49+
run: |
50+
docker pull ${{ steps.meta.outputs.tags }}
51+
docker tag ${{ steps.meta.outputs.tags }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
52+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
53+
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v2
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
subject-digest: ${{ steps.push.outputs.digest }}
59+
push-to-registry: true

0 commit comments

Comments
 (0)