Skip to content

Commit a8b1365

Browse files
committed
Add GitHub Actions workflow to build grade-python images
1 parent bffab67 commit a8b1365

15 files changed

Lines changed: 234 additions & 12 deletions

.github/workflows/build.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
name: Build and push Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
prepare:
10+
name: Determine base tag and full tag
11+
runs-on: ubuntu-24.04
12+
outputs:
13+
base_tag: ${{ steps.tags.outputs.base_tag }}
14+
full_tag: ${{ steps.tags.outputs.full_tag }}
15+
16+
steps:
17+
- name: Determine base tag and full tag
18+
id: tags
19+
run: |
20+
if [ "${GITHUB_REF_NAME#*-}" = "${GITHUB_REF_NAME}" ]; then
21+
base=${GITHUB_REF_NAME}
22+
full=$base
23+
echo "base_tag=$base" >> "$GITHUB_OUTPUT"
24+
echo "full_tag=$full" >> "$GITHUB_OUTPUT"
25+
else
26+
main=${GITHUB_REF_NAME%-*}
27+
base=${GITHUB_REF_NAME##*-}
28+
full=$main-$base
29+
if [ "${base#*u}" ]; then
30+
base=${base%%u*}
31+
fi
32+
echo "base_tag=$base" >> "$GITHUB_OUTPUT"
33+
echo "full_tag=$full" >> "$GITHUB_OUTPUT"
34+
fi
35+
36+
build-base:
37+
name: Build base image (${{ matrix.platform }})
38+
runs-on: ${{ matrix.runner }}
39+
needs: prepare
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
include:
44+
- platform: linux/amd64
45+
runner: ubuntu-24.04
46+
- platform: linux/arm64
47+
runner: ubuntu-24.04-arm
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Log in to Docker Hub
53+
uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
# Build and push platform-specific digest (no manifest tag yet)
62+
- name: Build and push by digest
63+
id: build
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
file: Dockerfile
68+
platforms: ${{ matrix.platform }}
69+
push: true
70+
build-args: |
71+
BASE_TAG=${{ needs.prepare.outputs.base_tag }}
72+
outputs: type=image,name=apluslms/grade-python,push-by-digest=true,name-canonical=true
73+
74+
# Save the digest so the merge job can find it
75+
- name: Export digest
76+
run: |
77+
mkdir -p /tmp/digests
78+
digest="${{ steps.build.outputs.digest }}"
79+
touch "/tmp/digests/${digest#sha256:}"
80+
81+
- name: Upload digest artifact
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: digest-base-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
85+
path: /tmp/digests/*
86+
retention-days: 1
87+
88+
merge-base:
89+
name: Merge base manifests
90+
runs-on: ubuntu-24.04
91+
needs: build-base
92+
93+
steps:
94+
- name: Download digests
95+
uses: actions/download-artifact@v4
96+
with:
97+
path: /tmp/digests
98+
pattern: digest-base-*
99+
merge-multiple: true
100+
101+
- name: Log in to Docker Hub
102+
uses: docker/login-action@v3
103+
with:
104+
username: ${{ secrets.DOCKERHUB_USERNAME }}
105+
password: ${{ secrets.DOCKERHUB_TOKEN }}
106+
107+
- name: Set up Docker Buildx
108+
uses: docker/setup-buildx-action@v3
109+
110+
- name: Determine tags
111+
id: meta
112+
uses: docker/metadata-action@v5
113+
with:
114+
images: apluslms/grade-python
115+
flavor: |
116+
latest=false
117+
tags: |
118+
type=raw,enable=${{ github.ref == 'refs/heads/master' }},value=latest
119+
type=ref,enable=${{ github.ref != 'refs/heads/master' }},event=branch
120+
121+
- name: Create and push multi-arch manifest
122+
working-directory: /tmp/digests
123+
run: |
124+
docker buildx imagetools create \
125+
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
126+
$(printf 'apluslms/grade-python@sha256:%s ' *)
127+
128+
build-math:
129+
name: Build math image (${{ matrix.platform }})
130+
runs-on: ${{ matrix.runner }}
131+
needs:
132+
- prepare
133+
- merge-base
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
include:
138+
- platform: linux/amd64
139+
runner: ubuntu-24.04
140+
- platform: linux/arm64
141+
runner: ubuntu-24.04-arm
142+
143+
steps:
144+
- uses: actions/checkout@v4
145+
146+
- name: Log in to Docker Hub
147+
uses: docker/login-action@v3
148+
with:
149+
username: ${{ secrets.DOCKERHUB_USERNAME }}
150+
password: ${{ secrets.DOCKERHUB_TOKEN }}
151+
152+
- name: Set up Docker Buildx
153+
uses: docker/setup-buildx-action@v3
154+
155+
# Build and push platform-specific digest (no manifest tag yet)
156+
- name: Build and push by digest
157+
id: build
158+
uses: docker/build-push-action@v6
159+
with:
160+
context: .
161+
file: Dockerfile.math
162+
platforms: ${{ matrix.platform }}
163+
push: true
164+
build-args: |
165+
FULL_TAG=${{ needs.prepare.outputs.full_tag }}
166+
outputs: type=image,name=apluslms/grade-python,push-by-digest=true,name-canonical=true
167+
168+
# Save the digest so the merge job can find it
169+
- name: Export digest
170+
run: |
171+
mkdir -p /tmp/digests
172+
digest="${{ steps.build.outputs.digest }}"
173+
touch "/tmp/digests/${digest#sha256:}"
174+
175+
- name: Upload digest artifact
176+
uses: actions/upload-artifact@v4
177+
with:
178+
name: digest-math-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
179+
path: /tmp/digests/*
180+
retention-days: 1
181+
182+
merge-math:
183+
name: Merge math manifests
184+
runs-on: ubuntu-24.04
185+
needs:
186+
- prepare
187+
- build-math
188+
189+
steps:
190+
- name: Download digests
191+
uses: actions/download-artifact@v4
192+
with:
193+
path: /tmp/digests
194+
pattern: digest-math-*
195+
merge-multiple: true
196+
197+
- name: Log in to Docker Hub
198+
uses: docker/login-action@v3
199+
with:
200+
username: ${{ secrets.DOCKERHUB_USERNAME }}
201+
password: ${{ secrets.DOCKERHUB_TOKEN }}
202+
203+
- name: Set up Docker Buildx
204+
uses: docker/setup-buildx-action@v3
205+
206+
- name: Determine tags
207+
id: meta
208+
uses: docker/metadata-action@v5
209+
with:
210+
images: apluslms/grade-python
211+
flavor: |
212+
latest=false
213+
tags: |
214+
type=raw,enable=${{ github.ref == 'refs/heads/master' }},value=math-latest
215+
type=raw,enable=${{ github.ref != 'refs/heads/master' }},value=math-${{ needs.prepare.outputs.full_tag }}
216+
217+
- name: Create and push multi-arch manifest
218+
working-directory: /tmp/digests
219+
run: |
220+
docker buildx imagetools create \
221+
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
222+
$(printf 'apluslms/grade-python@sha256:%s ' *)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG BASE_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grading-base:$BASE_TAG
2+
FROM apluslms/grading-base:$BASE_TAG
33

44
COPY rootfs /
55

Dockerfile.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:$FULL_TAG
2+
FROM apluslms/grade-python:$FULL_TAG
33

44
RUN pip_install \
55
beautifulsoup4 \

Dockerfile.jupyter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:ml-$FULL_TAG
2+
FROM apluslms/grade-python:ml-$FULL_TAG
33

44
RUN pip_install \
55
nbconvert~=7.2.9 \

Dockerfile.math

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:$FULL_TAG
2+
FROM apluslms/grade-python:$FULL_TAG
33

44
RUN apt_install \
55
bc \

Dockerfile.mec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:math-$FULL_TAG
2+
FROM apluslms/grade-python:math-$FULL_TAG
33

44

55
RUN pip_install \

Dockerfile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:math-$FULL_TAG
2+
FROM apluslms/grade-python:math-$FULL_TAG
33

44
RUN pip_install \
55
networkx==3.2.1 \

Dockerfile.ply

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:$FULL_TAG
2+
FROM apluslms/grade-python:$FULL_TAG
33

44
# PLY is yet another implementation of lex and yacc for Python,
55
# in other words, a parser and lexer generator.

Dockerfile.psql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:$FULL_TAG
2+
FROM apluslms/grade-python:$FULL_TAG
33

44
RUN apt_install \
55
postgresql \

Dockerfile.rdf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG FULL_TAG=latest
2-
FROM --platform=$TARGETPLATFORM apluslms/grade-python:$FULL_TAG
2+
FROM apluslms/grade-python:$FULL_TAG
33

44
RUN apt_install \
55
python3-rdflib \

0 commit comments

Comments
 (0)