-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·49 lines (41 loc) · 1.35 KB
/
build.sh
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
#!/bin/bash
#
# This script is just for building locally. The production build is in
# .github/workflows.
#
set -eu
usage() {
echo >&2 "usage: $0 <major.minor.patch Ruby version to build e.g. 3.3.0>"
echo >&2 "To push after build, set PUSH_TO_REGISTRY=1 and a valid GITHUB_TOKEN."
exit 64
}
sha_for_version() {
jq -r <build-matrix.json \
'.version[] | select(.rubyver|join(".") == "'"$1"'") | .checksum'
}
major_minor_version() {
jq -r <build-matrix.json \
'.version[] | select(.rubyver|join(".") == "'"$1"'") | .rubyver[0:2]|join(".")'
}
build_version() {
ruby_version=$1
ruby_major_minor=$(major_minor_version "${ruby_version}")
for img in base builder; do
echo "Building ${img} image for Ruby ${ruby_major_minor} (${ruby_version})"
image_name="govuk-ruby-${img}"
docker buildx build \
--platform "${ARCHS:-linux/amd64,linux/arm64}" \
--load \
--build-arg "RUBY_MAJOR=${ruby_major_minor}" \
--build-arg "RUBY_VERSION=${ruby_version}" \
--build-arg "RUBY_CHECKSUM=$(sha_for_version "$ruby_version")" \
-t "ghcr.io/alphagov/${image_name}:${ruby_major_minor}" \
-f "${img}.Dockerfile" .
if [[ ${PUSH_TO_REGISTRY:-} = "1" ]]; then
echo "pushing to registry"
docker push "ghcr.io/alphagov/${image_name}:${ruby_major_minor}"
fi
done
}
[[ -n "${1:-}" ]] || usage
build_version "$1"