Skip to content

Commit 28eab9b

Browse files
authored
Merge pull request #23 from keikoproj/fix-docker-push
chore: update release image GHA
2 parents 70bd64a + f796a1e commit 28eab9b

File tree

2 files changed

+120
-55
lines changed

2 files changed

+120
-55
lines changed

.github/workflows/docker-publish.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/image-push.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Create and publish image
2+
permissions:
3+
contents: write # Needed to check out the repository and update releases
4+
packages: write # Needed to push images to GitHub Container Registry (ghcr.io)
5+
attestations: write # For generating attestations
6+
id-token: write # For OIDC token authentication
7+
8+
on:
9+
push:
10+
branches: [ master ]
11+
tags:
12+
- "v*.*.*"
13+
14+
jobs:
15+
build-and-push:
16+
name: Build and push image
17+
runs-on: ubuntu-latest
18+
if: github.event_name != 'pull_request'
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # Fetch all history for proper versioning
24+
25+
# Set up QEMU for multi-platform builds
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
# Set up Docker Buildx
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
# Extract metadata for Docker
34+
- name: Extract Docker metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: docker.io/${{ github.repository_owner }}/${{ github.event.repository.name }},ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
39+
tags: |
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=ref,event=branch
43+
env:
44+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
45+
46+
# Extract primary Docker tag (without 'v')
47+
- name: Extract primary Docker tag
48+
id: docker_tag
49+
run: |
50+
TAGS="${{ steps.meta.outputs.tags }}"
51+
IFS=$'\n' read -r FIRST_IMAGE <<< "$TAGS"
52+
PRIMARY_TAG="${FIRST_IMAGE##*:}"
53+
echo "tag=$PRIMARY_TAG" >> $GITHUB_OUTPUT
54+
55+
# Login to DockerHub
56+
- name: Login to DockerHub
57+
uses: docker/login-action@v3
58+
with:
59+
username: ${{ secrets.DOCKERHUB_USERNAME }}
60+
password: ${{ secrets.DOCKERHUB_TOKEN }}
61+
62+
# Login to GitHub Container Registry
63+
- name: Login to GHCR
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ghcr.io
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Build and push cross-platform image
71+
id: push
72+
uses: docker/build-push-action@v6
73+
with:
74+
context: .
75+
file: ./Dockerfile
76+
platforms: linux/amd64,linux/arm64
77+
push: true
78+
provenance: false
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
annotations: ${{ steps.meta.outputs.annotations }}
82+
cache-from: type=gha
83+
cache-to: type=gha,mode=max
84+
build-args: |
85+
CREATED=${{ github.event.head_commit.timestamp || format('{0:yyyy-MM-ddTHH:mm:ssZ}', github.event.repository.updated_at) }}
86+
VERSION=${{ github.ref_name }}
87+
REVISION=${{ github.sha }}
88+
89+
- name: Generate artifact attestation (dockerhub)
90+
uses: actions/attest-build-provenance@v2
91+
with:
92+
subject-name: docker.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
93+
subject-digest: ${{ steps.push.outputs.digest }}
94+
push-to-registry: true
95+
96+
- name: Generate artifact attestation (ghcr)
97+
uses: actions/attest-build-provenance@v2
98+
with:
99+
subject-name: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
100+
subject-digest: ${{ steps.push.outputs.digest }}
101+
push-to-registry: true
102+
103+
- name: Update GitHub Release with image and attestation links
104+
if: startsWith(github.ref, 'refs/tags/v')
105+
uses: softprops/action-gh-release@v2
106+
with:
107+
tag_name: ${{ github.ref_name }}
108+
append_body: true
109+
body: |
110+
## Docker Images
111+
- [DockerHub](https://hub.docker.com/r/${{ github.repository_owner }}/${{ github.event.repository.name }}/tags?name=${{ steps.docker_tag.outputs.tag }})
112+
- [GHCR](https://github.com/orgs/${{ github.repository_owner }}/pkgs/container/${{ github.event.repository.name }})
113+
- `docker pull ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.docker_tag.outputs.tag }}`
114+
- `docker pull ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.docker_tag.outputs.tag }}`
115+
116+
## Attestations
117+
- DockerHub attestation for `${{ steps.docker_tag.outputs.tag }}` published (see OCI provenance)
118+
- GHCR attestation for `${{ steps.docker_tag.outputs.tag }}` published (see OCI provenance)
119+
env:
120+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)