diff --git a/docker_templates/alpine-linux.Dockerfile.j2 b/docker_templates/alpine-linux.Dockerfile.j2 index 41d379279..c434d1e12 100644 --- a/docker_templates/alpine-linux.Dockerfile.j2 +++ b/docker_templates/alpine-linux.Dockerfile.j2 @@ -15,7 +15,7 @@ RUN set -eux; \ ca-certificates p11-kit-trust \ # locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8 musl-locales musl-locales-lang \ -{% include 'partials/binutils.j2' -%} + {%- include 'partials/binutils.j2' %} tzdata \ # Contains `csplit` used for splitting multiple certificates in one file to multiple files, since keytool can # only import one at a time. diff --git a/docker_templates/nanoserver.Dockerfile.j2 b/docker_templates/nanoserver.Dockerfile.j2 index 7341568bc..2d130044f 100644 --- a/docker_templates/nanoserver.Dockerfile.j2 +++ b/docker_templates/nanoserver.Dockerfile.j2 @@ -22,4 +22,4 @@ RUN echo Verifying install ... \ {% endif -%} && echo java {% if version|int >= 11 %}--{% else %}-{% endif %}version && java {% if version|int >= 11 %}--{% else %}-{% endif %}version \ && echo Complete. -{% include 'partials/jshell.j2' %} \ No newline at end of file +{% include 'partials/jshell.j2' %} diff --git a/docker_templates/partials/arch-variable.j2 b/docker_templates/partials/arch-variable.j2 index b40f728de..9e32b5848 100644 --- a/docker_templates/partials/arch-variable.j2 +++ b/docker_templates/partials/arch-variable.j2 @@ -4,4 +4,4 @@ ARCH="$(apk --print-arch)"; \ {%- elif os == "ubi9-minimal" %} ARCH="$(rpm --query --queryformat='%{ARCH}' rpm)"; \ -{%- endif -%} \ No newline at end of file +{%- endif -%} diff --git a/docker_templates/partials/binutils.j2 b/docker_templates/partials/binutils.j2 index d81e9ce8c..b4b7872d0 100644 --- a/docker_templates/partials/binutils.j2 +++ b/docker_templates/partials/binutils.j2 @@ -1,5 +1,5 @@ - {% if image_type == "jdk" and version|int >= 13 -%} +{% if image_type == "jdk" and version|int >= 13 %} # jlink --strip-debug on 13+ needs objcopy: https://github.com/docker-library/openjdk/issues/351 # Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory binutils \ - {% endif -%} +{%- endif -%} diff --git a/docker_templates/partials/multi-arch-install.j2 b/docker_templates/partials/multi-arch-install.j2 index 5ad1f5bb0..4f8a9e6a0 100644 --- a/docker_templates/partials/multi-arch-install.j2 +++ b/docker_templates/partials/multi-arch-install.j2 @@ -27,4 +27,4 @@ RUN set -eux; \ --strip-components 1 \ --no-same-owner \ ; \ - rm -f /tmp/openjdk.tar.gz ${JAVA_HOME}/lib/src.zip; \ No newline at end of file + rm -f /tmp/openjdk.tar.gz ${JAVA_HOME}/lib/src.zip; diff --git a/docker_templates/partials/version-check-windows.j2 b/docker_templates/partials/version-check-windows.j2 index fa4c2daac..3c0df1f4f 100644 --- a/docker_templates/partials/version-check-windows.j2 +++ b/docker_templates/partials/version-check-windows.j2 @@ -4,4 +4,4 @@ RUN Write-Host 'Verifying install ...'; \ {% endif -%} Write-Host 'java {% if version|int >= 11 %}--{% else %}-{% endif %}version'; java {% if version|int >= 11 %}--{% else %}-{% endif %}version; \ \ - Write-Host 'Complete.' \ No newline at end of file + Write-Host 'Complete.' diff --git a/docker_templates/partials/version-check.j2 b/docker_templates/partials/version-check.j2 index 50afca768..d019ebd99 100644 --- a/docker_templates/partials/version-check.j2 +++ b/docker_templates/partials/version-check.j2 @@ -7,4 +7,4 @@ RUN set -eux; \ echo "javac {% if version|int >= 11 %}--{% else %}-{% endif %}version"; javac {% if version|int >= 11 %}--{% else %}-{% endif %}version; \ {% endif -%} echo "java {% if version|int >= 11 %}--{% else %}-{% endif %}version"; java {% if version|int >= 11 %}--{% else %}-{% endif %}version; \ - echo "Complete." \ No newline at end of file + echo "Complete." diff --git a/docker_templates/servercore.Dockerfile.j2 b/docker_templates/servercore.Dockerfile.j2 index 45d0e6d83..44d53c8da 100644 --- a/docker_templates/servercore.Dockerfile.j2 +++ b/docker_templates/servercore.Dockerfile.j2 @@ -31,4 +31,4 @@ RUN Write-Host ('Downloading {{ arch_data.download_url }} ...'); \ Remove-Item openjdk.msi -Force {% include 'partials/version-check-windows.j2' %} -{% include 'partials/jshell.j2' %} \ No newline at end of file +{% include 'partials/jshell.j2' %} diff --git a/docker_templates/ubi9-minimal.Dockerfile.j2 b/docker_templates/ubi9-minimal.Dockerfile.j2 index c8680184d..c4e7e1bcd 100644 --- a/docker_templates/ubi9-minimal.Dockerfile.j2 +++ b/docker_templates/ubi9-minimal.Dockerfile.j2 @@ -30,4 +30,4 @@ ENV JAVA_VERSION {{ java_version }} {% include 'partials/version-check.j2' %} COPY entrypoint.sh /__cacert_entrypoint.sh ENTRYPOINT ["/__cacert_entrypoint.sh"] -{% include 'partials/jshell.j2' %} \ No newline at end of file +{% include 'partials/jshell.j2' %} diff --git a/docker_templates/ubuntu.Dockerfile.j2 b/docker_templates/ubuntu.Dockerfile.j2 index 05dac147a..46e1b0453 100644 --- a/docker_templates/ubuntu.Dockerfile.j2 +++ b/docker_templates/ubuntu.Dockerfile.j2 @@ -19,7 +19,7 @@ RUN set -eux; \ # utilities for keeping Ubuntu and OpenJDK CA certificates in sync # https://github.com/adoptium/containers/issues/293 ca-certificates p11-kit \ -{% include 'partials/binutils.j2' -%} + {%- include 'partials/binutils.j2' %} tzdata \ # locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8 locales \ @@ -44,4 +44,4 @@ ENV JAVA_VERSION {{ java_version }} {% include 'partials/version-check.j2' %} COPY entrypoint.sh /__cacert_entrypoint.sh ENTRYPOINT ["/__cacert_entrypoint.sh"] -{% include 'partials/jshell.j2' %} \ No newline at end of file +{% include 'partials/jshell.j2' %} diff --git a/test_generate_dockerfiles.py b/test_generate_dockerfiles.py index 2e2f0b72e..8a8f32e18 100644 --- a/test_generate_dockerfiles.py +++ b/test_generate_dockerfiles.py @@ -157,6 +157,81 @@ def test_jdk11plus_jshell_cmd(self): expected_string = 'CMD ["jshell"]' self.assertNotIn(expected_string, rendered_template) + def test_binutils_inclusion(self): + template_name = "ubuntu.Dockerfile.j2" + template = self.env.get_template(template_name) + + # Binutils should be included for jdk images with version >= 13 + with self.subTest("jdk 13+ should include binutils"): + context = { + "version": 13, + "image_type": "jdk", + "os": "ubuntu", + "arch_data": {}, + } + rendered_template = template.render(**context) + self.assertIn("binutils", rendered_template) + + # Binutils should not be included for jre images regardless of version + with self.subTest("jre 13+ should not include binutils"): + context = { + "version": 13, + "image_type": "jre", + "os": "ubuntu", + "arch_data": {}, + } + rendered_template = template.render(**context) + self.assertNotIn("binutils", rendered_template) + + # Binutils should not be included for jdk images with version < 13 + with self.subTest("jdk < 13 should not include binutils"): + context = { + "version": 12, + "image_type": "jdk", + "os": "ubuntu", + "arch_data": {}, + } + rendered_template = template.render(**context) + self.assertNotIn("binutils", rendered_template) + + def test_arch_data_population(self): + template_name = "ubuntu.Dockerfile.j2" + template = self.env.get_template(template_name) + + # Simulate API response + arch_data = { + "amd64": { + "download_url": "http://fake-url.com", + "checksum": "fake-checksum", + } + } + + context = { + "version": 11, + "image_type": "jdk", + "os": "ubuntu", + "arch_data": arch_data, + } + rendered_template = template.render(**context) + + self.assertIn("http://fake-url.com", rendered_template) + self.assertIn("fake-checksum", rendered_template) + + def test_entrypoint_rendering(self): + template_name = "entrypoint.sh.j2" + template = self.env.get_template(template_name) + + context = { + "image_type": "jdk", + "os": "ubuntu", + "version": 11, + } + rendered_template = template.render(**context) + + # Ensure that the entrypoint script contains expected commands + self.assertIn("update-ca-certificates", rendered_template) + self.assertIn("exec \"$@\"", rendered_template) + if __name__ == "__main__": unittest.main()