Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-amazon-corretto
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb authored Jul 2, 2024
2 parents 8c93d71 + d0f18fc commit e181d56
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 50 deletions.
98 changes: 55 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,80 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
scalaVersion: ['2.12.17', '2.13.10', '3.2.2']
scalaVersion: ['2.12.19', '2.13.14', '3.3.3', '3.4.2']
javaTag: [
'graalvm-ce-22.3.0-b2-java17',
'graalvm-ce-22.3.0-b2-java11',
'eclipse-temurin-jammy-19.0.1_10',
'eclipse-temurin-jammy-17.0.5_8',
'eclipse-temurin-jammy-11.0.17_8',
'eclipse-temurin-jammy-8u352-b08',
'eclipse-temurin-focal-17.0.5_8',
'eclipse-temurin-focal-11.0.17_8',
'amazoncorretto-17.0.6',
'amazoncorretto-11.0.18'
'graalvm-community-22.0.1',
'graalvm-community-21.0.2',
'graalvm-ce-22.3.3-b1-java17',
'eclipse-temurin-jammy-22_36',
'eclipse-temurin-jammy-21.0.2_13',
'eclipse-temurin-jammy-17.0.10_7',
'eclipse-temurin-alpine-22_36',
'eclipse-temurin-alpine-21.0.2_13',
'eclipse-temurin-alpine-17.0.10_7',
'amazoncorretto-21.0.3',
'amazoncorretto-17.0.11'
]
include:
# https://github.com/graalvm/container/pkgs/container/graalvm-community
- javaTag: 'graalvm-community-22.0.1'
dockerContext: 'graalvm-community'
baseImageTag: '22.0.1-ol9'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'graalvm-community-21.0.2'
dockerContext: 'graalvm-community'
baseImageTag: '21.0.2-ol9'
platforms: 'linux/amd64,linux/arm64'
# https://github.com/graalvm/container/pkgs/container/graalvm-ce
- javaTag: 'graalvm-ce-22.3.0-b2-java17'
- javaTag: 'graalvm-ce-22.3.3-b1-java17'
dockerContext: 'graalvm-ce'
baseImageTag: 'ol9-java17-22.3.0-b2'
baseImageTag: 'ol9-java17-22.3.3-b1'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'graalvm-ce-22.3.0-b2-java11'
dockerContext: 'graalvm-ce'
baseImageTag: 'ol9-java11-22.3.0-b2'
platforms: 'linux/amd64'
# https://hub.docker.com/_/eclipse-temurin/tags
- javaTag: 'eclipse-temurin-jammy-19.0.1_10'
- javaTag: 'eclipse-temurin-jammy-22_36'
dockerContext: 'eclipse-temurin'
baseImageTag: '19.0.1_10-jdk-jammy'
baseImageTag: '22_36-jdk-jammy'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'eclipse-temurin-jammy-17.0.5_8'
- javaTag: 'eclipse-temurin-jammy-21.0.2_13'
dockerContext: 'eclipse-temurin'
baseImageTag: '17.0.5_8-jdk-jammy'
baseImageTag: '21.0.2_13-jdk-jammy'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'eclipse-temurin-jammy-11.0.17_8'
- javaTag: 'eclipse-temurin-jammy-17.0.10_7'
dockerContext: 'eclipse-temurin'
baseImageTag: '11.0.17_8-jdk-jammy'
baseImageTag: '17.0.10_7-jdk-jammy'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'eclipse-temurin-jammy-8u352-b08'
# https://hub.docker.com/_/eclipse-temurin/tags?page=1&name=alpine
- javaTag: 'eclipse-temurin-alpine-22_36'
dockerContext: 'eclipse-temurin'
baseImageTag: '8u352-b08-jdk-jammy'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'eclipse-temurin-focal-17.0.5_8'
dockerfile: 'alpine.Dockerfile'
baseImageTag: '22_36-jdk-alpine'
platforms: 'linux/amd64,linux/arm64/v8'
- javaTag: 'eclipse-temurin-alpine-21.0.2_13'
dockerContext: 'eclipse-temurin'
baseImageTag: '17.0.5_8-jdk-focal'
platforms: 'linux/amd64,linux/arm64'
- javaTag: 'eclipse-temurin-focal-11.0.17_8'
dockerfile: 'alpine.Dockerfile'
baseImageTag: '21.0.2_13-jdk-alpine'
platforms: 'linux/amd64,linux/arm64/v8'
- javaTag: 'eclipse-temurin-alpine-17.0.10_7'
dockerContext: 'eclipse-temurin'
baseImageTag: '11.0.17_8-jdk-focal'
dockerfile: 'alpine.Dockerfile'
baseImageTag: '17.0.10_7-jdk-alpine'
platforms: 'linux/amd64,linux/arm64'
# https://hub.docker.com/_/amazoncorretto/tags
- javaTag: 'amazoncorretto-17.0.6'
- javaTag: 'amazoncorretto-21.0.3'
dockerContext: 'amazoncorretto'
baseImageTag: '17.0.6'
baseImageTag: '21.0.3'
platforms: 'linux/amd64'
- javaTag: 'amazoncorretto-11.0.18'
- javaTag: 'amazoncorretto-17.0.11'
dockerContext: 'amazoncorretto'
baseImageTag: '11.0.18'
baseImageTag: '17.0.11'
platforms: 'linux/amd64'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2.1.0
uses: docker/setup-qemu-action@v3.0.0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2.4.1
uses: docker/setup-buildx-action@v3.3.0
# with:
# install: true
- name: Available platforms
Expand All @@ -100,11 +110,12 @@ jobs:
TAG=sbtscala/scala-sbt:${{ matrix.javaTag }}_${{ steps.get_sbt_version.outputs.VERSION }}_${{ matrix.scalaVersion }}
echo "TAG=$TAG" >> $GITHUB_OUTPUT
- name: Build docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: ${{ matrix.dockerContext }}
no-cache: true
tags: ${{ steps.create_docker_tag.outputs.TAG }}
file: ${{ matrix.dockerContext }}/${{ matrix.dockerfile || 'Dockerfile' }}
build-args: |
BASE_IMAGE_TAG=${{ matrix.baseImageTag }}
SBT_VERSION=${{ steps.get_sbt_version.outputs.VERSION }}
Expand All @@ -125,16 +136,17 @@ jobs:
scala --version &&
sbt about
- name: Log in to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
if: github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Rebuild and push ${{ matrix.platforms }} docker images
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v4
if: github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'
uses: docker/build-push-action@v6
with:
context: ${{ matrix.dockerContext }}
file: ${{ matrix.dockerContext }}/${{ matrix.dockerfile || 'Dockerfile' }}
tags: ${{ steps.create_docker_tag.outputs.TAG }}
build-args: |
BASE_IMAGE_TAG=${{ matrix.baseImageTag }}
Expand Down
15 changes: 8 additions & 7 deletions eclipse-temurin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ ENV USER_ID ${USER_ID:-1001}
ARG GROUP_ID
ENV GROUP_ID ${GROUP_ID:-1001}

# Install dependencies
# curl for downloading sbt and scala
# git and rpm for sbt-native-packager (see https://github.com/sbt/docker-sbt/pull/114)
RUN \
apt-get update && \
apt-get install -y curl git rpm && \
rm -rf /var/lib/apt/lists/*

# Install sbt
RUN \
curl -fsL "https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz" | tar xfz - -C /usr/share && \
Expand All @@ -42,13 +50,6 @@ RUN \
esac && \
scala -nocompdaemon test.scala && rm test.scala

# Install git and rpm for sbt-native-packager (see https://github.com/sbt/docker-sbt/pull/114)
RUN \
apt-get update && \
apt-get install git -y && \
apt-get install rpm -y && \
rm -rf /var/lib/apt/lists/*

# Symlink java to have it available on sbtuser's PATH
RUN ln -s /opt/java/openjdk/bin/java /usr/local/bin/java

Expand Down
91 changes: 91 additions & 0 deletions eclipse-temurin/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Use a multi-stage build to reduce the size of the final image
ARG BASE_IMAGE_TAG
FROM eclipse-temurin:${BASE_IMAGE_TAG:-21.0.2_13-jdk-alpine} as builder

ARG SCALA_VERSION=3.4.0
ARG SBT_VERSION=1.9.9
ARG USER_ID=1001
ARG GROUP_ID=1001
ENV SCALA_HOME=/usr/share/scala

# Install dependencies
RUN apk add --no-cache --virtual=.build-dependencies wget ca-certificates bash curl bc

# Install scala
RUN \
cd "/tmp" && \
case $SCALA_VERSION in \
"3"*) URL=https://github.com/lampepfl/dotty/releases/download/$SCALA_VERSION/scala3-$SCALA_VERSION.tar.gz SCALA_DIR=scala3-$SCALA_VERSION ;; \
*) URL=https://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz SCALA_DIR=scala-$SCALA_VERSION ;; \
esac && \
curl -fsL $URL | tar xfz - -C /usr/share && \
mv /usr/share/$SCALA_DIR $SCALA_HOME && \
ln -s "$SCALA_HOME/bin/"* "/usr/bin/" && \
update-ca-certificates && \
scala -version && \
case $SCALA_VERSION in \
"3"*) echo '@main def main = println(s"Scala library version ${dotty.tools.dotc.config.Properties.versionNumberString}")' > test.scala ;; \
*) echo "println(util.Properties.versionMsg)" > test.scala ;; \
esac && \
scala -nocompdaemon test.scala && rm test.scala

# Install sbt
RUN \
curl -fsL https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz | tar xfz - -C /usr/local && \
$(mv /usr/local/sbt-launcher-packaging-$SBT_VERSION /usr/local/sbt || true) && \
ln -s /usr/local/sbt/bin/* /usr/local/bin/ && \
sbt -Dsbt.rootdir=true -batch sbtVersion && \
apk del .build-dependencies && \
rm -rf "/tmp/"* && \
rm -rf /var/cache/apk/*

# Start a new stage for the final image
FROM eclipse-temurin:${BASE_IMAGE_TAG:-21.0.2_13-jdk-alpine}

ARG SCALA_VERSION=3.4.0
ARG SBT_VERSION=1.9.9
ARG USER_ID=1001
ARG GROUP_ID=1001

RUN apk add --no-cache bash git rpm

COPY --from=builder /usr/share/scala /usr/share/scala
COPY --from=builder /usr/local/sbt /usr/local/sbt
COPY --from=builder /usr/local/bin/sbt /usr/local/bin/sbt

# Add and use user sbtuser
RUN addgroup -g $GROUP_ID sbtuser && adduser -D -u $USER_ID -G sbtuser sbtuser
USER sbtuser

# Switch working directory
WORKDIR /home/sbtuser

ENV PATH="/usr/share/scala/bin:${PATH}"

# Prepare sbt (warm cache)
RUN \
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 sbtVersion && \
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

CMD sbt
80 changes: 80 additions & 0 deletions graalvm-community/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Scala and sbt Dockerfile
#
# https://github.com/sbt/docker-sbt
#

# Pull base image
ARG BASE_IMAGE_TAG
FROM ghcr.io/graalvm/graalvm-community:${BASE_IMAGE_TAG:-21.0.1-ol9}

# Env variables
ARG SCALA_VERSION
ENV SCALA_VERSION ${SCALA_VERSION:-2.13.12}
ARG SBT_VERSION
ENV SBT_VERSION ${SBT_VERSION:-1.9.7}
ENV JAVA_OPTS -XX:+UseG1GC
ARG USER_ID
ENV USER_ID ${USER_ID:-1001}
ARG GROUP_ID
ENV GROUP_ID ${GROUP_ID:-1001}

# Install sbt
RUN \
curl -fsL "https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz" | tar xfz - -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

# Install Scala
## Piping curl directly in tar
RUN \
case $SCALA_VERSION in \
"3"*) URL=https://github.com/lampepfl/dotty/releases/download/$SCALA_VERSION/scala3-$SCALA_VERSION.tar.gz SCALA_DIR=/usr/share/scala3-$SCALA_VERSION ;; \
*) URL=https://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz SCALA_DIR=/usr/share/scala-$SCALA_VERSION ;; \
esac && \
curl -fsL $URL | tar xfz - -C /usr/share && \
mv $SCALA_DIR /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 && \
case $SCALA_VERSION in \
"3"*) echo '@main def main = println(s"Scala library version ${dotty.tools.dotc.config.Properties.versionNumberString}")' > test.scala ;; \
*) echo "println(util.Properties.versionMsg)" > test.scala ;; \
esac && \
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

CMD sbt

0 comments on commit e181d56

Please sign in to comment.