From 4d6ea54771c284d5ea0bb798fedaf0423a6cdd58 Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 7 Nov 2025 14:22:23 +0100 Subject: [PATCH] feat(docker): added docker container support (#47) Reviewed-on: https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/pulls/47 Co-authored-by: Janis Co-committed-by: Janis --- .dockerignore | 1 + .gitignore | 1 + .sbtopts | 2 + Dockerfile | 41 +++++++++++++++++++ build.sbt | 1 - .../app/auth/{Auth.scala => AuthAction.scala} | 4 +- knockoutwhistweb/conf/application.conf | 10 ++--- 7 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 .sbtopts create mode 100644 Dockerfile rename knockoutwhistweb/app/auth/{Auth.scala => AuthAction.scala} (93%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.env diff --git a/.gitignore b/.gitignore index c0c2529..666f573 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,4 @@ target /knockoutwhistweb/.g8/ /knockoutwhistweb/.bsp/ /currentSnapshot.json +.env \ No newline at end of file diff --git a/.sbtopts b/.sbtopts new file mode 100644 index 0000000..27f4f7b --- /dev/null +++ b/.sbtopts @@ -0,0 +1,2 @@ +-J--add-opens=java.base/java.util=ALL-UNNAMED +-J--add-opens=java.base/java.lang=ALL-UNNAMED diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9f1033 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# === Stage 1: Build the Play application === +FROM sbtscala/scala-sbt:eclipse-temurin-alpine-22_36_1.10.3_3.5.1 AS builder + +WORKDIR /app + +# Install Node.js and Less CSS preprocessor +USER root +RUN apk add --no-cache nodejs npm && \ + npm install -g less + +# Cache dependencies first +COPY project ./project +COPY build.sbt ./ +RUN sbt -Dscoverage.skip=true update + +# Copy the rest of the code +COPY . . + +# Build the app and stage it +RUN sbt -Dscoverage.skip=true clean stage + +# === Stage 2: Runtime image === +FROM eclipse-temurin:21-jre-alpine + +# Install Argon2 CLI and libraries +RUN apk add --no-cache bash argon2 argon2-libs + +WORKDIR /opt/playapp + +# Copy staged Play build +COPY --from=builder /app/knockoutwhistweb/target/universal/stage /opt/playapp + +# Expose the default Play port +EXPOSE 9000 + +# Set environment variables +ENV PLAY_HTTP_PORT=9000 + +# Run the Play app +ENTRYPOINT ["./bin/knockoutwhistweb"] +CMD ["-Dplay.server.pidfile.path=/dev/null"] diff --git a/build.sbt b/build.sbt index f33dfa4..f842c2f 100644 --- a/build.sbt +++ b/build.sbt @@ -19,7 +19,6 @@ lazy val commonSettings = Seq( .map(m => "org.openjfx" % s"javafx-$m" % "21" classifier osName) }, libraryDependencies += guice, - coverageEnabled := true, coverageFailOnMinimum := true, coverageMinimumStmtTotal := 85, coverageMinimumBranchTotal := 100 diff --git a/knockoutwhistweb/app/auth/Auth.scala b/knockoutwhistweb/app/auth/AuthAction.scala similarity index 93% rename from knockoutwhistweb/app/auth/Auth.scala rename to knockoutwhistweb/app/auth/AuthAction.scala index b956035..30add86 100644 --- a/knockoutwhistweb/app/auth/Auth.scala +++ b/knockoutwhistweb/app/auth/AuthAction.scala @@ -14,8 +14,8 @@ class AuthAction @Inject()(val sessionManager: SessionManager, val parser: BodyP extends ActionBuilder[AuthenticatedRequest, AnyContent] { override def executionContext: ExecutionContext = ec - - private def getUserFromSession(request: RequestHeader): Option[User] = { + + protected def getUserFromSession(request: RequestHeader): Option[User] = { val session = request.cookies.get("sessionId") if (session.isDefined) return sessionManager.getUserBySession(session.get.value) diff --git a/knockoutwhistweb/conf/application.conf b/knockoutwhistweb/conf/application.conf index 33a9cd6..1ee3721 100644 --- a/knockoutwhistweb/conf/application.conf +++ b/knockoutwhistweb/conf/application.conf @@ -2,14 +2,14 @@ play.filters.disabled += play.filters.csrf.CSRFFilter play.filters.disabled += play.filters.hosts.AllowedHostsFilter +play.http.secret.key="QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n" +play.http.secret.key=${?APPLICATION_SECRET} auth { issuer = "knockoutwhistweb" audience = "ui" - # ${?PUBLIC_KEY_FILE} - privateKeyFile = "/home/janis/Workspaces/IntelliJ/KnockOutWhist/Gitops/rsa512-private.pem" - privateKeyPem = ${?PUBLIC_KEY_PEM} - #${?PUBLIC_KEY_FILE} - publicKeyFile = "/home/janis/Workspaces/IntelliJ/KnockOutWhist/Gitops/rsa512-public.pem" + privateKeyFile = ${?PRIVATE_KEY_FILE} + privateKeyPem = ${?PRIVATE_KEY_PEM} + publicKeyFile = ${?PUBLIC_KEY_FILE} publicKeyPem = ${?PUBLIC_KEY_PEM} }