Skip to content

Commit f56f55b

Browse files
authoredAug 13, 2024··
jinja refactoring and more test coverage (#629)
1 parent 0327d46 commit f56f55b

11 files changed

+88
-10
lines changed
 

‎.github/workflows/code-freeze.yml

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333

3434
# Code freeze if branch-regex matches
3535
codefreeze_if_branch_match:
36+
permissions:
37+
contents: write
38+
pull-requests: write
3639
needs: codefreeze_branch_check
3740
uses: adoptium/.github/.github/workflows/code-freeze.yml@main
3841
if: (github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && needs.codefreeze_branch_check.outputs.regex-matches == 'true'

‎docker_templates/alpine-linux.Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN set -eux; \
1515
ca-certificates p11-kit-trust \
1616
# locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8
1717
musl-locales musl-locales-lang \
18-
{% include 'partials/binutils.j2' -%}
18+
{%- include 'partials/binutils.j2' %}
1919
tzdata \
2020
# Contains `csplit` used for splitting multiple certificates in one file to multiple files, since keytool can
2121
# only import one at a time.

‎docker_templates/nanoserver.Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ RUN echo Verifying install ... \
2222
{% endif -%}
2323
&& echo java {% if version|int >= 11 %}--{% else %}-{% endif %}version && java {% if version|int >= 11 %}--{% else %}-{% endif %}version \
2424
&& echo Complete.
25-
{% include 'partials/jshell.j2' %}
25+
{% include 'partials/jshell.j2' %}

‎docker_templates/partials/arch-variable.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
ARCH="$(apk --print-arch)"; \
55
{%- elif os == "ubi9-minimal" %}
66
ARCH="$(rpm --query --queryformat='%{ARCH}' rpm)"; \
7-
{%- endif -%}
7+
{%- endif -%}

‎docker_templates/partials/binutils.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{% if image_type == "jdk" and version|int >= 13 -%}
1+
{% if image_type == "jdk" and version|int >= 13 %}
22
# jlink --strip-debug on 13+ needs objcopy: https://github.com/docker-library/openjdk/issues/351
33
# Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory
44
binutils \
5-
{% endif -%}
5+
{%- endif -%}

‎docker_templates/partials/multi-arch-install.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ RUN set -eux; \
2727
--strip-components 1 \
2828
--no-same-owner \
2929
; \
30-
rm -f /tmp/openjdk.tar.gz ${JAVA_HOME}/lib/src.zip;
30+
rm -f /tmp/openjdk.tar.gz ${JAVA_HOME}/lib/src.zip;

‎docker_templates/partials/version-check-windows.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ RUN Write-Host 'Verifying install ...'; \
44
{% endif -%}
55
Write-Host 'java {% if version|int >= 11 %}--{% else %}-{% endif %}version'; java {% if version|int >= 11 %}--{% else %}-{% endif %}version; \
66
\
7-
Write-Host 'Complete.'
7+
Write-Host 'Complete.'

‎docker_templates/partials/version-check.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ RUN set -eux; \
77
echo "javac {% if version|int >= 11 %}--{% else %}-{% endif %}version"; javac {% if version|int >= 11 %}--{% else %}-{% endif %}version; \
88
{% endif -%}
99
echo "java {% if version|int >= 11 %}--{% else %}-{% endif %}version"; java {% if version|int >= 11 %}--{% else %}-{% endif %}version; \
10-
echo "Complete."
10+
echo "Complete."

‎docker_templates/servercore.Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ RUN Write-Host ('Downloading {{ arch_data.download_url }} ...'); \
3131
Remove-Item openjdk.msi -Force
3232

3333
{% include 'partials/version-check-windows.j2' %}
34-
{% include 'partials/jshell.j2' %}
34+
{% include 'partials/jshell.j2' %}

‎docker_templates/ubuntu.Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN set -eux; \
1919
# utilities for keeping Ubuntu and OpenJDK CA certificates in sync
2020
# https://github.com/adoptium/containers/issues/293
2121
ca-certificates p11-kit \
22-
{% include 'partials/binutils.j2' -%}
22+
{%- include 'partials/binutils.j2' %}
2323
tzdata \
2424
# locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8
2525
locales \

‎test_generate_dockerfiles.py

+75
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,81 @@ def test_jdk11plus_jshell_cmd(self):
157157
expected_string = 'CMD ["jshell"]'
158158
self.assertNotIn(expected_string, rendered_template)
159159

160+
def test_binutils_inclusion(self):
161+
template_name = "ubuntu.Dockerfile.j2"
162+
template = self.env.get_template(template_name)
163+
164+
# Binutils should be included for jdk images with version >= 13
165+
with self.subTest("jdk 13+ should include binutils"):
166+
context = {
167+
"version": 13,
168+
"image_type": "jdk",
169+
"os": "ubuntu",
170+
"arch_data": {},
171+
}
172+
rendered_template = template.render(**context)
173+
self.assertIn("binutils", rendered_template)
174+
175+
# Binutils should not be included for jre images regardless of version
176+
with self.subTest("jre 13+ should not include binutils"):
177+
context = {
178+
"version": 13,
179+
"image_type": "jre",
180+
"os": "ubuntu",
181+
"arch_data": {},
182+
}
183+
rendered_template = template.render(**context)
184+
self.assertNotIn("binutils", rendered_template)
185+
186+
# Binutils should not be included for jdk images with version < 13
187+
with self.subTest("jdk < 13 should not include binutils"):
188+
context = {
189+
"version": 12,
190+
"image_type": "jdk",
191+
"os": "ubuntu",
192+
"arch_data": {},
193+
}
194+
rendered_template = template.render(**context)
195+
self.assertNotIn("binutils", rendered_template)
196+
197+
def test_arch_data_population(self):
198+
template_name = "ubuntu.Dockerfile.j2"
199+
template = self.env.get_template(template_name)
200+
201+
# Simulate API response
202+
arch_data = {
203+
"amd64": {
204+
"download_url": "http://fake-url.com",
205+
"checksum": "fake-checksum",
206+
}
207+
}
208+
209+
context = {
210+
"version": 11,
211+
"image_type": "jdk",
212+
"os": "ubuntu",
213+
"arch_data": arch_data,
214+
}
215+
rendered_template = template.render(**context)
216+
217+
self.assertIn("http://fake-url.com", rendered_template)
218+
self.assertIn("fake-checksum", rendered_template)
219+
220+
def test_entrypoint_rendering(self):
221+
template_name = "entrypoint.sh.j2"
222+
template = self.env.get_template(template_name)
223+
224+
context = {
225+
"image_type": "jdk",
226+
"os": "ubuntu",
227+
"version": 11,
228+
}
229+
rendered_template = template.render(**context)
230+
231+
# Ensure that the entrypoint script contains expected commands
232+
self.assertIn("update-ca-certificates", rendered_template)
233+
self.assertIn("exec \"$@\"", rendered_template)
234+
160235

161236
if __name__ == "__main__":
162237
unittest.main()

0 commit comments

Comments
 (0)