Skip to content

Commit 7e63843

Browse files
committed
Add initial jq-based templating engine
This makes our templating much more sustainable, and will allow our commit automation to make better commit messages (`Update 3.8 to openssl 1.1.1i`, `Update 3.8 to 3.8.10`, etc).
1 parent 2a3ffff commit 7e63843

19 files changed

+393
-204
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*/**/Dockerfile linguist-generated
2+
/*/**/docker-entrypoint.sh linguist-generated
3+
/Dockerfile*.template linguist-language=Dockerfile
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Verify Templating
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
defaults:
8+
run:
9+
shell: 'bash -Eeuo pipefail -x {0}'
10+
11+
jobs:
12+
apply-templates:
13+
name: Check For Uncomitted Changes
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Apply Templates
18+
run: ./apply-templates.sh
19+
- name: Check Git Status
20+
run: |
21+
status="$(git status --short)"
22+
[ -z "$status" ]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.jq-template.awk

3.8-rc/alpine/Dockerfile

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8-rc/alpine/management/Dockerfile

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8-rc/ubuntu/Dockerfile

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8-rc/ubuntu/management/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8/alpine/Dockerfile

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8/alpine/management/Dockerfile

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8/ubuntu/Dockerfile

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3.8/ubuntu/management/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile-alpine.template

+28-8
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,37 @@ ARG PGP_KEYSERVER=ha.pool.sks-keyservers.net
1515
# run the build with a different PGP_KEYSERVER, e.g. docker build --tag rabbitmq:3.8 --build-arg PGP_KEYSERVER=pgpkeys.eu 3.8/ubuntu
1616
# For context, see https://github.com/docker-library/official-images/issues/4252
1717

18-
# Using the latest OpenSSL LTS release, with support until September 2023 - https://www.openssl.org/source/
19-
ENV OPENSSL_VERSION %%OPENSSL_VERSION%%
20-
ENV OPENSSL_SOURCE_SHA256="%%OPENSSL_SOURCE_SHA256%%"
18+
ENV OPENSSL_VERSION {{ .openssl.version }}
19+
ENV OPENSSL_SOURCE_SHA256="{{ .openssl.sha256 }}"
2120
# https://www.openssl.org/community/omc.html
22-
ENV OPENSSL_PGP_KEY_IDS="%%OPENSSL_PGP_KEY_IDS%%"
21+
ENV OPENSSL_PGP_KEY_IDS="{{
22+
[
23+
# Matt Caswell
24+
"8657 ABB2 60F0 56B1 E519 0839 D9C4 D26D 0E60 4491",
2325

24-
# Use the latest stable Erlang/OTP release (https://github.com/erlang/otp/tags)
25-
ENV OTP_VERSION %%OTP_VERSION%%
26+
# Mark J. Cox
27+
"5B25 45DA B219 95F4 088C EFAA 36CE E4DE B00C FE33",
28+
29+
# Paul Dale
30+
"ED23 0BEC 4D4F 2518 B9D7 DF41 F0DB 4D21 C1D3 5231",
31+
32+
# Tim Hudson
33+
"C1F3 3DD8 CE1D 4CC6 13AF 14DA 9195 C482 41FB F7DD",
34+
35+
# Richard Levitte
36+
"7953 AC1F BC3D C8B3 B292 393E D5E9 E43F 7DF9 EE8C",
37+
38+
# Kurt Roeckx
39+
"E5E5 2560 DD91 C556 DDBD A5D0 2064 C536 41C2 5E5D"
40+
]
41+
# TODO auto-generate / scrape this list from the canonical upstream source instead (check the signature file and add an entry in the .openssl object with just the one signature that we expect to have signed this release, after cross-referencing the official OMC list?)
42+
| map("0x" + gsub(" "; "")) | join(" ")
43+
}}"
44+
45+
ENV OTP_VERSION {{ .otp.version }}
2646
# TODO add PGP checking when the feature will be added to Erlang/OTP's build system
2747
# http://erlang.org/pipermail/erlang-questions/2019-January/097067.html
28-
ENV OTP_SOURCE_SHA256="%%OTP_SOURCE_SHA256%%"
48+
ENV OTP_SOURCE_SHA256="{{ .otp.sha256 }}"
2949

3050
# Install dependencies required to build Erlang/OTP from source
3151
# http://erlang.org/doc/installation_guide/INSTALL.html
@@ -180,7 +200,7 @@ RUN set -eux; \
180200
ln -sf "$RABBITMQ_DATA_DIR/.erlang.cookie" /root/.erlang.cookie
181201

182202
# Use the latest stable RabbitMQ release (https://www.rabbitmq.com/download.html)
183-
ENV RABBITMQ_VERSION %%RABBITMQ_VERSION%%
203+
ENV RABBITMQ_VERSION {{ .version }}
184204
# https://www.rabbitmq.com/signatures.html#importing-gpg
185205
ENV RABBITMQ_PGP_KEY_ID="0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
186206
ENV RABBITMQ_HOME=/opt/rabbitmq

Dockerfile-management.template

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM %%FROM%%
1+
FROM {{
2+
"rabbitmq:" + env.version
3+
+ if env.variant == "alpine" then "-alpine" else "" end
4+
}}
25

36
RUN rabbitmq-plugins enable --offline rabbitmq_management
47

@@ -24,7 +27,13 @@ RUN set -eux; \
2427
' -- /plugins/rabbitmq_management-*.ez > /usr/local/bin/rabbitmqadmin; \
2528
[ -s /usr/local/bin/rabbitmqadmin ]; \
2629
chmod +x /usr/local/bin/rabbitmqadmin; \
27-
%%INSTALL_PYTHON%%; \
30+
{{ if env.variant == "alpine" then ( -}}
31+
apk add --no-cache python3; \
32+
{{ ) else ( -}}
33+
apt-get update; \
34+
apt-get install -y --no-install-recommends python3; \
35+
rm -rf /var/lib/apt/lists/*; \
36+
{{ ) end -}}
2837
rabbitmqadmin --version
2938

3039
EXPOSE 15671 15672

Dockerfile-ubuntu.template

+28-8
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,37 @@ ARG PGP_KEYSERVER=ha.pool.sks-keyservers.net
1818
# run the build with a different PGP_KEYSERVER, e.g. docker build --tag rabbitmq:3.8 --build-arg PGP_KEYSERVER=pgpkeys.eu 3.8/ubuntu
1919
# For context, see https://github.com/docker-library/official-images/issues/4252
2020

21-
# Using the latest OpenSSL LTS release, with support until September 2023 - https://www.openssl.org/source/
22-
ENV OPENSSL_VERSION %%OPENSSL_VERSION%%
23-
ENV OPENSSL_SOURCE_SHA256="%%OPENSSL_SOURCE_SHA256%%"
21+
ENV OPENSSL_VERSION {{ .openssl.version }}
22+
ENV OPENSSL_SOURCE_SHA256="{{ .openssl.sha256 }}"
2423
# https://www.openssl.org/community/omc.html
25-
ENV OPENSSL_PGP_KEY_IDS="%%OPENSSL_PGP_KEY_IDS%%"
24+
ENV OPENSSL_PGP_KEY_IDS="{{
25+
[
26+
# Matt Caswell
27+
"8657 ABB2 60F0 56B1 E519 0839 D9C4 D26D 0E60 4491",
2628

27-
# Use the latest stable Erlang/OTP release (https://github.com/erlang/otp/tags)
28-
ENV OTP_VERSION %%OTP_VERSION%%
29+
# Mark J. Cox
30+
"5B25 45DA B219 95F4 088C EFAA 36CE E4DE B00C FE33",
31+
32+
# Paul Dale
33+
"ED23 0BEC 4D4F 2518 B9D7 DF41 F0DB 4D21 C1D3 5231",
34+
35+
# Tim Hudson
36+
"C1F3 3DD8 CE1D 4CC6 13AF 14DA 9195 C482 41FB F7DD",
37+
38+
# Richard Levitte
39+
"7953 AC1F BC3D C8B3 B292 393E D5E9 E43F 7DF9 EE8C",
40+
41+
# Kurt Roeckx
42+
"E5E5 2560 DD91 C556 DDBD A5D0 2064 C536 41C2 5E5D"
43+
]
44+
# TODO auto-generate / scrape this list from the canonical upstream source instead (check the signature file and add an entry in the .openssl object with just the one signature that we expect to have signed this release, after cross-referencing the official OMC list?)
45+
| map("0x" + gsub(" "; "")) | join(" ")
46+
}}"
47+
48+
ENV OTP_VERSION {{ .otp.version }}
2949
# TODO add PGP checking when the feature will be added to Erlang/OTP's build system
3050
# http://erlang.org/pipermail/erlang-questions/2019-January/097067.html
31-
ENV OTP_SOURCE_SHA256="%%OTP_SOURCE_SHA256%%"
51+
ENV OTP_SOURCE_SHA256="{{ .otp.sha256 }}"
3252

3353
# Install dependencies required to build Erlang/OTP from source
3454
# http://erlang.org/doc/installation_guide/INSTALL.html
@@ -191,7 +211,7 @@ RUN set -eux; \
191211
ln -sf "$RABBITMQ_DATA_DIR/.erlang.cookie" /root/.erlang.cookie
192212

193213
# Use the latest stable RabbitMQ release (https://www.rabbitmq.com/download.html)
194-
ENV RABBITMQ_VERSION %%RABBITMQ_VERSION%%
214+
ENV RABBITMQ_VERSION {{ .version }}
195215
# https://www.rabbitmq.com/signatures.html#importing-gpg
196216
ENV RABBITMQ_PGP_KEY_ID="0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
197217
ENV RABBITMQ_HOME=/opt/rabbitmq

apply-templates.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
[ -f versions.json ] # run "versions.sh" first
5+
6+
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
7+
8+
jqt='.jq-template.awk'
9+
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
10+
jqt="$BASHBREW_SCRIPTS/jq-template.awk"
11+
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then
12+
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/5f0c26381fb7cc78b2d217d58007800bdcfbcfa1/scripts/jq-template.awk'
13+
fi
14+
15+
if [ "$#" -eq 0 ]; then
16+
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
17+
eval "set -- $versions"
18+
fi
19+
20+
generated_warning() {
21+
cat <<-EOH
22+
#
23+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
24+
#
25+
# PLEASE DO NOT EDIT IT DIRECTLY.
26+
#
27+
28+
EOH
29+
}
30+
31+
for version; do
32+
export version
33+
34+
for variant in alpine ubuntu; do
35+
export variant
36+
37+
echo "processing $version/$variant ..."
38+
39+
{
40+
generated_warning
41+
gawk -f "$jqt" "Dockerfile-$variant.template"
42+
} > "$version/$variant/Dockerfile"
43+
44+
cp -a docker-entrypoint.sh "$version/$variant/"
45+
46+
if [ "$variant" = 'alpine' ]; then
47+
sed -i -e 's/gosu/su-exec/g' "$version/$variant/docker-entrypoint.sh"
48+
fi
49+
50+
echo "processing $version/$variant/management ..."
51+
52+
{
53+
generated_warning
54+
gawk -f "$jqt" Dockerfile-management.template
55+
} > "$version/$variant/management/Dockerfile"
56+
done
57+
done

0 commit comments

Comments
 (0)