Created
February 14, 2023 04:04
-
-
Save akkinenivijay/008b5706084a9cd1bd5e1c3fbe289026 to your computer and use it in GitHub Desktop.
Docker Image with Sbt, Scala and GraalVM native-image installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM oraclelinux:9 | |
# Env variables | |
ARG GRAALVM_VERSION=22.3.1 | |
ARG GRAALVM_ARCH=linux-aarch64 | |
ARG JAVA_VERSION=java17 | |
ARG GRAALVM_PKG=https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-$GRAALVM_VERSION/graalvm-ce-$JAVA_VERSION-$GRAALVM_ARCH-$GRAALVM_VERSION.tar.gz | |
ARG SCALA_VERSION=3.2.2 | |
ARG SBT_VERSION=1.8.2 | |
ARG USER_ID | |
ENV USER_ID ${USER_ID:-1001} | |
ARG GROUP_ID | |
ENV GROUP_ID ${GROUP_ID:-1001} | |
ENV LANG=en_US.UTF-8 \ | |
JAVA_HOME=/opt/graalvm-ce-$JAVA_VERSION-$GRAALVM_VERSION | |
# Install dev libraries needed. | |
RUN dnf update -y oraclelinux-release-el9 \ | |
&& dnf --enablerepo ol9_codeready_builder install -y bzip2-devel ed gcc gcc-c++ gcc-gfortran gzip file fontconfig less libcurl-devel make openssl openssl-devel readline-devel tar glibc-langpack-en \ | |
vi which xz-devel zlib-devel findutils glibc-static libstdc++ libstdc++-devel libstdc++-static zlib-static libxcrypt-compat wget unzip gcc make glibc-devel zlib-devel\ | |
&& dnf clean all | |
RUN fc-cache -f -v | |
# Install GraalVM | |
RUN curl --fail --silent --location --retry 3 ${GRAALVM_PKG} \ | |
| gunzip | tar x -C /opt/ \ | |
# Set alternative links | |
&& mkdir -p "/usr/java" \ | |
&& ln -sfT "$JAVA_HOME" /usr/java/default \ | |
&& ln -sfT "$JAVA_HOME" /usr/java/latest \ | |
&& for bin in "$JAVA_HOME/bin/"*; do \ | |
base="$(basename "$bin")"; \ | |
[ ! -e "/usr/bin/$base" ]; \ | |
alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \ | |
done \ | |
&& gu install native-image \ | |
# Add new links for newly installed component native-image | |
&& for bin in "$JAVA_HOME/bin/"*; do \ | |
base="$(basename "$bin")"; \ | |
if [[ ! -e "/usr/bin/$base" ]]; then \ | |
alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \ | |
fi \ | |
done; | |
# Install sbt | |
RUN curl --fail --silent --location --retry 3 https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz | gunzip | tar x -C /usr/share/ && \ | |
chown -R root:root /usr/share/sbt && \ | |
chmod -R 755 /usr/share/sbt && \ | |
ln -s /usr/share/sbt/bin/sbt /usr/local/bin/sbt | |
RUN \ | |
URL=https://github.com/lampepfl/dotty/releases/download/$SCALA_VERSION/scala3-$SCALA_VERSION.tar.gz && curl --fail --silent --location --retry 3 $URL | gunzip | tar x -C /usr/share/ && \ | |
mv /usr/share/scala3-$SCALA_VERSION /usr/share/scala && \ | |
chown -R root:root /usr/share/scala && \ | |
chmod -R 755 /usr/share/scala && \ | |
ln -s /usr/share/scala/bin/* /usr/local/bin && \ | |
echo '@main def main = println(s"Scala library version ${dotty.tools.dotc.config.Properties.versionNumberString}")' > test.scala \ | |
scala -nocompdaemon test.scala && rm test.scala | |
# Add and use user sbtuser | |
RUN groupadd --gid $GROUP_ID sbtuser && useradd --gid $GROUP_ID --uid $USER_ID sbtuser --shell /bin/bash | |
USER sbtuser | |
# Switch working directory | |
WORKDIR /home/sbtuser | |
# Prepare sbt (warm cache) | |
RUN \ | |
sbt sbtVersion && \ | |
mkdir -p project && \ | |
echo "scalaVersion := \"${SCALA_VERSION}\"" > build.sbt && \ | |
echo "sbt.version=${SBT_VERSION}" > project/build.properties && \ | |
echo "// force sbt compiler-bridge download" > project/Dependencies.scala && \ | |
echo "case object Temp" > Temp.scala && \ | |
sbt compile && \ | |
rm -r project && rm build.sbt && rm Temp.scala && rm -r target | |
# Link everything into root as well | |
# This allows users of this container to choose, whether they want to run the container as sbtuser (non-root) or as root | |
USER root | |
RUN \ | |
rm -rf /tmp/..?* /tmp/.[!.]* * && \ | |
ln -s /home/sbtuser/.cache /root/.cache && \ | |
ln -s /home/sbtuser/.sbt /root/.sbt && \ | |
if [ -d "/home/sbtuser/.ivy2" ]; then ln -s /home/sbtuser/.ivy2 /root/.ivy2; fi | |
# Switch working directory back to root | |
## Users wanting to use this container as non-root should combine the two following arguments | |
## -u sbtuser | |
## -w /home/sbtuser | |
WORKDIR /root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment