-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild_matrix.sh
More file actions
executable file
·223 lines (201 loc) · 7.54 KB
/
build_matrix.sh
File metadata and controls
executable file
·223 lines (201 loc) · 7.54 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env bash
# build_matrix.sh — build NONMEM Docker images across Ubuntu LTS × NONMEM × gfortran versions
#
# Usage:
# ./build_matrix.sh [--arm64] [--jobs N]
#
# Options:
# --arm64 Also build linux/arm64 images (requires docker buildx + QEMU; see below)
# --jobs N Maximum parallel builds (default: 16)
#
# Prerequisites:
# 1. Copy nonmem_passwords.conf.example to nonmem_passwords.conf and fill in values.
# 2. Place nonmem.lic in NONMEM_ZIP_DIR (set in the conf file).
#
# ARM64 prerequisites (one-time setup on an x86-64 host):
# sudo apt-get install qemu-user-static binfmt-support
# docker run --privileged --rm tonistiigi/binfmt --install all
# docker buildx create --name multiplatform --driver docker-container \
# --driver-opt network=host --use
# docker buildx inspect --bootstrap
#
# Tag format: {NM_VERSION}-ubuntu{UBUNTU}-gfortran{GFC}-{arch}
# Example: 7.5.1-ubuntu24.04-gfortran13-amd64
#
# Results are written to build_matrix.log in the script directory.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONF_FILE="${SCRIPT_DIR}/nonmem_passwords.conf"
LOG_FILE="${SCRIPT_DIR}/build_matrix.log"
MAX_JOBS=16
BUILD_ARM64=false
# --- Parse arguments ---
while [[ $# -gt 0 ]]; do
case "$1" in
--arm64) BUILD_ARM64=true; shift ;;
--jobs) MAX_JOBS="$2"; shift 2 ;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done
# --- Load config ---
if [[ ! -f "${CONF_FILE}" ]]; then
echo "ERROR: ${CONF_FILE} not found." >&2
echo "Copy nonmem_passwords.conf.example to nonmem_passwords.conf and fill in values." >&2
exit 1
fi
# shellcheck source=/dev/null
source "${CONF_FILE}"
NONMEM_ZIP_DIR="${NONMEM_ZIP_DIR:-/home/bill/tmp/nonmem}"
if [[ ! -f "${NONMEM_ZIP_DIR}/nonmem.lic" ]]; then
echo "ERROR: nonmem.lic not found in ${NONMEM_ZIP_DIR}" >&2
exit 1
fi
# --- buildx pre-flight check ---
if ! docker buildx version &>/dev/null; then
echo "ERROR: docker buildx is not available." >&2
echo "This script requires docker buildx (included with Docker 20.10+)." >&2
exit 1
fi
# --- ARM64 pre-flight check ---
if [[ "${BUILD_ARM64}" == true ]]; then
if ! docker buildx inspect 2>/dev/null | grep -q "linux/arm64"; then
echo "ERROR: linux/arm64 is not available in your current buildx builder." >&2
echo "Run the ARM64 setup steps:" >&2
echo " sudo apt-get install qemu-user-static binfmt-support" >&2
echo " docker run --privileged --rm tonistiigi/binfmt --install all" >&2
echo " docker buildx create --name multiplatform --driver docker-container \\" >&2
echo " --driver-opt network=host --use" >&2
echo " docker buildx inspect --bootstrap" >&2
exit 1
fi
fi
# --- Copy license into build context ---
cp "${NONMEM_ZIP_DIR}/nonmem.lic" "${SCRIPT_DIR}/nonmem.lic"
# --- Initialize log ---
: > "${LOG_FILE}"
echo "Build matrix started at $(date)" | tee -a "${LOG_FILE}"
echo "" | tee -a "${LOG_FILE}"
# --- NONMEM versions: "major minor patch zipfile password" ---
# Zip filenames differ between old (NONMEM7.x.y.zip) and new (NONMEMxyz.zip) conventions.
NONMEM_VERSIONS=(
"7 2 0 NONMEM7.2.0.zip ${PASS_720}"
"7 3 0 NONMEM7.3.0.zip ${PASS_730}"
"7 4 1 NONMEM7.4.1.zip ${PASS_74x}"
"7 4 2 NONMEM7.4.2.zip ${PASS_74x}"
"7 4 3 NONMEM7.4.3.zip ${PASS_74x}"
"7 4 4 NONMEM7.4.4.zip ${PASS_74x}"
"7 5 0 NONMEM750.zip ${PASS_75x}"
"7 5 1 NONMEM751.zip ${PASS_75x}"
"7 6 0 NONMEM760.zip ${PASS_760}"
)
# Ubuntu LTS versions for amd64 builds
AMD64_UBUNTU_VERSIONS=(14.04 16.04 18.04 20.04 22.04 24.04)
# Ubuntu LTS versions for arm64 builds (14.04/16.04 skipped: ARM toolchain too immature)
ARM64_UBUNTU_VERSIONS=(18.04 20.04 22.04 24.04)
# gfortran versions available in standard repos (no PPA) per Ubuntu release.
# Sourced empirically from apt-cache search on each Ubuntu version.
declare -A UBUNTU_GFORTRAN_VERSIONS=(
["14.04"]="4.4 4.6 4.7 4.8"
["16.04"]="4.7 4.8 4.9 5"
["18.04"]="4.8 5 6 7 8"
["20.04"]="7 8 9 10"
["22.04"]="9 10 11 12"
["24.04"]="9 10 11 12 13 14"
)
# For ARM64, only attempt NONMEM 7.5.1+ (older versions have x86-specific setup scripts)
is_compatible_arm64() {
local major=$1 minor=$2 patch=$3
if (( major < 7 )) || \
(( major == 7 && minor < 5 )) || \
(( major == 7 && minor == 5 && patch == 0 )); then
return 1
fi
return 0
}
# --- Parallel job tracking (by PID) ---
declare -a build_pids=()
run_build() {
local tag="$1"; shift
local cmd=("$@")
{
if "${cmd[@]}" >/dev/null 2>&1; then
echo "SUCCESS: ${tag}" | tee -a "${LOG_FILE}"
else
echo "FAILED: ${tag}" | tee -a "${LOG_FILE}"
fi
} &
build_pids+=($!)
# Throttle: when at the cap, wait for the oldest build to free a slot
if (( ${#build_pids[@]} >= MAX_JOBS )); then
wait "${build_pids[0]}" || true
build_pids=("${build_pids[@]:1}")
fi
}
# --- amd64 builds ---
echo "=== amd64 builds ===" | tee -a "${LOG_FILE}"
for entry in "${NONMEM_VERSIONS[@]}"; do
read -r major minor patch zipfile password <<< "${entry}"
for ubuntu in "${AMD64_UBUNTU_VERSIONS[@]}"; do
for gfc in ${UBUNTU_GFORTRAN_VERSIONS["${ubuntu}"]}; do
tag="humanpredictions/nonmem:${major}.${minor}.${patch}-ubuntu${ubuntu}-gfortran${gfc}-amd64"
run_build "${tag}" \
docker buildx build \
--platform linux/amd64 \
--load \
--build-context nonmem_zips="${NONMEM_ZIP_DIR}" \
--build-arg UBUNTU_VERSION="${ubuntu}" \
--build-arg NONMEM_MAJOR_VERSION="${major}" \
--build-arg NONMEM_MINOR_VERSION="${minor}" \
--build-arg NONMEM_PATCH_VERSION="${patch}" \
--build-arg NONMEM_ZIPFILE="${zipfile}" \
--build-arg NONMEMZIPPASS="${password}" \
--build-arg GFORTRAN_VERSION="${gfc}" \
-t "${tag}" \
-f "${SCRIPT_DIR}/NONMEM.Dockerfile" \
"${SCRIPT_DIR}"
done
done
done
# --- arm64 builds ---
if [[ "${BUILD_ARM64}" == true ]]; then
echo "" | tee -a "${LOG_FILE}"
echo "=== arm64 builds (Raspberry Pi 4/5 + AWS Graviton2/3/4) ===" | tee -a "${LOG_FILE}"
for entry in "${NONMEM_VERSIONS[@]}"; do
read -r major minor patch zipfile password <<< "${entry}"
if ! is_compatible_arm64 "${major}" "${minor}" "${patch}"; then
continue
fi
for ubuntu in "${ARM64_UBUNTU_VERSIONS[@]}"; do
for gfc in ${UBUNTU_GFORTRAN_VERSIONS["${ubuntu}"]}; do
tag="humanpredictions/nonmem:${major}.${minor}.${patch}-ubuntu${ubuntu}-gfortran${gfc}-arm64"
run_build "${tag}" \
docker buildx build \
--platform linux/arm64 \
--load \
--build-context nonmem_zips="${NONMEM_ZIP_DIR}" \
--build-arg UBUNTU_VERSION="${ubuntu}" \
--build-arg NONMEM_MAJOR_VERSION="${major}" \
--build-arg NONMEM_MINOR_VERSION="${minor}" \
--build-arg NONMEM_PATCH_VERSION="${patch}" \
--build-arg NONMEM_ZIPFILE="${zipfile}" \
--build-arg NONMEMZIPPASS="${password}" \
--build-arg GFORTRAN_VERSION="${gfc}" \
-t "${tag}" \
-f "${SCRIPT_DIR}/NONMEM.Dockerfile" \
"${SCRIPT_DIR}"
done
done
done
fi
# --- Wait for all remaining jobs ---
if (( ${#build_pids[@]} > 0 )); then
wait "${build_pids[@]}" || true
fi
# --- Summary ---
echo "" | tee -a "${LOG_FILE}"
echo "=== Summary ===" | tee -a "${LOG_FILE}"
successes=$(grep -c "^SUCCESS:" "${LOG_FILE}" || true)
failures=$(grep -c "^FAILED:" "${LOG_FILE}" || true)
echo "Succeeded: ${successes}" | tee -a "${LOG_FILE}"
echo "Failed: ${failures}" | tee -a "${LOG_FILE}"
echo "Build matrix completed at $(date)" | tee -a "${LOG_FILE}"