Reputation: 2689
in scala app, Im using Dockerfile ( I need Dockerfile instead of native packager to automated builds in hub docker ).
FROM openjdk:8-jre-alpine
ENV SBT_VERSION 0.13.15
RUN apk add --no-cache bash curl openrc git && \
curl -sL "http://dl.bintray.com/sbt/native-packages/sbt/$SBT_VERSION/sbt-$SBT_VERSION.tgz" | gunzip | tar -x -C /usr/local && \
ln -s /usr/local/sbt/bin/sbt /usr/local/bin/sbt && \
chmod 0755 /usr/local/bin/sbt && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/community docker
RUN rc-update add docker
RUN sbt sbtVersion
COPY . /tmp
WORKDIR /tmp
RUN sbt stage
RUN chmod +x runAfterTime.sh
ENTRYPOINT [ "./runAfterTime.sh" ]
but it takes so much time.. downloading half of internet on each change. Can this be easily speed up ?
EDIT: Im using also "hackaround" , dockerfile:
FROM openjdk:8-jre-alpine
ENV SBT_VERSION 0.13.15
RUN apk add --no-cache bash curl openrc git && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/community docker
RUN rc-update add docker
COPY target /tmp/target
COPY runAfterTime.sh /tmp
WORKDIR /tmp
RUN chmod +x runAfterTime.sh
ENTRYPOINT [ "./runAfterTime.sh" ]
So build is done from machine, using sbt cache, this way I can build image faster and push to docker hub, but would be nice to speed it up somehow, use sbt cache..
Upvotes: 3
Views: 3127
Reputation: 2689
Ok I found easy solution for this. So first is to download all deps right ? To cache current stage. This we can achieve by just adding build.sbt and plugins.sbt, run sbt reload & update. And then add src files, so changes in src wont run everything from beginning. Here is done dockerfile:
FROM openjdk:8-jre-alpine
ENV SBT_VERSION 0.13.15
RUN apk add --no-cache bash curl openrc git && \
curl -sL "http://dl.bintray.com/sbt/native-packages/sbt/$SBT_VERSION/sbt-$SBT_VERSION.tgz" | gunzip | tar -x -C /usr/local && \
ln -s /usr/local/sbt/bin/sbt /usr/local/bin/sbt && \
chmod 0755 /usr/local/bin/sbt && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main --repository http://dl-cdn.alpinelinux.org/alpine/edge/community docker
RUN rc-update add docker
ADD build.sbt /tmp
RUN mkdir -p /tmp/project
ADD project/Commons.scala /tmp/project
ADD project/plugins.sbt /tmp/project
ADD project/build.properties /tmp/project
WORKDIR /tmp
RUN sbt reload
RUN sbt update
ADD src /tmp
ADD runAfterTime.sh /tmp
RUN sbt stage
RUN chmod +x runAfterTime.sh
ENTRYPOINT [ "./runAfterTime.sh" ]
Upvotes: 2