164 lines
5.5 KiB
Docker
164 lines
5.5 KiB
Docker
#
|
|
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
|
|
#
|
|
# PLEASE DO NOT EDIT IT DIRECTLY.
|
|
#
|
|
|
|
FROM openjdk:26-jdk-oraclelinux9
|
|
|
|
ENV CATALINA_HOME /usr/local/tomcat
|
|
ENV PATH $CATALINA_HOME/bin:$PATH
|
|
RUN mkdir -p "$CATALINA_HOME"
|
|
WORKDIR $CATALINA_HOME
|
|
|
|
# let "Tomcat Native" live somewhere isolated
|
|
ENV TOMCAT_NATIVE_LIBDIR $CATALINA_HOME/native-jni-lib
|
|
ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOMCAT_NATIVE_LIBDIR
|
|
|
|
ENV TOMCAT_MAJOR 10
|
|
ENV TOMCAT_VERSION 10.1.46
|
|
ENV TOMCAT_SHA512 20da89fa77fb8d4dbfccf6c68383751348169542aad9d3cbcaf82011337355b9847b883cc71678fa6cc71ef3f55e8d5d7a09a53238b86011816fa989f9c4ff5e
|
|
|
|
RUN set -eux; \
|
|
\
|
|
# removing dnf after it is installed gets really hairy, so we'll just live with it (since we need it for "dnf mark")
|
|
microdnf install -y dnf; \
|
|
# a helper function to install things, but only if they aren't installed (and to mark them so "autoremove" can purge them for us)
|
|
_install_temporary() { ( set -eu +x; \
|
|
local pkg todo=''; \
|
|
for pkg; do \
|
|
if ! rpm --query "$pkg" > /dev/null 2>&1; then \
|
|
todo="$todo $pkg"; \
|
|
fi; \
|
|
done; \
|
|
if [ -n "$todo" ]; then \
|
|
set -x; \
|
|
dnf install -y $todo; \
|
|
dnf mark remove $todo; \
|
|
fi; \
|
|
) }; \
|
|
_install_temporary gzip tar; \
|
|
\
|
|
ddist() { \
|
|
local f="$1"; shift; \
|
|
local distFile="$1"; shift; \
|
|
local mvnFile="${1:-}"; \
|
|
local success=; \
|
|
local distUrl=; \
|
|
for distUrl in \
|
|
# https://apache.org/history/mirror-history.html
|
|
"https://dlcdn.apache.org/$distFile" \
|
|
# if the version is outdated, we have to pull from the archive
|
|
"https://archive.apache.org/dist/$distFile" \
|
|
# if all else fails, let's try Maven (https://www.mail-archive.com/users@tomcat.apache.org/msg134940.html; https://mvnrepository.com/artifact/org.apache.tomcat/tomcat; https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/)
|
|
${mvnFile:+"https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/$mvnFile"} \
|
|
; do \
|
|
if curl -fL -o "$f" "$distUrl" && [ -s "$f" ]; then \
|
|
success=1; \
|
|
break; \
|
|
fi; \
|
|
done; \
|
|
[ -n "$success" ]; \
|
|
}; \
|
|
\
|
|
ddist 'tomcat.tar.gz' "tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz" "$TOMCAT_VERSION/tomcat-$TOMCAT_VERSION.tar.gz"; \
|
|
echo "$TOMCAT_SHA512 *tomcat.tar.gz" | sha512sum --strict --check -; \
|
|
ddist 'tomcat.tar.gz.asc' "tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz.asc" "$TOMCAT_VERSION/tomcat-$TOMCAT_VERSION.tar.gz.asc"; \
|
|
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
|
|
curl -fL -o upstream-KEYS 'https://www.apache.org/dist/tomcat/tomcat-10/KEYS'; \
|
|
gpg --batch --import upstream-KEYS; \
|
|
# filter upstream KEYS file to *just* known/precomputed fingerprints
|
|
printf '' > filtered-KEYS; \
|
|
# see https://www.apache.org/dist/tomcat/tomcat-10/KEYS
|
|
for key in \
|
|
'A9C5DF4D22E99998D9875A5110C01C5A2F6059E7' \
|
|
'5C3C5F3E314C866292F359A8F3AD5C94A67F707E' \
|
|
; do \
|
|
gpg --batch --fingerprint "$key"; \
|
|
gpg --batch --export --armor "$key" >> filtered-KEYS; \
|
|
done; \
|
|
gpgconf --kill all; \
|
|
rm -rf "$GNUPGHOME"; \
|
|
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
|
|
gpg --batch --import filtered-KEYS; \
|
|
gpg --batch --verify tomcat.tar.gz.asc tomcat.tar.gz; \
|
|
tar -xf tomcat.tar.gz --strip-components=1; \
|
|
rm bin/*.bat; \
|
|
rm tomcat.tar.gz*; \
|
|
gpgconf --kill all; \
|
|
rm -rf "$GNUPGHOME"; \
|
|
\
|
|
# https://tomcat.apache.org/tomcat-9.0-doc/security-howto.html#Default_web_applications
|
|
mv webapps webapps.dist; \
|
|
mkdir webapps; \
|
|
# we don't delete them completely because they're frankly a pain to get back for users who do want them, and they're generally tiny (~7MB)
|
|
\
|
|
nativeBuildDir="$(mktemp -d)"; \
|
|
tar -xf bin/tomcat-native.tar.gz -C "$nativeBuildDir" --strip-components=1; \
|
|
_install_temporary \
|
|
apr-devel \
|
|
findutils \
|
|
gcc \
|
|
make \
|
|
openssl-devel \
|
|
# "gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory"
|
|
redhat-rpm-config \
|
|
; \
|
|
( \
|
|
export CATALINA_HOME="$PWD"; \
|
|
cd "$nativeBuildDir/native"; \
|
|
aprConfig="$(command -v apr-1-config)"; \
|
|
./configure \
|
|
--libdir="$TOMCAT_NATIVE_LIBDIR" \
|
|
--prefix="$CATALINA_HOME" \
|
|
--with-apr="$aprConfig" \
|
|
--with-java-home="$JAVA_HOME" \
|
|
; \
|
|
nproc="$(nproc)"; \
|
|
make -j "$nproc"; \
|
|
make install; \
|
|
); \
|
|
rm -rf "$nativeBuildDir"; \
|
|
rm bin/tomcat-native.tar.gz; \
|
|
\
|
|
# sh removes env vars it doesn't support (ones with periods)
|
|
# https://github.com/docker-library/tomcat/issues/77
|
|
find ./bin/ -name '*.sh' -exec sed -ri 's|^#!/bin/sh$|#!/usr/bin/env bash|' '{}' +; \
|
|
\
|
|
# fix permissions (especially for running as non-root)
|
|
# https://github.com/docker-library/tomcat/issues/35
|
|
chmod -R +rX .; \
|
|
chmod 1777 logs temp work; \
|
|
\
|
|
# mark any explicit dependencies as manually installed
|
|
find "$TOMCAT_NATIVE_LIBDIR" -type f -executable -exec ldd '{}' ';' \
|
|
| awk '/=>/ && $(NF-1) != "=>" { print $(NF-1) }' \
|
|
| xargs -rt readlink -e \
|
|
| sort -u \
|
|
| xargs -rt rpm --query --whatprovides \
|
|
| sort -u \
|
|
| tee "$TOMCAT_NATIVE_LIBDIR/.dependencies.txt" \
|
|
| xargs -r dnf mark install \
|
|
; \
|
|
\
|
|
# clean up anything added temporarily and not later marked as necessary
|
|
dnf autoremove -y; \
|
|
dnf clean all; \
|
|
rm -rf /var/cache/dnf; \
|
|
\
|
|
# smoke test
|
|
catalina.sh version
|
|
|
|
# verify Tomcat Native is working properly
|
|
RUN set -eux; \
|
|
nativeLines="$(catalina.sh configtest 2>&1)"; \
|
|
nativeLines="$(echo "$nativeLines" | grep 'Apache Tomcat Native')"; \
|
|
nativeLines="$(echo "$nativeLines" | sort -u)"; \
|
|
if ! echo "$nativeLines" | grep -E 'INFO: Loaded( APR based)? Apache Tomcat Native library' >&2; then \
|
|
echo >&2 "$nativeLines"; \
|
|
exit 1; \
|
|
fi
|
|
|
|
EXPOSE 8080
|
|
CMD ["catalina.sh", "run"]
|