GoogleCloudPlatform / cloud-builders-community

Community-contributed images for Google Cloud Build
https://cloud.google.com/cloud-build/
Apache License 2.0
1.25k stars 851 forks source link

How can I build a scala-sbt image with java 11 #396

Open MaxySpark opened 4 years ago

MaxySpark commented 4 years ago

How can I build a scala-sbt image with java 11 using this https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/scala-sbt I didn't see any java 11 image here gcr.io/cloud-builders/java

mikela commented 4 years ago

You can probably use openjdk:11-slim-buster as the BASE_IMAGE. You'll need to install Docker manually (in the Dockerfile), something like:

RUN apt-get update -qqy \
  && java -version \
  && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common sudo gcc libffi-dev make bc \
  && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
  && apt-key fingerprint 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 \
  && add-apt-repository \
        "deb [arch=amd64] https://download.docker.com/linux/debian \
        $(lsb_release -cs) \
        stable" \
  && apt-get -y update \
  && apt-get -y install docker-ce=5:19.03.8~3-0~debian-buster docker-ce-cli=5:19.03.8~3-0~debian-buster containerd.io \
&& ...

You may not need all the packages I put in the first apt install, I just clipped a long list I have there.

pawelprazak commented 3 years ago

An example of a Dockerfile that could be used for that:

ARG BASE_IMAGE=adoptopenjdk:11-jdk-hotspot

FROM docker:19.03.11 as static-docker-source
FROM ${BASE_IMAGE}

ARG SBT_VERSION=1.4.7
ARG SHA=0718a5afeac8c1464d33311f4de9617f63f9c88fbcbb5aba4e7b5aa56455f6b6
ARG BASE_URL=https://github.com/sbt/sbt/releases/download
COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker
RUN apt-get update -qqy \
  && apt-get install -qqy curl bc unzip \
  && mkdir -p /usr/share \
  && curl -fsSL -o "sbt-${SBT_VERSION}.zip" "${BASE_URL}/v${SBT_VERSION}/sbt-${SBT_VERSION}.zip" \
  && echo "${SHA}  sbt-${SBT_VERSION}.zip" | sha256sum -c - \
  && unzip -qq "sbt-${SBT_VERSION}.zip" \
  && rm -f "sbt-${SBT_VERSION}.zip" \
  && mv sbt "/usr/share/sbt-${SBT_VERSION}" \
  && ln -s "/usr/share/sbt-${SBT_VERSION}/bin/sbt" /usr/bin/sbt \
  && apt-get remove -qqy --purge curl unzip \
  && rm /var/lib/apt/lists/*_*

ENTRYPOINT ["/usr/bin/sbt"]

but not having to maintain this would be very useful long term