-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (162 loc) · 6.4 KB
/
docker.yml
File metadata and controls
184 lines (162 loc) · 6.4 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
# Build & Publish GitHub Container Registry (GHCR) Images
name: Build Geant4 Images
on:
push:
branches: [ main ] # publish on main updates
tags: [ 'v*' ] # also publish on version tags
pull_request: # PRs: build only (no push)
concurrency:
group: ghcr-${{ github.ref }}
cancel-in-progress: true
jobs:
discover:
name: Discover Dockerfiles
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.scan.outputs.matrix }}
image: ${{ steps.scan.outputs.image }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# ci/distros_tags.sh must echo a JSON matrix to $GITHUB_OUTPUT:
# echo "matrix=<JSON>" >> $GITHUB_OUTPUT
# and the base image name (no tag) like "ghcr.io/<owner>/geant4":
# echo "image=ghcr.io/<owner>/geant4" >> $GITHUB_OUTPUT
- id: scan
name: Build matrix
run: ci/distros_tags.sh
build:
name: Build ${{ matrix.geant4_tag }} on ${{ matrix.docker_from }}
needs: discover
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.discover.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Enable QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
name: Generate tags & labels
uses: docker/metadata-action@v5
with:
images: ${{ needs.discover.outputs.image }}
tags: |
# Single canonical tag: geant4-<tag>-<base>
type=raw,value=${{ matrix.geant4_tag }}-${{ matrix.docker_from }}
labels: |
org.opencontainers.image.source=${{ github.repository }}
org.opencontainers.image.description=Geant4 image (${{ matrix.geant4_tag }} on ${{ matrix.docker_from }})
# Generate a Dockerfile using your python script, passing the FULL base image
- name: Generate Dockerfile
run: |
python3 ci/g4pkglist.py -p "${{ matrix.distro }}" -f "${{ matrix.docker_from }}" --install > Dockerfile.generated
echo "Generated Dockerfile:"
sed -n '1,60p' Dockerfile.generated
- name: Choose platforms for this item
id: plats
shell: bash
run: |
PLATS="linux/amd64,linux/arm64"
case "${{ matrix.docker_from }}" in
archlinux:*) PLATS="linux/amd64" ;; # Arch image is amd64-only
esac
echo "plats=$PLATS" >> "$GITHUB_OUTPUT"
# Multi-arch when pushing; single-arch and load locally on PRs
- name: Build and Push (release/merge)
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.generated
platforms: ${{ steps.plats.outputs.plats }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ needs.discover.outputs.image }}:cache
cache-to: type=registry,ref=${{ needs.discover.outputs.image }}:cache,mode=max
- name: Summarize image reference
shell: bash
env:
IMAGE: ${{ needs.discover.outputs.image }}
TAG: ${{ matrix.geant4_tag }}-${{ matrix.docker_from }}
PUSHED: ${{ github.event_name != 'pull_request' }}
IS_ARCH: ${{ startsWith(matrix.docker_from, 'archlinux:') }}
run: |
# prepare summary target safely
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
mkdir -p "$(dirname "$GITHUB_STEP_SUMMARY")"
SUMMARY_OUT="$GITHUB_STEP_SUMMARY"
else
SUMMARY_OUT="$RUNNER_TEMP/step_summary.md"
mkdir -p "$(dirname "$SUMMARY_OUT")"
echo "GITHUB_STEP_SUMMARY not set; writing to $SUMMARY_OUT"
fi
PLATFORM_HINT="--platform=linux/amd64"
{
echo "## Docker Image"
echo ""
echo "**Tag:** \`${IMAGE}:${TAG}\`"
if [ "$PUSHED" = "true" ]; then
echo ""
echo "### Pull"
echo '```bash'
echo "docker pull ${IMAGE}:${TAG}"
echo '```'
else
echo ""
echo "_PR build (image not pushed). Loaded locally on the runner with tags:_"
echo '```'
printf '%s\n' "${{ steps.meta.outputs.tags }}"
echo '```'
fi
echo ""
echo "### Run (interactive shell)"
echo '```bash'
if [ "$IS_ARCH" = "true" ]; then
echo "docker run --rm -it ${PLATFORM_HINT} ${IMAGE}:${TAG} bash"
else
echo "docker run --rm -it ${IMAGE}:${TAG} bash"
fi
echo '```'
echo ""
echo "### Run with browser (noVNC)"
echo "Open **http://localhost:6080** after starting."
echo ""
echo "**Default geometry:** \`1280x800\` (override with \`-e GEOMETRY=WIDTHxHEIGHT\`)."
echo ""
echo '**Start (same-arch host):**'
echo '```bash'
if [ "$IS_ARCH" = "true" ]; then
echo "docker run --rm -p 6080:6080 ${PLATFORM_HINT} ${IMAGE}:${TAG}"
else
echo "docker run --rm -p 6080:6080 ${IMAGE}:${TAG}"
fi
echo '```'
echo ""
echo '**Start with custom resolution:**'
echo '```bash'
if [ "$IS_ARCH" = "true" ]; then
echo "docker run --rm -p 6080:6080 -e GEOMETRY=1600x900 ${PLATFORM_HINT} ${IMAGE}:${TAG}"
else
echo "docker run --rm -p 6080:6080 -e GEOMETRY=1600x900 ${IMAGE}:${TAG}"
fi
echo '```'
echo ""
echo "### Notes by distro"
echo "- **Ubuntu/Debian/Fedora/AlmaLinux**: Xvfb + x11vnc + packaged noVNC."
echo "- **Arch Linux**: Xvfb + x0vncserver (TigerVNC) + noVNC from /opt (amd64-only → use \`${PLATFORM_HINT}\` on arm64)."
} >> "$SUMMARY_OUT"
echo "Summary written to: $SUMMARY_OUT"