From 62e8d65587e17929edffc55a524581791e091c17 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Tue, 28 Aug 2018 23:41:31 +0200 Subject: [PATCH 1/2] Some work on Docker based on what Phase made on his PR The Ore container may have to be manually configured for some stuff --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 38 +++++++++++++++++++++++--------------- build.sbt | 3 +++ docker-compose.yml | 8 ++++---- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/.dockerignore b/.dockerignore index 45117aa99..988ddbf38 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,19 @@ +/* + +!app/ + +!conf/ # This is created in the Dockerfile conf/application.conf +!OreTestPlugin/ + +!project/ +project/target/ +project/project/ + +!public/ + +!scripts/ + +!build.sbt diff --git a/Dockerfile b/Dockerfile index 63f51af79..20671a00a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,31 @@ FROM openjdk:8-jdk-alpine -MAINTAINER Jadon Fowler +LABEL maintainer="Jadon Fowler " -# Install Activator -RUN apk update -RUN apk add curl unzip bash postgresql -RUN curl -O http://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip -RUN unzip typesafe-activator-1.3.6.zip -d / && rm typesafe-activator-1.3.6.zip && chmod a+x /activator-dist-1.3.6/activator -ENV PATH $PATH:/activator-dist-1.3.6 +# Temporary build folder for the 'stage' task +WORKDIR /home/ore/build +ADD . ./ +ADD conf/application.conf.template conf/application.conf -# Copy Ore -RUN mkdir -p /home/play/ore/ -WORKDIR /home/play/ore/ -ADD . /home/play/ore/ +ENV SBT_VERSION=0.13.9 \ + SBT_HOME=/usr/local/sbt \ + JDBC_DATABASE_URL=jdbc:postgresql://db/ore \ + SPONGE_AUTH_URL=http://spongeauth:8000 \ + APPLICATION_SECRET="some_secret" + +ENV PATH=${PATH}:${SBT_HOME}/bin + +RUN apk add --virtual --no-cache curl ca-certificates bash && \ + curl -sL "http://dl.bintray.com/sbt/native-packages/sbt/$SBT_VERSION/sbt-$SBT_VERSION.tgz" | gunzip | tar -x -C /usr/local && \ + sbt stage && \ + apk del curl + +WORKDIR /home/ore/prod/bin/ + +RUN cp -r /home/ore/build/target/universal/stage/* /home/ore/prod/ && \ + rm -rf /home/ore/build/ # Ore runs on port 9000 -# 8888 is the Activator UI EXPOSE 9000 -RUN cp conf/application.conf.template conf/application.conf - -CMD ["/home/play/ore/docker.sh"] +CMD ["./ore"] diff --git a/build.sbt b/build.sbt index d6d2e9d8a..60c4b9f79 100755 --- a/build.sbt +++ b/build.sbt @@ -11,6 +11,9 @@ resolvers ++= Seq( "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/" ) +sources in (Compile, doc) := Seq.empty +publishArtifact in (Compile, packageDoc) := false + libraryDependencies ++= Seq( ehcache , ws , specs2 % Test , guice ) libraryDependencies ++= Seq( "org.spongepowered" % "play-discourse" % "3.0", diff --git a/docker-compose.yml b/docker-compose.yml index c835e6bd2..abb3c7e87 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "2" +version: '2' services: app: @@ -7,18 +7,18 @@ services: - 'db' - 'spongeauth' ports: - - "9000:9000" + - '9000:9000' stdin_open: true db: build: '.docker/db/' restart: always environment: POSTGRES_USER: root - POSTGRES_PASSWORD: "" + POSTGRES_PASSWORD: '' POSTGRES_DB: ore spongeauth: image: spongepowered/spongeauth depends_on: - 'db' ports: - - "8000:8000" + - '8000:8000' From c525e5e82ac5b48e9e8c47942dc7971367e70df3 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Tue, 28 Aug 2018 23:41:49 +0200 Subject: [PATCH 2/2] Proper SBT setup for building the image --- Dockerfile | 27 +++++++++++++++++++-------- docker-compose.yml | 5 ++++- docker.sh | 3 ++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20671a00a..0d44ab513 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,15 @@ +# This Dockerfile is designed to be used for production FROM openjdk:8-jdk-alpine LABEL maintainer="Jadon Fowler " # Temporary build folder for the 'stage' task WORKDIR /home/ore/build +# The .dockerignore file on the project root avoids build cache and personal configuration to be included in the image ADD . ./ -ADD conf/application.conf.template conf/application.conf -ENV SBT_VERSION=0.13.9 \ +# TODO use Docker secrets for the app key and passwords (and any other sensible information) +ENV SBT_VERSION=1.2.1 \ SBT_HOME=/usr/local/sbt \ JDBC_DATABASE_URL=jdbc:postgresql://db/ore \ SPONGE_AUTH_URL=http://spongeauth:8000 \ @@ -15,15 +17,24 @@ ENV SBT_VERSION=0.13.9 \ ENV PATH=${PATH}:${SBT_HOME}/bin -RUN apk add --virtual --no-cache curl ca-certificates bash && \ - curl -sL "http://dl.bintray.com/sbt/native-packages/sbt/$SBT_VERSION/sbt-$SBT_VERSION.tgz" | gunzip | tar -x -C /usr/local && \ +# TODO a shell script to extract the SBT version from project/build.properties and set SBT_VERSION to the output value +RUN cp conf/application.conf conf/application.conf && \ + apk add --virtual --no-cache curl ca-certificates bash && \ +# Downloads SBT with the version given above and extracts it + curl -sL "https://piccolo.link/sbt-$SBT_VERSION.tgz" -o "sbt-$SBT_VERSION.tgz" && \ + tar -xvzf "sbt-$SBT_VERSION.tgz" -C /usr/local && \ +# Compiles Ore and makes a production distribution (but not in an archive, unlike 'dist') sbt stage && \ + mkdir -p /home/ore/prod && \ +# Copy the 'stage' task result _content_ into the production directory + cp -r /home/ore/build/target/universal/stage/* /home/ore/prod && \ +# Cleans the temporary build directory, as we don't need it in the final image + rm -rf /home/ore/build && \ +# SBT is no longer needed too + rm -rf $SBT_HOME && \ apk del curl -WORKDIR /home/ore/prod/bin/ - -RUN cp -r /home/ore/build/target/universal/stage/* /home/ore/prod/ && \ - rm -rf /home/ore/build/ +WORKDIR /home/ore/prod/bin # Ore runs on port 9000 EXPOSE 9000 diff --git a/docker-compose.yml b/docker-compose.yml index abb3c7e87..eb58ffece 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,8 @@ -version: '2' +version: '3' services: app: + image: ore:1.6.8 build: . depends_on: - 'db' @@ -12,6 +13,8 @@ services: db: build: '.docker/db/' restart: always + ports: + - '5432:5432' environment: POSTGRES_USER: root POSTGRES_PASSWORD: '' diff --git a/docker.sh b/docker.sh index 3adfb62fa..fe01fb4dd 100755 --- a/docker.sh +++ b/docker.sh @@ -1,4 +1,5 @@ #!/bin/sh +# This is probably not needed anymore # We want to connect to db/ore -env JDBC_DATABASE_URL="jdbc:postgresql://db/ore" SPONGE_AUTH_URL="http://spongeauth:8000" activator run +JDBC_DATABASE_URL="jdbc:postgresql://db/ore" SPONGE_AUTH_URL="http://spongeauth:8000" java -jar