Skip to content

Commit

Permalink
Merge pull request #209 from Quantisan/feature/jdk-21-variants
Browse files Browse the repository at this point in the history
Feature: JDK 21 variants
  • Loading branch information
cap10morgan authored Oct 12, 2023
2 parents 8af52eb + 4c682ec commit 6409ad6
Show file tree
Hide file tree
Showing 89 changed files with 2,469 additions and 39 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ by this change.
## JDK versions

Java follows a release cadence of every 6 months with an LTS (long-term support)
release every 3 years. As of 2019-9-25, our images will default to the latest
LTS release of OpenJDK (currently 17). But we also now provide the ability to
release every 2-3 years. As of 2019-9-25, our images will default to the latest
LTS release of OpenJDK (currently 21). But we also now provide the ability to
specify which version of Java you'd like via Docker tags:

JDK 1.8 tools-deps image: `clojure:temurin-8-tools-deps`
JDK 11 variant of the tools-deps image: `clojure:temurin-11-tools-deps` or `clojure:temurin-11`
JDK 17 variant of the tools-deps image: `clojure:tools-deps` or `clojure:temurin-17` or `clojure:temurin-17-tools-deps`
JDK 17 with boot 2.8.3: `clojure:temurin-17-boot-2.8.3`
JDK 20 with the latest version of lein: `clojure:temurin-20-lein`
JDK 21 variant of the tools-deps image: `clojure:tools-deps` or `clojure:temurin-21` or `clojure:temurin-21-tools-deps`

## Linux distro

Expand All @@ -64,10 +64,19 @@ want a different base image than what they provide). It is recommended to use
the Debian variants unless you have a need to use Ubuntu or stick closer to the
official upstream images.

As of 2022-9-29 the default distro is Ubuntu jammy in order to maintain
backwards compatibility. But you should not interpret this default as a
recommendation. Use Debian bullseye or bullseye-slim variants unless you have
a good, specific reason not to. There are fewer dead ends that way.
As of 2023-10-12 the default distro is Debian bookworm (12) in JDK 21+ images
and Ubuntu jammy (22.04) in JDK <=20 images in order to maintain backwards
compatibility. But we recommend you use Debian variants on any JDK version
unless you have a good, specific reason not to. There are fewer dead ends that
way.

### debian-slim

For a lighter-weight image, try the Debian `-slim` variants. You can just put
`bookworm-slim` (for Debian 12) or `bullseye-slim` (for Debian 11) in the distro
slot of your Docker tag to get those.

### Examples

You can specify which distro & version you'd like by appending it to the end of
your Docker tag as in the following examples (but note that not every
Expand All @@ -77,6 +86,7 @@ Java 8 leiningen on Debian bullseye-slim: `clojure:temurin-8-lein-bullseye-slim`
Java 11 leiningen on Debian bullseye: `clojure:temurin-11-lein-bullseye`
Java 17 tools-deps on Ubuntu focal: `clojure:tools-deps` or `clojure:temurin-17` or `clojure:temurin-17-tools-deps` or `clojure:temurin-17-tools-deps-focal`
Java 17 tools-deps on Debian bullseye-slim: `clojure:bullseye-slim` or `clojure:tools-deps-bullseye-slim` or `clojure:temurin-17-bullseye-slim` or `clojure:temurin-17-tools-deps-bullseye-slim`
Java 21 tools-deps on Debian bookworm: `clojure:tools-deps` or `clojure:temurin-21-tools-deps` or `clojure:temurin-21-bookworm`

### Alpine Linux

Expand All @@ -89,15 +99,6 @@ Some example tags:
Java 17 leiningen on Alpine: `clojure:temurin-17-alpine` `clojure:temurin-17-lein-alpine`
Java 20 tools-deps on Alpine: `clojure:temurin-20-tools-deps-alpine` or `clojure:temurin-20-alpine`

### `clojure:slim-buster` / `clojure:slim-bullseye`

These images are based on the Debian buster distribution but have fewer
packages installed and are thus a bit smaller than the `buster` or `bullseye`
images. Their use is recommended.

Note that as of 2022-9-29 there are no `slim-focal` images published by the
eclipse-temurin maintainers, so the slim option there is the `alpine` variant.

## Examples

### Interactive Shell
Expand Down
32 changes: 25 additions & 7 deletions src/docker_clojure/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@

(def git-repo "https://github.com/Quantisan/docker-clojure.git")

(def jdk-versions #{8 11 17 20})
(def jdk-versions #{8 11 17 20 21})

(def base-images
"Map of JDK version to base image name(s) with :default as a fallback"
{:default ["eclipse-temurin" "debian"]})
{8 ["eclipse-temurin" "debian"]
11 ["eclipse-temurin" "debian"]
17 ["eclipse-temurin" "debian"]
20 ["eclipse-temurin" "debian"]
:default ["debian" "eclipse-temurin"]})

;; The default JDK version to use for tags that don't specify one; usually the latest LTS release
(def default-jdk-version 17)
(def default-jdk-version 21)

(def distros
"Map of base image name to set of distro tags to use, namespaced by Linux
distro type. :default key is a fallback for base images not o/w specified."
{:default #{:alpine/alpine :ubuntu/focal :ubuntu/jammy}
"debian" #{:debian-slim/bullseye-slim :debian/bullseye}})
"debian" #{:debian-slim/bookworm-slim :debian/bookworm
:debian-slim/bullseye-slim :debian/bullseye}})

(def default-architectures
#{"amd64" "arm64v8"})
Expand All @@ -65,7 +70,11 @@
(def default-distros
"The default distro to use for tags that don't specify one, keyed by jdk-version.
:default is a fallback for jdk versions not o/w specified."
{:default :ubuntu/jammy})
{8 :ubuntu/jammy
11 :ubuntu/jammy
17 :ubuntu/jammy
20 :ubuntu/jammy
:default :debian/bookworm})

(def build-tools
{"lein" "2.10.0"
Expand All @@ -86,12 +95,21 @@
; download boot as of 2022-11-17. Probably would deprecate one or both of
; JDK 8 and/or boot variants before spending much time working around an
; issue like this.

; no more focal builds for JDK 20+
; TODO: Add ability to specify version >= 20 for these
{:jdk-version 20
:distro :ubuntu/focal} ; no more focal builds for JDK 20+
:distro :ubuntu/focal}
{:jdk-version 21
:distro :ubuntu/focal}
{:build-tool "boot"
:distro :alpine/alpine} ; boot is breaking on Alpine
; we're no longer building boot variants for JDK 20+
; TODO: Add ability to specify version >= 20 for these
{:jdk-version 20
:build-tool "boot"} ; we're no longer building boot variants for JDK 20+
:build-tool "boot"}
{:jdk-version 21
:build-tool "boot"}
;; commented out example
#_{:jdk-version 8
:distro :alpine/alpine}})
Expand Down
15 changes: 10 additions & 5 deletions src/docker_clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
(= v (get haystack k)))
needles))

(defn base-image-tag [base-image jdk-version distro]
(defn base-image-tag
[base-image jdk-version distro]
(str base-image ":"
(case base-image
"eclipse-temurin" (str jdk-version "-jdk-")
Expand All @@ -44,7 +45,8 @@
::cfg/maintainer ::cfg/docker-tag]
:opt-un [::cfg/build-tool-versions ::cfg/architectures]))

(defn assoc-if [m pred k v]
(defn assoc-if
[m pred k v]
(if (pred)
(assoc m k v)
m))
Expand Down Expand Up @@ -118,7 +120,8 @@
(get-or-default cfg/default-distros cfg/default-jdk-version)
[::all]))

(defn image-variant-combinations [base-images jdk-versions distros build-tools]
(defn image-variant-combinations
[base-images jdk-versions distros build-tools]
(reduce
(fn [variants jdk-version]
(concat
Expand All @@ -136,7 +139,8 @@
acc'))))))
#{} jdk-versions))

(defn image-variants [base-images jdk-versions distros build-tools]
(defn image-variants
[base-images jdk-versions distros build-tools]
(into #{}
(comp
(map variant-map)
Expand All @@ -153,7 +157,8 @@
(Thread/sleep rand-time)
(apply f args)))

(defn build-images [parallelization installer-hashes variants]
(defn build-images
[parallelization installer-hashes variants]
(log "Building images" parallelization "at a time")
(let [variants-ch (to-chan! variants)
builds-ch (chan parallelization)]
Expand Down
33 changes: 33 additions & 0 deletions target/debian-bookworm-11/boot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM debian:bookworm

ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:11 $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"

ENV BOOT_VERSION=2.8.3
ENV BOOT_INSTALL=/usr/local/bin/

WORKDIR /tmp

# NOTE: BOOT_VERSION tells the boot.sh script which version of boot to install
# on its first run. We always download the latest version of boot.sh because
# it is just the installer script.
RUN \
apt-get update && \
apt-get install -y make wget && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p $BOOT_INSTALL && \
wget -q https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh && \
echo "Comparing installer checksum..." && \
sha256sum boot.sh && \
echo "0ccd697f2027e7e1cd3be3d62721057cbc841585740d0aaa9fbb485d7b1f17c3 *boot.sh" | sha256sum -c - && \
mv boot.sh $BOOT_INSTALL/boot && \
chmod 0755 $BOOT_INSTALL/boot && \
apt-get purge -y --auto-remove wget

ENV PATH=$PATH:$BOOT_INSTALL
ENV BOOT_AS_ROOT=yes

RUN boot

CMD ["boot", "repl"]
21 changes: 21 additions & 0 deletions target/debian-bookworm-11/boot/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eou pipefail

entrypoint=boot

cmd=${1:-}

# check if the first arg starts with a hyphen
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
exec "${entrypoint}" "$@"
fi

if [[ -n "${cmd}" ]]; then
# see if help for the subcommand is successful
if "${entrypoint}" "${cmd}" --help >/dev/null 2>&1; then
exec "${entrypoint}" "$@"
fi
fi

exec "$@"
44 changes: 44 additions & 0 deletions target/debian-bookworm-11/lein/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM debian:bookworm

ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:11 $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"

ENV LEIN_VERSION=2.10.0
ENV LEIN_INSTALL=/usr/local/bin/

WORKDIR /tmp

# Download the whole repo as an archive
RUN set -eux; \
apt-get update && \
apt-get install -y make gnupg wget && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p $LEIN_INSTALL && \
wget -q https://codeberg.org/leiningen/leiningen/raw/tag/$LEIN_VERSION/bin/lein-pkg && \
echo "Comparing lein-pkg checksum ..." && \
sha256sum lein-pkg && \
echo "b1757ce941e4cbf15cbf649b7b4f413365e612da892d22841ec1728391bb66af *lein-pkg" | sha256sum -c - && \
mv lein-pkg $LEIN_INSTALL/lein && \
chmod 0755 $LEIN_INSTALL/lein && \
export GNUPGHOME="$(mktemp -d)" && \
export FILENAME_EXT=jar && \
gpg --batch --keyserver hkps://keyserver.ubuntu.com --recv-keys 6A2D483DB59437EBB97D09B1040193357D0606ED && \
wget -q https://codeberg.org/leiningen/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT && \
wget -q https://codeberg.org/leiningen/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT.asc && \
echo "Verifying file PGP signature..." && \
gpg --batch --verify leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT.asc leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT && \
gpgconf --kill all && \
rm -rf "$GNUPGHOME" leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT.asc && \
mkdir -p /usr/share/java && \
mv leiningen-$LEIN_VERSION-standalone.$FILENAME_EXT /usr/share/java/leiningen-$LEIN_VERSION-standalone.jar && \
apt-get purge -y --auto-remove gnupg wget

ENV PATH=$PATH:$LEIN_INSTALL
ENV LEIN_ROOT 1

# Install clojure 1.11.1 so users don't have to download it every time
RUN echo '(defproject dummy "" :dependencies [[org.clojure/clojure "1.11.1"]])' > project.clj \
&& lein deps && rm project.clj

CMD ["lein", "repl"]
21 changes: 21 additions & 0 deletions target/debian-bookworm-11/lein/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eou pipefail

entrypoint=lein

cmd=${1:-}

# check if the first arg starts with a hyphen
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
exec "${entrypoint}" "$@"
fi

if [[ -n "${cmd}" ]]; then
# see if help for the subcommand is successful
if "${entrypoint}" "${cmd}" --help >/dev/null 2>&1; then
exec "${entrypoint}" "$@"
fi
fi

exec "$@"
29 changes: 29 additions & 0 deletions target/debian-bookworm-11/tools-deps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM debian:bookworm

ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:11 $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"

ENV CLOJURE_VERSION=1.11.1.1413

WORKDIR /tmp

RUN \
apt-get update && \
apt-get install -y curl make git rlwrap wget && \
rm -rf /var/lib/apt/lists/* && \
wget https://download.clojure.org/install/linux-install-$CLOJURE_VERSION.sh && \
sha256sum linux-install-$CLOJURE_VERSION.sh && \
echo "ad9aa1e99c59a4f7eb66450914fbec543337d9fada60dd9d34eec7fe18ae4965 *linux-install-$CLOJURE_VERSION.sh" | sha256sum -c - && \
chmod +x linux-install-$CLOJURE_VERSION.sh && \
./linux-install-$CLOJURE_VERSION.sh && \
rm linux-install-$CLOJURE_VERSION.sh && \
clojure -e "(clojure-version)" && \
apt-get purge -y --auto-remove curl wget

# Docker bug makes rlwrap crash w/o short sleep first
# Bug: https://github.com/moby/moby/issues/28009
# As of 2021-09-10 this bug still exists, despite that issue being closed
COPY rlwrap.retry /usr/local/bin/rlwrap

CMD ["clj"]
36 changes: 36 additions & 0 deletions target/debian-bookworm-17/boot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM debian:bookworm

ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:17 $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"

ENV BOOT_VERSION=2.8.3
ENV BOOT_INSTALL=/usr/local/bin/

WORKDIR /tmp

# NOTE: BOOT_VERSION tells the boot.sh script which version of boot to install
# on its first run. We always download the latest version of boot.sh because
# it is just the installer script.
RUN \
apt-get update && \
apt-get install -y make wget && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p $BOOT_INSTALL && \
wget -q https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh && \
echo "Comparing installer checksum..." && \
sha256sum boot.sh && \
echo "0ccd697f2027e7e1cd3be3d62721057cbc841585740d0aaa9fbb485d7b1f17c3 *boot.sh" | sha256sum -c - && \
mv boot.sh $BOOT_INSTALL/boot && \
chmod 0755 $BOOT_INSTALL/boot && \
apt-get purge -y --auto-remove wget

ENV PATH=$PATH:$BOOT_INSTALL
ENV BOOT_AS_ROOT=yes

RUN boot

COPY entrypoint /usr/local/bin/entrypoint

ENTRYPOINT ["entrypoint"]
CMD ["repl"]
21 changes: 21 additions & 0 deletions target/debian-bookworm-17/boot/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eou pipefail

entrypoint=boot

cmd=${1:-}

# check if the first arg starts with a hyphen
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
exec "${entrypoint}" "$@"
fi

if [[ -n "${cmd}" ]]; then
# see if help for the subcommand is successful
if "${entrypoint}" "${cmd}" --help >/dev/null 2>&1; then
exec "${entrypoint}" "$@"
fi
fi

exec "$@"
Loading

0 comments on commit 6409ad6

Please sign in to comment.