Skip to content

Commit 81e6723

Browse files
authored
AP-500: set up github actions (#1)
* AP-500: set up github actions * use fixed multiplatform build strategy * make whitespace consistent
1 parent 9778646 commit 81e6723

File tree

6 files changed

+943
-6
lines changed

6 files changed

+943
-6
lines changed

.github/workflows/build.yml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Build / Test / Push
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
workflow_dispatch:
8+
9+
env:
10+
BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }}
11+
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.runner }}
16+
outputs:
17+
image-arm64: ${{ steps.gen-output.outputs.image-arm64 }}
18+
image-x64: ${{ steps.gen-output.outputs.image-x64 }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- platform: linux/amd64
24+
runner: ubuntu-24.04
25+
- platform: linux/arm64
26+
runner: ubuntu-24.04-arm
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Login to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- id: build-meta
42+
name: Prepare Docker metadata
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ghcr.io/${{ github.repository }}
46+
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
47+
48+
# Build cache is shared among all builds of the same architecture
49+
- id: cache-meta
50+
name: Fetch build cache metadata
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ghcr.io/${{ github.repository }}
54+
tags: type=raw,value=buildcache-${{ runner.arch }}
55+
56+
- id: get-registry
57+
name: Get the sanitized registry name
58+
run: |
59+
echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
60+
61+
- id: build
62+
name: Build/push the arch-specific image
63+
uses: docker/build-push-action@v6
64+
with:
65+
platforms: ${{ matrix.platform }}
66+
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
67+
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
68+
labels: ${{ steps.build-meta.outputs.labels }}
69+
provenance: mode=max
70+
sbom: true
71+
tags: ${{ steps.get-registry.outputs.registry }}
72+
outputs: type=image,push-by-digest=true,push=true
73+
74+
- id: gen-output
75+
name: Write arch-specific image digest to outputs
76+
run: |
77+
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
78+
79+
merge:
80+
runs-on: ubuntu-latest
81+
needs: build
82+
env:
83+
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.image-arm64 }}
84+
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.image-x64 }}
85+
outputs:
86+
image: ${{ steps.meta.outputs.tags }}
87+
build-image-arm64: ${{ needs.build.outputs.image-arm64 }}
88+
build-image-x64: ${{ needs.build.outputs.image-x64 }}
89+
steps:
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
93+
- name: Set up Docker Buildx
94+
uses: docker/setup-buildx-action@v3
95+
96+
- name: Login to GitHub Container Registry
97+
uses: docker/login-action@v3
98+
with:
99+
registry: ghcr.io
100+
username: ${{ github.actor }}
101+
password: ${{ secrets.GITHUB_TOKEN }}
102+
103+
- id: meta
104+
name: Generate tag for the app image
105+
uses: docker/metadata-action@v5
106+
with:
107+
images: ghcr.io/${{ github.repository }}
108+
tags: |
109+
type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }}
110+
111+
- name: Push the multi-platform app image
112+
run: |
113+
docker buildx imagetools create \
114+
--tag "$DOCKER_METADATA_OUTPUT_TAGS" \
115+
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"
116+
117+
test:
118+
runs-on: ubuntu-latest
119+
needs: merge
120+
env:
121+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
122+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
123+
steps:
124+
- name: Checkout code
125+
uses: actions/checkout@v4
126+
127+
- name: Set up Docker Compose
128+
uses: docker/setup-compose-action@v1
129+
130+
- name: Login to GitHub Container Registry
131+
uses: docker/login-action@v3
132+
with:
133+
registry: ghcr.io
134+
username: ${{ github.actor }}
135+
password: ${{ secrets.GITHUB_TOKEN }}
136+
137+
- name: Setup the stack
138+
run: |
139+
docker compose build --quiet
140+
docker compose pull --quiet
141+
docker compose up --wait
142+
143+
- name: Run test
144+
if: ${{ always() }}
145+
run: |
146+
docker compose exec app curl -sfo /dev/null http://localhost/viewer.php?cachefile=Interview62894.xml
147+
148+
- name: Copy out artifacts
149+
if: ${{ always() }}
150+
run: |
151+
docker compose cp app:/opt/app/artifacts ./
152+
docker compose logs > artifacts/docker-compose-services.log
153+
docker compose config > artifacts/docker-compose.merged.yml
154+
155+
- name: Upload the test report
156+
if: ${{ always() }}
157+
uses: actions/upload-artifact@v4
158+
with:
159+
name: ohms-viewer Build Report (${{ github.run_id }}_${{ github.run_attempt }})
160+
path: artifacts/*
161+
if-no-files-found: error
162+
163+
push:
164+
runs-on: ubuntu-latest
165+
needs:
166+
- merge
167+
- test
168+
env:
169+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
170+
DOCKER_APP_IMAGE_ARM64: ${{ needs.merge.outputs.build-image-arm64 }}
171+
DOCKER_APP_IMAGE_X64: ${{ needs.merge.outputs.build-image-x64 }}
172+
steps:
173+
- name: Checkout code
174+
uses: actions/checkout@v4
175+
176+
- name: Set up Docker Buildx
177+
uses: docker/setup-buildx-action@v3
178+
179+
- name: Login to GitHub Container Registry
180+
uses: docker/login-action@v3
181+
with:
182+
registry: ghcr.io
183+
username: ${{ github.actor }}
184+
password: ${{ secrets.GITHUB_TOKEN }}
185+
186+
- name: Produce permanent image tags
187+
uses: docker/metadata-action@v5
188+
with:
189+
images: ghcr.io/${{ github.repository }}
190+
tags: |
191+
type=sha
192+
type=ref,event=branch
193+
type=raw,value=latest,enable={{is_default_branch}}
194+
195+
- name: Retag and push the image
196+
run: |
197+
docker buildx imagetools create \
198+
$(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $DOCKER_APP_IMAGE_ARM64 $DOCKER_APP_IMAGE_X64

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Push Release Tags
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
workflow_dispatch:
8+
9+
env:
10+
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
11+
12+
jobs:
13+
retag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Determine the sha-based image tag to retag
30+
id: get-base-image
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ghcr.io/${{ github.repository }}
34+
tags: type=sha
35+
36+
- name: Verify that the image was previously built
37+
env:
38+
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
39+
run: |
40+
docker manifest inspect "$BASE_IMAGE"
41+
42+
- name: Produce release tags
43+
id: tag-meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ghcr.io/${{ github.repository }}
47+
flavor: latest=false
48+
tags: |
49+
type=ref,event=tag
50+
type=semver,pattern={{major}}
51+
type=semver,pattern={{major}}.{{minor}}
52+
type=semver,pattern={{version}}
53+
54+
- name: Retag and push image
55+
env:
56+
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
57+
run: |
58+
docker buildx imagetools create \
59+
$(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
60+
"$(echo "$BASE_IMAGE" | cut -f1 -d:)"

Jenkinsfile

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

0 commit comments

Comments
 (0)