Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update dockerfile to jdk8 and cleanup build #390

Merged
merged 2 commits into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ _site
target
support
vendor
project/target
39 changes: 14 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
FROM java:7
FROM java:8-jdk
MAINTAINER Gabe Conradi <[email protected]>

RUN apt-get update && apt-get install -y zip unzip && rm -r /var/lib/apt/lists/*

RUN useradd -Ur -d /opt/collins collins
RUN for dir in /build /build/collins /var/log/collins /var/run/collins; do mkdir $dir; chown collins $dir; done
ENV ACTIVATOR_VERSION 1.3.7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a little off to have this env var sitting around, since it's not used for anything except building the container. What about moving it to the top of the RUN section, rather than having it as a global ENV?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM


WORKDIR /build
# get Play, Collins, build, and deploy it to /opt/collins
COPY . /build/collins
RUN wget -q http://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6-minimal.zip -O /build/typesafe-activator-1.3.6-minimal.zip && \
unzip -q ./typesafe-activator-1.3.6-minimal.zip && \
RUN cd /build && \
wget -q http://downloads.typesafe.com/typesafe-activator/$ACTIVATOR_VERSION/typesafe-activator-$ACTIVATOR_VERSION-minimal.zip -O /build/activator.zip && \
unzip -q ./activator.zip && \
cd collins && \
java -version 2>&1 && \
PLAY_CMD=/build/activator-1.3.6-minimal/activator ./scripts/package.sh && \
PLAY_CMD=/build/activator-$ACTIVATOR_VERSION-minimal/activator ./scripts/package.sh && \
unzip -q /build/collins/target/collins.zip -d /opt/ && \
cd / && rm -rf /build && \
chown -R collins /opt/collins
cd / && rm -rf /build

# Add in all the default configs we want in this build so collins can run.
# Override /opt/collins/conf with your own configs with -v
COPY conf/docker/validations.conf /opt/collins/conf/validations.conf
COPY conf/docker/authentication.conf /opt/collins/conf/authentication.conf
COPY conf/docker/database.conf /opt/collins/conf/database.conf
COPY conf/docker/production.conf /opt/collins/conf/production.conf
COPY conf/docker/users.conf /opt/collins/conf/users.conf
COPY conf/docker/profiles.yaml /opt/collins/conf/profiles.yaml
COPY conf/docker/permissions.yaml /opt/collins/conf/permissions.yaml
COPY conf/docker/logger.xml /opt/collins/conf/logger.xml
WORKDIR /opt/collins

RUN chown -R collins /opt/collins
# Add in all the default configs we want in this build so collins can run.
# You probably will want to override these configs in production
COPY conf/docker conf/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to copy or mount this to allow easy updating of the configs (e.g. via puppet) without rebuilding the container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configs can be overridden at runtime. This just places the default configs in the correct place to enable config-less startup.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the best practice to make the user-configurable storage a VOLUME ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For storage, yes. These are just configs though (i.e. the app isnt persisting any state into this directory). The user could totally allocate a volume for /opt/collins/conf at runtime if they wanted (but collins would not start up without its production config present)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that a set of default configs should be baked into the image.

It would be nice to expose the user-serviceable configs by adding VOLUME /opt/collins/conf in the Dockerfile, as described at https://docs.docker.com/engine/articles/dockerfile_best-practices/#volume

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will not work. That will tell docker to allocate a volume at runtime always, making our default configs inaccessible (shadowed). This works as it is written, and will allow users to provide their own configs as necessary (via -v flags)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would copy the files into the volume. But since it doesn't work like that, working code is good. 👍


WORKDIR /opt/collins
USER collins
EXPOSE 9000
EXPOSE 3333
CMD ["/usr/bin/java","-server","-Dconfig.file=/opt/collins/conf/production.conf","-Dhttp.port=9000","-Dlogger.file=/opt/collins/conf/logger.xml","-Dnetworkaddress.cache.ttl=1","-Dnetworkaddress.cache.negative.ttl=1","-Dcom.sun.management.jmxremote","-Dcom.sun.management.jmxremote.port=3333","-Dcom.sun.management.jmxremote.authenticate=false","-Dcom.sun.management.jmxremote.ssl=false","-XX:MaxPermSize=384m","-XX:+CMSClassUnloadingEnabled","-XX:+PrintGCDetails","-XX:+PrintGCTimeStamps","-XX:+PrintGCDateStamps","-XX:+PrintTenuringDistribution","-XX:+PrintHeapAtGC","-Xloggc:/var/log/collins/gc.log","-XX:+UseGCLogFileRotation","-cp","/opt/collins/lib/*","play.core.server.NettyServer","/opt/collins"]
# expose HTTP, JMX
EXPOSE 9000 3333
CMD ["/usr/bin/java","-server","-Dconfig.file=/opt/collins/conf/production.conf","-Dhttp.port=9000","-Dlogger.file=/opt/collins/conf/logger.xml","-Dnetworkaddress.cache.ttl=1","-Dnetworkaddress.cache.negative.ttl=1","-Dcom.sun.management.jmxremote","-Dcom.sun.management.jmxremote.port=3333","-Dcom.sun.management.jmxremote.authenticate=false","-Dcom.sun.management.jmxremote.ssl=false","-XX:MaxPermSize=384m","-XX:+CMSClassUnloadingEnabled","-cp","/opt/collins/lib/*","play.core.server.NettyServer","/opt/collins"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this extremely long line be split to multiple lines please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually. Dockerfile syntax requires it is on one line :(


2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ parallelExecution in IntegrationTest := false

scalaVersion := "2.11.7"

autoScalaLibrary := true

scalacOptions ++= Seq("-deprecation","-unchecked", "-feature")

scalacOptions += "-feature"
Expand Down
3 changes: 0 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ object ApplicationBuild extends Build {
val appName = "collins"
val appVersion = "2.0-SNAPSHOT"

val appDependencies = Seq()

val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
version := appVersion,
libraryDependencies ++= appDependencies,
TwirlKeys.templateImports ++= Seq(
"collins.models._",
"collins.models.shared._",
Expand Down