Skip to content

Commit

Permalink
Merge pull request #220 from alexander-yakushev/jdk-22
Browse files Browse the repository at this point in the history
JDK 22, take two
  • Loading branch information
cap10morgan authored Apr 10, 2024
2 parents b5c133d + f61ef22 commit 28a3175
Show file tree
Hide file tree
Showing 33 changed files with 919 additions and 31 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ 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 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`
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 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`
JDK 22 variant of the tools-deps image: `clojure:temurin-22` or `clojure:temurin-22-tools-deps`

## Linux distro

Expand Down Expand Up @@ -82,11 +83,12 @@ 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
combination is provided upstream and thus likewise for us):

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`
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`
Java 22 leiningen on Debian bookworm: `clojure:temurin-21-lein-bookworm`

### Alpine Linux

Expand All @@ -96,8 +98,8 @@ As of 2022-9-29 these are available for the linux/amd64 architecture only.

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`
Java 17 leiningen on Alpine: `clojure:temurin-17-alpine` `clojure:temurin-17-lein-alpine`
Java 21 tools-deps on Alpine: `clojure:temurin-21-tools-deps-alpine` or `clojure:temurin-21-alpine`

## Examples

Expand Down Expand Up @@ -144,4 +146,4 @@ linux/arm64).
## Tests

The `docker-clojure` build tool has a test suite that can be run via the
`bb run test` script.
`bb run test` script.
14 changes: 5 additions & 9 deletions src/docker_clojure/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
(s/nilable (s/and ::non-blank-string #(re-matches #"[\d\.]+" %))))
(s/def ::build-tools (s/map-of ::build-tool ::build-tool-version))

(s/def ::exclusions
(s/keys :opt-un [::jdk-version ::distro ::build-tool ::build-tool-version]))

(s/def ::maintainers
(s/coll-of ::non-blank-string :distinct true :into #{}))

Expand All @@ -39,7 +36,7 @@

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

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

(def base-images
"Map of JDK version to base image name(s) with :default as a fallback"
Expand Down Expand Up @@ -95,14 +92,13 @@
; issue like this.

; no more focal builds for JDK 20+
; TODO: Add ability to specify version >= 20 for these
{:jdk-version 21
{:jdk-version #(>= % 20)
:distro :ubuntu/focal}
; boot is breaking on Alpine
{:build-tool "boot"
:distro :alpine/alpine} ; boot is breaking on Alpine
:distro :alpine/alpine}
; we're no longer building boot variants for JDK 20+
; TODO: Add ability to specify version >= 20 for these
{:jdk-version 21
{:jdk-version #(>= % 20)
:build-tool "boot"}
;; commented out example
#_{:jdk-version 8
Expand Down
22 changes: 13 additions & 9 deletions src/docker_clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
[docker-clojure.log :refer [log] :as logger]
[clojure.edn :as edn]))

(defn contains-every-key-value?
"Returns true if the map `haystack` contains every key-value pair in the map
`needles`. `haystack` may contain additional keys that are not in `needles`.
Returns false if any of the keys in `needles` are missing from `haystack` or
have different values."
[haystack needles]
(defn exclude-variant?
"Returns true if the map `variant` contains every key-value pair in the map
`exclusion`. `variant` may contain additional keys that are not in
`exclusion`. Some values of `exclusion` can also be a predicate of one
argument which is then tested against the respective value from `variant`.
Returns false if any of the keys in `exclusions` are missing from `variant` or
have different values, or the predicate value returned false."
[variant exclusion]
(every? (fn [[k v]]
(= v (get haystack k)))
needles))
(if (fn? v)
(v (get variant k))
(= v (get variant k))))
exclusion))

(defn base-image-tag
[base-image jdk-version distro]
Expand All @@ -37,7 +41,7 @@
"Returns true if `variant` matches one of `exclusions` elements (meaning
`(contains-every-key-value? variant exclusion)` returns true)."
[exclusions variant]
(some (partial contains-every-key-value? variant) exclusions))
(some (partial exclude-variant? variant) exclusions))

(s/def ::variant
(s/keys :req-un [::cfg/jdk-version ::cfg/base-image ::cfg/base-image-tag
Expand Down
47 changes: 47 additions & 0 deletions target/debian-bookworm-22/lein/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:bookworm

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

ENV LEIN_VERSION=2.11.2
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 "28a1a62668c5f427b413a8677e376affaa995f023b1fcd06e2d4c98ac1df5f3e *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 9D13D9426A0814B3373CF5E3D8A8243577A7859F && \
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

COPY entrypoint /usr/local/bin/entrypoint

ENTRYPOINT ["entrypoint"]
CMD ["repl"]
21 changes: 21 additions & 0 deletions target/debian-bookworm-22/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 "$@"
32 changes: 32 additions & 0 deletions target/debian-bookworm-22/tools-deps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM debian:bookworm

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

ENV CLOJURE_VERSION=1.11.1.1435

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 "7edee5b12197a2dbe6338e672b109b18164cde84bea1f049ceceed41fc4dd10a *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

COPY entrypoint /usr/local/bin/entrypoint

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

set -eou pipefail

entrypoint=clj

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 "$@"
30 changes: 30 additions & 0 deletions target/debian-bookworm-22/tools-deps/rlwrap.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# This script works around a Docker bug that prevents rlwrap from starting
# right when a container is first started. It is intended to replace
# /usr/bin/rlwrap and also be named rlwrap but earlier in the PATH
# (e.g. /usr/local/bin).

max_tries=100 # 100 tries is ~1 second
try=0

while true; do
# see if rlwrap can start at all
output=$(/usr/bin/rlwrap true 2>&1 >/dev/null)
exit_code=$?
if [ $exit_code -gt 0 ]; then
# it didn't start
try=$((try+1))
if [ $try -gt $max_tries ]; then
# we're at max attempts so output the error and exit w/ the same code
echo "$output" >&2
exit $exit_code
else
# wait a bit and try again
sleep 0.01
fi
else
# rlwrap can start so let's run it for real
exec /usr/bin/rlwrap "$@"
fi
done
47 changes: 47 additions & 0 deletions target/debian-bookworm-slim-22/lein/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:bookworm-slim

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

ENV LEIN_VERSION=2.11.2
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 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 "28a1a62668c5f427b413a8677e376affaa995f023b1fcd06e2d4c98ac1df5f3e *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 9D13D9426A0814B3373CF5E3D8A8243577A7859F && \
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

COPY entrypoint /usr/local/bin/entrypoint

ENTRYPOINT ["entrypoint"]
CMD ["repl"]
21 changes: 21 additions & 0 deletions target/debian-bookworm-slim-22/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 "$@"
32 changes: 32 additions & 0 deletions target/debian-bookworm-slim-22/tools-deps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM debian:bookworm-slim

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

ENV CLOJURE_VERSION=1.11.1.1435

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 "7edee5b12197a2dbe6338e672b109b18164cde84bea1f049ceceed41fc4dd10a *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

COPY entrypoint /usr/local/bin/entrypoint

ENTRYPOINT ["entrypoint"]
CMD ["-M", "--repl"]
Loading

0 comments on commit 28a3175

Please sign in to comment.