Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding docker image templates #175

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions bin/apply-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def process_template_files(major_version, version, platform):

template = templateEnv.get_template(f"{platform}.Dockerfile.template")
input_parameter = {}
if major_version == '8' and platform!= 'alpine':
version = '1.8.0'
input_parameter['CORRETTO_VERSION'] = version
input_parameter['MAJOR_VERSION'] = major_version
if platform == 'alpine':
Expand All @@ -19,24 +21,61 @@ def process_template_files(major_version, version, platform):
shutil.rmtree(f"{major_version}/jre/{platform}")
except:
pass
for os_version in os_versions:
input_parameter['OS_VERSION'] = os_version
os.makedirs(f"{major_version}/jdk/{platform}/{os_version}/", exist_ok=True)
with open(f"{major_version}/jdk/{platform}/{os_version}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter))
if platform == 'alpine':
for os_version in os_versions:
input_parameter['OS_VERSION'] = os_version
os.makedirs(f"{major_version}/jdk/{platform}/{os_version}/", exist_ok=True)
with open(f"{major_version}/jdk/{platform}/{os_version}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter))

if major_version == '8':
os.makedirs(f"{major_version}/jre/{platform}/{os_version}/", exist_ok=True)
with open(f"{major_version}/jre/{platform}/{os_version}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter, **{'jre':True}))

elif 'headless' in platform or 'headful' in platform:
head_variant = 'headless' if 'headless' in platform else 'headful'
if major_version=='11' or major_version=='17':
os.makedirs(f"{major_version}/{head_variant}/{platform}/", exist_ok=True)
with open(f"{major_version}/{head_variant}/{platform}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter))

elif platform == 'al2023-generic':
if major_version=='20':
os.makedirs(f"{major_version}/jdk/{platform}/", exist_ok=True)
with open(f"{major_version}/jdk/{platform}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter))

else:
os.makedirs(f"{major_version}/jdk/{platform}/", exist_ok=True)
with open(f"{major_version}/jdk/{platform}/Dockerfile", 'w') as output:
if major_version == '8':
output.write(template.render(**input_parameter, **{'version_8':True}))
elif major_version == '11':
output.write(template.render(**input_parameter, **{'version_11':True}))
else:
output.write(template.render(**input_parameter))

if major_version == '8' and platform != 'al2-generic':
os.makedirs(f"{major_version}/jre/{platform}/", exist_ok=True)
with open(f"{major_version}/jre/{platform}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter, **{'jre':True, 'version_8':True}))


if major_version == '8':
os.makedirs(f"{major_version}/jre/{platform}/{os_version}/", exist_ok=True)
with open(f"{major_version}/jre/{platform}/{os_version}/Dockerfile", 'w') as output:
output.write(template.render(**input_parameter, **{'jre':True}))

def main():
with open('versions.json','r') as version_file:
versions = json.load(version_file)

for key in versions:
process_template_files(key, versions[key], 'alpine')
process_template_files(key, versions[key], 'al2')
process_template_files(key, versions[key], 'al2-generic')
process_template_files(key, versions[key], 'al2-headful')
process_template_files(key, versions[key], 'al2-headless')
process_template_files(key, versions[key], 'al2023')
process_template_files(key, versions[key], 'al2023-generic')
process_template_files(key, versions[key], 'al2023-headful')
process_template_files(key, versions[key], 'al2023-headless')

if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions templates/al2-generic.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM amazonlinux:2

ARG version={{CORRETTO_VERSION}}
# In addition to installing the Amazon corretto, we also install
# fontconfig. The folks who manage the docker hub's
# official image library have found that font management
# is a common usecase, and painpoint, and have
# recommended that Java images include font support.
#
# See:
# https://github.com/docker-library/official-images/blob/master/test/tests/java-uimanager-font/container.java

# The logic and code related to Fingerprint is contributed by @tianon in a Github PR's Conversation
# Comment = https://github.com/docker-library/official-images/pull/7459#issuecomment-592242757
# PR = https://github.com/docker-library/official-images/pull/7459
RUN set -eux \
&& export GNUPGHOME="$(mktemp -d)" \
&& curl -fL -o corretto.key https://yum.corretto.aws/corretto.key \
&& gpg --batch --import corretto.key \
&& gpg --batch --export --armor '6DC3636DAE534049C8B94623A122542AB04F24E3' > corretto.key \
&& rpm --import corretto.key \
&& rm -r "$GNUPGHOME" corretto.key \
&& curl -fL -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo \
&& grep -q '^gpgcheck=1' /etc/yum.repos.d/corretto.repo \
&& echo "priority=9" >> /etc/yum.repos.d/corretto.repo \{% if version_8 %}
&& yum install -y java-{{CORRETTO_VERSION}}-amazon-corretto-devel-$version \
&& (find /usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto -name src.zip -delete || true) \{% else %}
&& yum install -y java-{{MAJOR_VERSION}}-amazon-corretto-devel-$version \
&& (find /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto -name src.zip -delete || true) \{% endif %}
&& yum install -y fontconfig \
&& yum clean all

ENV LANG C.UTF-8
{% if version_8 %}ENV JAVA_HOME=/usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto
{% else %}ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto{% endif %}
26 changes: 26 additions & 0 deletions templates/al2-headful.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM amazonlinux:2

ARG version={{CORRETTO_VERSION}}

RUN set -eux \
&& export resouce_version=$(echo $version | tr '-' '.') \
&& rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2 \
&& echo "localpkg_gpgcheck=1" >> /etc/yum.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \
&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2.1.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-$version.amzn2.1.$(uname -m).rpm") \
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/${resouce_version}/${rpm} \
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: rsa sha1 (md5) pgp md5 OK" || exit 1 \
&& yum install -y $(yum deplist "${CORRETO_TEMP}/${rpm}" |grep provider | grep -vE "log4j-cve|corretto" | tr -s ' ' |cut -d ' ' -f 3 ); \
done \
&& rpm -i --nodeps ${CORRETO_TEMP}/*.rpm \
&& popd \
&& (find /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m) -name src.zip -delete || true) \
&& rm -rf ${CORRETO_TEMP} \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& sed -i '/localpkg_gpgcheck=1/d' /etc/yum.conf

ENV LANG C.UTF-8
ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto
26 changes: 26 additions & 0 deletions templates/al2-headless.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM amazonlinux:2

ARG version={{CORRETTO_VERSION}}

RUN set -eux \
&& export resouce_version=$(echo $version | tr '-' '.') \
&& rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2 \
&& echo "localpkg_gpgcheck=1" >> /etc/yum.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \
&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2.1.$(uname -m).rpm") \
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/${resouce_version}/${rpm} \
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: rsa sha1 (md5) pgp md5 OK" || exit 1 \
&& yum install -y $(yum deplist "${CORRETO_TEMP}/${rpm}" |grep provider | grep -vE "log4j-cve|corretto" | tr -s ' ' |cut -d ' ' -f 3 ); \
done \
&& rpm -i --nodeps ${CORRETO_TEMP}/*.rpm \
&& popd \
&& (find /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m) -name src.zip -delete || true) \
&& rm -rf ${CORRETO_TEMP} \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& sed -i '/localpkg_gpgcheck=1/d' /etc/yum.conf

ENV LANG C.UTF-8
ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto
31 changes: 31 additions & 0 deletions templates/al2.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM amazonlinux:2

ARG version={{CORRETTO_VERSION}}

RUN set -eux \
{%if version_8 %}&& export resouce_version=$(echo $version | tr '-' '.' | tr '_' '.'| tr -d "b" | awk -F. '{print $2"."$4"."$5"."$6}') \{% else %}&& export resouce_version=$(echo $version | tr '-' '.') \{% endif %}
&& rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2 \
&& echo "localpkg_gpgcheck=1" >> /etc/yum.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \
{% if jre %}&& RPM_LIST=("java-{{CORRETTO_VERSION}}-amazon-corretto-$version.amzn2.$(uname -m).rpm") \{% elif version_8 %}&& RPM_LIST=("java-{{CORRETTO_VERSION}}-amazon-corretto-$version.amzn2.$(uname -m).rpm" "java-{{CORRETTO_VERSION}}-amazon-corretto-devel-$version.amzn2.$(uname -m).rpm") \{% elif version_11 %}&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-$version.amzn2.$(uname -m).rpm") \{% else %}&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2.1.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-$version.amzn2.1.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-devel-$version.amzn2.1.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-jmods-$version.amzn2.1.$(uname -m).rpm") \{% endif %}
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/${resouce_version}/${rpm} \{% if jre %}
&& echo $(rpm -K "${CORRETO_TEMP}/${rpm}") \{% endif %}
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: rsa sha1 (md5) pgp md5 OK" || exit 1 \{% if jre %}
done \{% endif %}{% if version_8 %}
&& yum install -y $(yum deplist "${CORRETO_TEMP}/${rpm}" |grep provider | grep -v log4j-cve | tr -s ' ' |cut -d ' ' -f 3 ); \{% else %}
&& if [[ ${rpm} != *jmods* ]]; then \
yum install -y $(yum deplist "${CORRETO_TEMP}/${rpm}" |grep provider | grep -vE "log4j-cve|corretto" | tr -s ' ' |cut -d ' ' -f 3 ); \
fi; \{% endif %}{% if not jre %}
done \{% endif %}
&& rpm -i --nodeps ${CORRETO_TEMP}/*.rpm \
&& popd \
{%if version_8 %}&& (find /usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto.$(uname -m) -name "*src.zip" -delete || true) \{% else %}&& (find /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m) -name src.zip -delete || true) \{% endif %}
&& rm -rf ${CORRETO_TEMP} \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& sed -i '/localpkg_gpgcheck=1/d' /etc/yum.conf

ENV LANG C.UTF-8
{%if jre %}ENV JAVA_HOME=/usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto/jre{% elif version_8 %}ENV JAVA_HOME=/usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto{% else %}ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto{% endif %}
29 changes: 29 additions & 0 deletions templates/al2023-generic.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM amazonlinux:2023

ARG version={{CORRETTO_VERSION}}
# In addition to installing the Amazon corretto, we also install
# libs that are needed for jdk to be functional

# The logic and code related to Fingerprint is contributed by @tianon in a Github PR's Conversation
# Comment = https://github.com/docker-library/official-images/pull/7459#issuecomment-592242757
# PR = https://github.com/docker-library/official-images/pull/7459
RUN set -eux \
&& export GNUPGHOME="$(mktemp -d)" \
&& curl -fL -o corretto.key https://yum.corretto.aws/corretto.key \
&& dnf install gnupg2 -y --allowerasing \
&& dnf install findutils -y \
&& gpg --batch --import corretto.key \
&& gpg --batch --export --armor '6DC3636DAE534049C8B94623A122542AB04F24E3' > corretto.key \
&& rpm --import corretto.key \
&& rm -r "$GNUPGHOME" corretto.key \
&& curl -fL -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo \
&& grep -q '^gpgcheck=1' /etc/yum.repos.d/corretto.repo \
&& echo "priority=9" >> /etc/yum.repos.d/corretto.repo \
&& dnf install -y java-{{MAJOR_VERSION}}-amazon-corretto-devel-$version \
&& (find /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto -name src.zip -delete || true) \
&& dnf remove -y findutils \
&& dnf install -y fontconfig freetype libjpeg dejavu-sans-fonts dejavu-serif-fonts dejavu-sans-mono-fonts libjpeg \
&& dnf clean all

ENV LANG C.UTF-8
ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto
24 changes: 24 additions & 0 deletions templates/al2023-headful.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM amazonlinux:2023

ARG version={{CORRETTO_VERSION}}
ARG package_version=1

RUN set -eux \
&& rpm --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2023 \
&& echo "localpkg_gpgcheck=1" >> /etc/dnf/dnf.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \
&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2023.${package_version}.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-$version.amzn2023.${package_version}.$(uname -m).rpm") \
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/$(echo $version | tr '-' '.')/${rpm} \
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: digests signatures OK" || exit 1; \
done \
&& dnf install -y ${CORRETO_TEMP}/*.rpm \
&& popd \
&& rm -rf /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m)/lib/src.zip \
&& rm -rf ${CORRETO_TEMP} \
&& dnf clean all \
&& sed -i '/localpkg_gpgcheck=1/d' /etc/dnf/dnf.conf

ENV LANG C.UTF-8
ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto
24 changes: 24 additions & 0 deletions templates/al2023-headless.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM amazonlinux:2023

ARG version={{CORRETTO_VERSION}}
ARG package_version=1

RUN set -eux \
&& rpm --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2023 \
&& echo "localpkg_gpgcheck=1" >> /etc/dnf/dnf.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \
&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2023.${package_version}.$(uname -m).rpm") \
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/$(echo $version | tr '-' '.')/${rpm} \
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: digests signatures OK" || exit 1; \
done \
&& dnf install -y ${CORRETO_TEMP}/*.rpm \
&& popd \
&& rm -rf /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m)/lib/src.zip \
&& rm -rf ${CORRETO_TEMP} \
&& dnf clean all \
&& sed -i '/localpkg_gpgcheck=1/d' /etc/dnf/dnf.conf

ENV LANG C.UTF-8
ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto
30 changes: 30 additions & 0 deletions templates/al2023.Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM amazonlinux:2023

ARG version={{CORRETTO_VERSION}}{% if not version_8 %}
ARG package_version=1{% endif %}

RUN set -eux \{%if version_8 %}
&& export resouce_version=$(echo $version | tr '-' '.' | tr '_' '.'| tr -d "b" | awk -F. '{print $2"."$4"."$5"."$6}') \{% endif %}
&& rpm --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2023 \
&& echo "localpkg_gpgcheck=1" >> /etc/dnf/dnf.conf \
&& CORRETO_TEMP=$(mktemp -d) \
&& pushd ${CORRETO_TEMP} \{% if jre %}
&& RPM_LIST=("java-{{CORRETTO_VERSION}}-amazon-corretto-$version.amzn2023.$(uname -m).rpm") \{% elif version_8 %}
&& RPM_LIST=("java-{{CORRETTO_VERSION}}-amazon-corretto-$version.amzn2023.$(uname -m).rpm" "java-{{CORRETTO_VERSION}}-amazon-corretto-devel-$version.amzn2023.$(uname -m).rpm") \{% else %}
&& RPM_LIST=("java-{{MAJOR_VERSION}}-amazon-corretto-headless-$version.amzn2023.${package_version}.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-$version.amzn2023.${package_version}.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-devel-$version.amzn2023.${package_version}.$(uname -m).rpm" "java-{{MAJOR_VERSION}}-amazon-corretto-jmods-$version.amzn2023.${package_version}.$(uname -m).rpm") \{% endif %}
&& for rpm in ${RPM_LIST[@]}; do \
curl --fail -O https://corretto.aws/downloads/resources/$(echo $version | tr '-' '.')/${rpm} \
&& rpm -K "${CORRETO_TEMP}/${rpm}" | grep -F "${CORRETO_TEMP}/${rpm}: digests signatures OK" || exit 1; \
done \
&& dnf install -y ${CORRETO_TEMP}/*.rpm \{% if jre %}
&& alternatives --install /usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto java-{{CORRETTO_VERSION}}-amazon-corretto /usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto.$(uname -m) 100 \{% endif %}
&& popd \{%if version_8 %}
&& rm -rf /usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto.$(uname -m)/lib/src.zip \{% else %}
&& rm -rf /usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto.$(uname -m)/lib/src.zip \{% endif %}
&& rm -rf ${CORRETO_TEMP} \
&& dnf clean all \{% if version_8 and not jre%}
&& rm -rf /var/cache/yum \{% endif %}
&& sed -i '/localpkg_gpgcheck=1/d' /etc/dnf/dnf.conf

ENV LANG C.UTF-8
{% if jre %}ENV JAVA_HOME=/usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto/jre{% elif version_8 %}ENV JAVA_HOME=/usr/lib/jvm/java-{{CORRETTO_VERSION}}-amazon-corretto{% else %}ENV JAVA_HOME=/usr/lib/jvm/java-{{MAJOR_VERSION}}-amazon-corretto{% endif %}