Skip to content

Commit 66ddd87

Browse files
committed
testing image registry creation
1 parent 5b71721 commit 66ddd87

3 files changed

Lines changed: 461 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Build & Publish GitHub Container Registry (GHCR) Images
2+
name: Build Geant4 Images
3+
4+
on:
5+
push:
6+
branches: [ main ] # publish on main updates
7+
tags: [ 'v*' ] # also publish on version tags
8+
pull_request: # PRs: build only (no push)
9+
10+
concurrency:
11+
group: ghcr-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
discover:
16+
name: Discover Dockerfiles
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.scan.outputs.matrix }}
20+
image: ${{ steps.scan.outputs.image }}
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
# ci/distros_tags.sh must echo a JSON matrix to $GITHUB_OUTPUT:
26+
# echo "matrix=<JSON>" >> $GITHUB_OUTPUT
27+
# and the base image name (no tag) like "ghcr.io/<owner>/gemc":
28+
# echo "image=ghcr.io/<owner>/gemc" >> $GITHUB_OUTPUT
29+
- id: scan
30+
name: Build matrix
31+
run: |
32+
echo "matrix=$(ci/distros_tags.sh)" >> "$GITHUB_OUTPUT"
33+
echo "image=ghcr.io/${{ github.repository_owner }}/gemc" >> "$GITHUB_OUTPUT"
34+
35+
build:
36+
name: Build ${{ matrix.geant4_tag }} on ${{ matrix.docker_from }}
37+
needs: discover
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
packages: write
42+
strategy:
43+
fail-fast: false
44+
matrix: ${{ fromJSON(needs.discover.outputs.matrix) }}
45+
env:
46+
PLATS: linux/amd64,linux/arm64
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
- name: Enable QEMU
52+
uses: docker/setup-qemu-action@v3
53+
54+
- name: Set up Buildx
55+
uses: docker/setup-buildx-action@v3
56+
57+
- name: Log in to GHCR
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- id: meta
65+
name: Generate tags & labels
66+
uses: docker/metadata-action@v5
67+
with:
68+
images: ${{ needs.discover.outputs.image }}
69+
tags: |
70+
# Single canonical tag: geant4-<tag>-<base>
71+
type=raw,value=${{ matrix.geant4_tag }}-${{ matrix.docker_from }}
72+
labels: |
73+
org.opencontainers.image.source=${{ github.repository }}
74+
org.opencontainers.image.description=Geant4 image (${{ matrix.geant4_tag }} on ${{ matrix.docker_from }})
75+
76+
# Generate a Dockerfile using your python script, passing the FULL base image
77+
- name: Generate Dockerfile
78+
run: |
79+
python3 ci/g4pkglist.py -p "${{ matrix.docker_from }}" --install > Dockerfile.generated
80+
echo "Generated Dockerfile:"
81+
sed -n '1,60p' Dockerfile.generated
82+
83+
# Multi-arch when pushing; single-arch and load locally on PRs
84+
- name: Build and Push (release/merge)
85+
if: ${{ github.event_name != 'pull_request' }}
86+
uses: docker/build-push-action@v5
87+
with:
88+
context: .
89+
file: ./Dockerfile.generated
90+
platforms: ${{ env.PLATS }}
91+
push: true
92+
tags: ${{ steps.meta.outputs.tags }}
93+
labels: ${{ steps.meta.outputs.labels }}
94+
cache-from: type=registry,ref=${{ needs.discover.outputs.image }}:cache
95+
cache-to: type=registry,ref=${{ needs.discover.outputs.image }}:cache,mode=max
96+
97+
98+
- name: Summarize image reference
99+
if: ${{ always() }}
100+
env:
101+
IMAGE: ${{ needs.discover.outputs.image }}
102+
TAG: ${{ matrix.geant4_tag }}-${{ matrix.docker_from }}
103+
PUSHED: ${{ github.event_name != 'pull_request' }}
104+
run: |
105+
PLATFORM_HINT="--platform=linux/amd64"
106+
{
107+
echo "## Docker Image"
108+
if [ "$PUSHED" = "true" ]; then
109+
echo ""
110+
echo "**Tag:** \`$IMAGE:$TAG\`"
111+
echo ""
112+
echo "### Pull"
113+
echo '```bash'
114+
echo "docker pull $IMAGE:$TAG"
115+
echo '```'
116+
echo "### Run"
117+
echo '```bash'
118+
echo "docker run --rm -it $IMAGE:$TAG bash"
119+
echo '```'
120+
echo "### Run (Apple Silicon Mac)"
121+
echo '```bash'
122+
echo "docker run --rm -it $PLATFORM_HINT $IMAGE:$TAG bash"
123+
echo '```'
124+
else
125+
echo ""
126+
echo "_PR build (image not pushed). Loaded locally on the runner with tags:_"
127+
echo '```'
128+
printf '%s\n' "${{ steps.meta.outputs.tags }}"
129+
echo '```'
130+
fi
131+
} >> "$GITHUB_STEP_SUMMARY"

ci/distros_tags.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# -e — Exit on error
3+
# -u — Treat unset variables as an error
4+
# -o pipefail — Prevent errors in a pipeline from being masked
5+
set -euo pipefail
6+
7+
get_ubuntu_lts() {
8+
echo "24.04"
9+
}
10+
11+
get_fedora_latest() {
12+
echo "40"
13+
}
14+
15+
get_arch_latest() {
16+
echo "latest"
17+
}
18+
19+
get_almalinux_latest() {
20+
echo "9.4"
21+
}
22+
23+
get_debian_latest() {
24+
echo "13"
25+
}
26+
27+
get_rhel_latest() {
28+
echo "9.4"
29+
}
30+
31+
get_geant4_tag() {
32+
echo "11.3.2"
33+
}
34+
35+
# --- Build JSON GitHub matrix ---
36+
build_matrix() {
37+
local geant4_tag
38+
geant4_tag=$(get_geant4_tag)
39+
40+
cat <<EOF
41+
{
42+
"include": [
43+
{
44+
"distro": "ubuntu",
45+
"docker_from": "ubuntu:$(get_ubuntu_lts)",
46+
"geant4_tag": "${geant4_tag}"
47+
},
48+
{
49+
"distro": "fedora",
50+
"docker_from": "fedora:$(get_fedora_latest)",
51+
"geant4_tag": "${geant4_tag}"
52+
},
53+
{
54+
"distro": "arch",
55+
"docker_from": "archlinux:$(get_arch_latest)",
56+
"geant4_tag": "${geant4_tag}"
57+
},
58+
{
59+
"distro": "almalinux",
60+
"docker_from": "almalinux:$(get_almalinux_latest)",
61+
"geant4_tag": "${geant4_tag}"
62+
},
63+
{
64+
"distro": "debian",
65+
"docker_from": "debian:$(get_debian_latest)",
66+
"geant4_tag": "${geant4_tag}"
67+
},
68+
{
69+
"distro": "rhel",
70+
"docker_from": "redhat/ubi9:$(get_rhel_latest)",
71+
"geant4_tag": "${geant4_tag}"
72+
}
73+
]
74+
}
75+
EOF
76+
}
77+
78+
# --- Execute ---
79+
build_matrix

0 commit comments

Comments
 (0)