Skip to content

Commit d124686

Browse files
committed
add docker push workflow
1 parent 1f43ce7 commit d124686

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

.github/workflows/docker-push.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build Docker image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
tags: [ 'v*.*.*' ]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
id-token: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Install cosign
26+
if: github.event_name != 'pull_request'
27+
uses: uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
28+
with:
29+
cosign-release: 'v2.2.4'
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
33+
34+
- name: Log in to registry ${{ env.REGISTRY }}
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract Docker metadata
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
57+
- name: Sign the published Docker image
58+
if: ${{ github.event_name != 'pull_request' }}
59+
env:
60+
TAGS: ${{ steps.meta.outputs.tags }}
61+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
62+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
63+

0 commit comments

Comments
 (0)