-
Notifications
You must be signed in to change notification settings - Fork 22
182 lines (158 loc) · 5.52 KB
/
commit-stage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Commit Stage
on: push
env:
REGISTRY: ghcr.io
IMAGE_NAME: thomasvitale/devex/book-service
VERSION: latest
jobs:
build:
name: Build and Test
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: 22
distribution: temurin
cache: gradle
- name: Build, unit tests and integration tests
run: |
cd 06-knative/basic/book-service
chmod +x gradlew
./gradlew build
package:
name: Package and Publish
if: ${{ github.ref == 'refs/heads/main' }}
needs: [ build ]
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Pack
uses: buildpacks/github-actions/setup-pack@v5.0.0
with:
pack-version: 0.34.2
- name: Login to container registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
registry: ${{ env.REGISTRY }}
- name: Build and publish OCI image
run: |
pack build ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
--builder docker.io/paketobuildpacks/builder-jammy-buildpackless-tiny \
--buildpack gcr.io/paketo-buildpacks/java \
--env BP_JVM_VERSION=22 \
--path 06-knative/basic/book-service \
--platform ${{ matrix.platform }} \
--report-output-dir ./report.toml \
--publish
- name: Export digest
run: |
mkdir -p /tmp/digests
digest=$(grep 'digest' report.toml | sed 's/.*= "\(.*\)"/\1/')
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-book-service-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
needs: [ package ]
runs-on: ubuntu-24.04
permissions:
attestations: write
contents: read
id-token: write
packages: write
outputs:
image-digest: ${{ steps.image-info.outputs.digest }}
image-name: ${{ steps.image-info.outputs.name }}
steps:
- name: Prepare
run: |
timestamp=$(date +%Y%m%d-%H%M%S)
echo "TIMESTAMP=${timestamp}" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-book-service-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install Cosign
uses: sigstore/cosign-installer@v3.5.0
- name: Generate Docker meta information
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.version=${{ github.sha }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
tags: |
type=raw,value=${{ env.TIMESTAMP }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=long
- name: Login to container registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
registry: ${{ env.REGISTRY }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
- name: Setup Arkade
uses: alexellis/setup-arkade@v2
- name: Install crane
uses: alexellis/arkade-get@master
with:
crane: v0.19.2
- name: Get OCI image digest
id: image-info
run: |
image_digest=$(crane digest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }})
echo $image_digest
echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV
- name: Sign image
run: |
cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.IMAGE_DIGEST }}
- name: Generate SLSA Build Attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ env.IMAGE_DIGEST }}
push-to-registry: true
github-token: ${{ secrets.IMAGE_PUSH_TOKEN }}