-
Notifications
You must be signed in to change notification settings - Fork 2
237 lines (225 loc) · 9.44 KB
/
Copy pathci-docker-build.yml
File metadata and controls
237 lines (225 loc) · 9.44 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Docker
on:
workflow_call:
secrets:
SENTRY_AUTH_TOKEN:
required: false
SENTRY_ORG:
required: false
SENTRY_PROJECT:
required: false
inputs:
should_skip:
description: "Whether to skip the workflow"
required: false
type: string
default: "false"
webapp_changed:
description: "Whether webapp files changed (or should build for other reasons)"
required: false
type: string
default: "true"
application_server_changed:
description: "Whether application-server files changed (or should build for other reasons)"
required: false
type: string
default: "true"
agent_images_changed:
description: "Whether agent image files changed (or should build for other reasons)"
required: false
type: string
default: "true"
postgres_image_changed:
description: "Whether the PostgreSQL image inputs changed"
required: false
type: string
default: "true"
outputs:
application-server-published:
description: "Whether an application-server image exists at this commit"
value: ${{ jobs.application-server-build.outputs.manifest-digest != '' || jobs.tag-unchanged-images.outputs.application-server-published == 'true' }}
permissions: {}
jobs:
webapp-build:
name: "Webapp"
if: inputs.should_skip != 'true' && inputs.webapp_changed == 'true'
uses: ./.github/workflows/reusable-docker-build.yml
permissions:
contents: read
packages: write
id-token: write
attestations: write
secrets:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
image-name: "hephaestus-build/webapp"
docker-file: "./webapp/Dockerfile"
docker-context: "."
registry: "ghcr.io"
# Use the PR source branch; ref_name identifies GitHub's synthetic merge ref on pull requests.
build-args: |
SOURCE_COMMIT=${{ github.sha }}
COOLIFY_BRANCH=${{ github.head_ref || github.ref_name }}
single-arch: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
labels: |
org.opencontainers.image.title=Hephaestus Webapp
org.opencontainers.image.description=Web client for Hephaestus
org.opencontainers.image.vendor=AET TUM
org.opencontainers.image.licenses=MIT
hephaestus.component=webapp
application-server-build:
name: "App Server"
if: >-
inputs.should_skip != 'true' &&
(inputs.application_server_changed == 'true' || github.event_name != 'pull_request')
uses: ./.github/workflows/reusable-docker-build.yml
permissions:
contents: read
packages: write
id-token: write
attestations: write
with:
image-name: "hephaestus-build/application-server"
# Application CDS configuration lives in server/application/pom.xml; rationale: docs/admin/buildpacks-cds-decision.md.
use-buildpacks: true
maven-module: "server/application"
registry: "ghcr.io"
single-arch: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
labels: |
org.opencontainers.image.title=Hephaestus Application Server
org.opencontainers.image.description=Spring Boot server for Hephaestus
org.opencontainers.image.vendor=AET TUM
org.opencontainers.image.licenses=MIT
hephaestus.component=application-server
agent-pi-build:
name: "Agent: Pi"
if: inputs.should_skip != 'true' && inputs.agent_images_changed == 'true'
uses: ./.github/workflows/reusable-docker-build.yml
permissions:
contents: read
packages: write
id-token: write
attestations: write
with:
image-name: "hephaestus-build/agent-pi"
docker-file: "./docker/agents/pi/Dockerfile"
docker-context: "./docker/agents"
registry: "ghcr.io"
# Cache-busts the OS-package upgrade layer; this build imports the `cache-main` registry cache.
build-args: |
SOURCE_COMMIT=${{ github.sha }}
single-arch: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
labels: |
org.opencontainers.image.title=Hephaestus Agent - Pi
org.opencontainers.image.description=Sandboxed Pi coding agent for AI-powered code review
org.opencontainers.image.vendor=AET TUM
org.opencontainers.image.licenses=MIT
hephaestus.component=agent-pi
postgres-build:
name: "Postgres (pg_partman)"
if: >-
inputs.should_skip != 'true' &&
(inputs.postgres_image_changed == 'true' || github.event_name != 'pull_request')
uses: ./.github/workflows/reusable-docker-build.yml
permissions:
contents: read
packages: write
id-token: write
attestations: write
with:
image-name: "hephaestus-build/postgres"
docker-file: "./docker/postgres/Dockerfile"
docker-context: "./docker/postgres"
registry: "ghcr.io"
# Cache-busts the OS-package upgrade layer; this build imports the `cache-main` registry cache.
build-args: |
SOURCE_COMMIT=${{ github.sha }}
single-arch: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
labels: |
org.opencontainers.image.title=Hephaestus Postgres
org.opencontainers.image.description=PostgreSQL + pg_partman for all environments (dev/preview/prod)
org.opencontainers.image.vendor=AET TUM
org.opencontainers.image.licenses=MIT
hephaestus.component=postgres
# Preview stacks resolve every component by PR head SHA; alias verified base digests for unchanged components.
tag-unchanged-images:
name: "Tag unchanged images"
if: >-
inputs.should_skip != 'true' && github.event_name == 'pull_request' &&
(inputs.webapp_changed != 'true' || inputs.application_server_changed != 'true' ||
inputs.agent_images_changed != 'true' ||
inputs.postgres_image_changed != 'true')
timeout-minutes: 15
runs-on: ubuntu-latest
outputs:
application-server-published: ${{ steps.tag.outputs.application-server-published }}
permissions:
packages: write
attestations: read
contents: read
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Log in to Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify and tag unchanged images
id: tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WEBAPP_CHANGED: ${{ inputs.webapp_changed }}
APPLICATION_SERVER_CHANGED: ${{ inputs.application_server_changed }}
AGENT_IMAGES_CHANGED: ${{ inputs.agent_images_changed }}
POSTGRES_IMAGE_CHANGED: ${{ inputs.postgres_image_changed }}
PR_NUMBER: ${{ github.event.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
REPOSITORY: ${{ github.repository }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
set -euo pipefail
tag_image() {
local image="ghcr.io/hephaestus-build/$1"
local source="$image:$BASE_SHA"
local digest
digest=$(docker buildx imagetools inspect --format '{{.Manifest.Digest}}' "$source" 2>/dev/null || true)
if [[ ! "$digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then
local merged_head
merged_head=$(gh api "repos/$REPOSITORY/commits/$BASE_SHA/pulls" \
--jq '[.[] | select(.merged_at != null)][0].head.sha // empty')
if [ -n "$merged_head" ]; then
source="$image:$merged_head"
digest=$(docker buildx imagetools inspect --format '{{.Manifest.Digest}}' "$source" 2>/dev/null || true)
fi
fi
if [[ ! "$digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then
echo "::error::Invalid digest for $source: ${digest:-<empty>}"
return 1
fi
local verified="$image@$digest"
cosign verify "$verified" \
--certificate-identity-regexp "^https://github\\.com/$REPOSITORY/\\.github/workflows/reusable-docker-build\\.yml@" \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
--certificate-github-workflow-repository "$REPOSITORY" \
> /dev/null
gh attestation verify "oci://$verified" --owner "$REPOSITORY_OWNER"
docker buildx imagetools create \
--tag "$image:$HEAD_SHA" \
--tag "$image:pr-$PR_NUMBER" \
--tag "$image:run-$RUN_ID-$RUN_ATTEMPT" \
"$verified"
}
[ "$WEBAPP_CHANGED" = "true" ] || tag_image webapp
if [ "$APPLICATION_SERVER_CHANGED" != "true" ]; then
tag_image application-server
echo "application-server-published=true" >> "$GITHUB_OUTPUT"
fi
[ "$AGENT_IMAGES_CHANGED" = "true" ] || tag_image agent-pi
[ "$POSTGRES_IMAGE_CHANGED" = "true" ] || tag_image postgres