Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Last active May 22, 2020 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunojppb/f24c311d583f4f6c9e89cde4a54c73f6 to your computer and use it in GitHub Desktop.
Save brunojppb/f24c311d583f4f6c9e89cde4a54c73f6 to your computer and use it in GitHub Desktop.
Building a docker image with SBT and Node for Play Framework projects

Create a Dockerfile for your SBT image with the following content (installing SBT 1.3.10)

FROM openjdk:8-alpine
LABEL maintainer="contact@bpaulino.com"

RUN apk update
RUN apk add postgresql-client

# Optional: Install Scala
# ENV SCALA_VERSION=2.12.8 \
# SCALA_HOME=/usr/share/scala
# NOTE: bash is used by scala/scalac scripts, and it cannot be easily replaced with ash.
# Optional Scala lang installed directly
# RUN apk add --no-cache --virtual=.build-dependencies wget ca-certificates && \
#    apk add --no-cache bash curl jq && \
#    cd "/tmp" && \
#    wget --no-verbose "https://downloads.typesafe.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" && \
#    tar xzf "scala-${SCALA_VERSION}.tgz" && \
#    mkdir "${SCALA_HOME}" && \
#    rm "/tmp/scala-${SCALA_VERSION}/bin/"*.bat && \
#    mv "/tmp/scala-${SCALA_VERSION}/bin" "/tmp/scala-${SCALA_VERSION}/lib" "${SCALA_HOME}" && \
#    ln -s "${SCALA_HOME}/bin/"* "/usr/bin/" && \
#    apk del .build-dependencies && \
#    rm -rf "/tmp/"*

RUN apk add --no-cache --virtual=.build-dependencies wget ca-certificates && apk add --no-cache bash curl jq

# Install SBT
RUN export PATH="/usr/local/sbt/bin:$PATH" \
  &&  apk update \
  && apk add ca-certificates wget tar && mkdir -p "/usr/local/sbt" \
  && wget -qO - --no-check-certificate "https://piccolo.link/sbt-1.3.10.tgz" | tar xz -C /usr/local/sbt --strip-components=1 \
  && sbt sbtVersion

ENV PATH "/usr/local/sbt/bin:$PATH"

Now build the image:

docker build - < Dockerfile.yml

If you need Node.js to build a frontend project, combine the previous image with the following one:

FROM brunojppb/scala-sbt:1.3.10
LABEL maintainer="contact@bpaulino.com"

ARG NODE_VER=14.3.0
ARG NPM_VER=6

RUN apk -U add curl git make gcc g++ python linux-headers paxctl libgcc libstdc++ binutils-gold ca-certificates \
  && cd /tmp \
  && curl --silent --ssl https://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER.tar.gz | tar zxf - \
  && cd node-v$NODE_VER \
  && ./configure --prefix=/usr \
  && make -j4 && make install \
  && paxctl -cm /usr/bin/node \
  && npm install -g npm@$NPM_VER \
  && find /usr/lib/node_modules/npm -name test -o -name .bin -type d \
  | xargs rm -rf \
  && apk del \
  curl \
  git \
  make \
  gcc \
  g++ \
  python \
  linux-headers \
  paxctl \
  grep \
  binutils-gold \
  ca-certificates \
  && rm -rf \
  /tmp/* \
  /var/cache/apk/* \
  /root/.npm \
  /root/.node-gyp \
  /usr/lib/node_modules/npm/man \
  /usr/lib/node_modules/npm/doc \
  /usr/lib/node_modules/npm/html \
  /usr/share/man

CMD ["node", "-v"]

Now tag the image

docker tag <IMAGE_ID_FROM_PREVIOUS_BUILD> brunojppb/sbt-node:14.3.0
docker push brunojppb/sbt-node:14.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment