Skip to content

Commit 6e5bdef

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

15 files changed

Lines changed: 239 additions & 12 deletions

.github/workflows/build.yml

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