diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index fd2f5d81..00000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/base:latest - -# create directories -RUN mkdir -p /amony/app -RUN mkdir -p /amony/data - -# copy files -COPY ./web-client/dist /amony/app/web-client -COPY ./server/web-server/target/scala-3.3.4/amony.jar /amony/app -COPY ./server/web-server/src/main/resources/prod/application.conf /amony - -WORKDIR /usr/amony -EXPOSE 8080 -ENV JAVA_TOOL_OPTIONS "-Dconfig.file=/amony/application.conf" -ENV AMONY_HOME "/amony" -#ENV AMONY_CONFIG_FILE "/amony/application.conf" -ENTRYPOINT ["java", "-jar", "/amony/app/amony.jar"] diff --git a/README.md b/README.md index 1f3f974b..5f486d41 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ docker pull europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/app:lat ### 2. Run the docker image -The default location for the media files is `/amony/media`. You can mount a local directory to it. -The default location for the solr index, database and config files is `/amony/data`. It is recommended to mount a local directory to it to persist the data. +The default location for the media files is `/media`. You can mount a local directory to it. +The default location for the solr index, database and config files is `/app/data`. It is recommended to mount a local directory to it to persist the data. ```bash -docker run -v /path/to/my/media:/amony/media -v /path/to/my/amony-data:/amony/data -p 8080:8080 --name amony europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/app:latest +docker run -v /path/to/my/media:/media -v /path/to/my/amony-data:/app/data -p 8080:8080 --name amony europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/amony-app:latest ``` ### 3. Usage @@ -93,23 +93,15 @@ npm install --save npm run build ``` -### 2. Build the server +### 2. Build the docker image ``` cd server -sbt assembly +sbt web-server/jibDockerBuild ``` -### 3. Build the docker image - -``` -docker build -t my-amony-app:latest . -``` - -The first time this can take a bit longer since it downloads & installs all dependencies for `ffmpeg`. - ### 4. Run the docker image ```bash -docker run -v /path/to/my/media:/amony/media -v /path/to/my/amony-data:/amony/data -p 8080:8080 my-amony-app:latest +docker run -v /path/to/my/media:/media -v /path/to/my/amony-data:/app/data -p 8080:8080 --name amony europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/amony-app:latest ``` diff --git a/server/build.sbt b/server/build.sbt index 15814c96..86a55266 100644 --- a/server/build.sbt +++ b/server/build.sbt @@ -1,5 +1,7 @@ //import sbt.Keys.scalaVersion import sbtassembly.AssemblyPlugin.autoImport.assemblyMergeStrategy +import com.google.cloud.tools.jib.api.buildplan.Platform +import de.gccc.jib.MappingsHelper // --- Dependencies @@ -22,7 +24,7 @@ val slickHikariCp = "com.typesafe.slick" %% "slick-hikaricp" val jwtCirce = "com.github.jwt-scala" %% "jwt-circe" % "10.0.1" val slf4jApi = "org.slf4j" % "slf4j-api" % "2.0.16" -val scribeSlf4j = "com.outr" %% "scribe-slf4j" % "3.15.2" +val scribeSlf4j = "com.outr" %% "scribe-slf4j" % "3.15.3" val fs2Core = "co.fs2" %% "fs2-core" % "3.11.0" val fs2Io = "co.fs2" %% "fs2-io" % "3.11.0" @@ -247,16 +249,23 @@ lazy val amonyServer = run / javaOptions ++= javaOpts, outputStrategy := Some(StdoutOutput), - jibBaseImage := "europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/base:latest", -// jibPlatforms := Set("linux/amd64"), - jibImageFormat := JibImageFormat.Docker, - jibRegistry := "europe-west4-docker.pkg.dev", - jibName := "amony-app", - jibTags := List("latest"), - jibEntrypoint := Some(List("java", "-jar", "/amony.jar")), - jibCustomRepositoryPath := Some("amony-04c85b/docker-images/amony"), + jibBaseImage := "europe-west4-docker.pkg.dev/amony-04c85b/docker-images/amony/base:latest", + jibRegistry := "europe-west4-docker.pkg.dev", + jibName := "amony-app", + jibCustomRepositoryPath := Some("amony-04c85b/docker-images/amony/" + jibName.value), + jibPlatforms := Set(new Platform("amd64", "linux")), + jibImageFormat := JibImageFormat.Docker, + jibTags := List("latest"), + jibExtraMappings ++= { + // this adds the frontend assets to the docker image + val webClientDir = (Compile / baseDirectory).value / ".." / ".." / "web-client" / "dist" + val target = "/app/web-client" + MappingsHelper.contentOf(webClientDir, target) + }, + jibEnvironment := Map("JAVA_TOOL_OPTIONS" -> "-Dconfig.file=/app/resources/prod/application.conf"), + jibUseCurrentTimestamp := true, - Compile / packageBin / mainClass := Some("nl.amony.webserver.WebServer"), + Compile / packageBin / mainClass := Some("nl.amony.webserver.Main"), libraryDependencies ++= Seq( // logging @@ -264,8 +273,7 @@ lazy val amonyServer = // config loading typesafeConfig, pureConfig, // database - liquibaseCore, slickHikariCp, hsqlDB, h2DB, - circe, circeGeneric, circeParser, + slickHikariCp, hsqlDB, h2DB, fs2Core, http4sEmberServer, // test @@ -275,18 +283,6 @@ lazy val amonyServer = excludeDependencies ++= List( ExclusionRule("javax.xml.bind", "jaxb-api"), ), - - // assembly / logLevel := Level.Debug, - assembly / assemblyJarName := "amony.jar", - assembly / assemblyMergeStrategy := { - case s if s.endsWith("module-info.class") => MergeStrategy.discard - case s if s.endsWith("Log4j2Plugins.dat") => MergeStrategy.discard - case s if s.startsWith("org/iq80/leveldb") => MergeStrategy.first - case s if s.endsWith("io.netty.versions.properties") => MergeStrategy.first - case x => - val oldStrategy = (assembly / assemblyMergeStrategy).value - oldStrategy(x) - } ) lazy val amony = project diff --git a/server/project/plugins.sbt b/server/project/plugins.sbt index a343a9a2..101d6eee 100644 --- a/server/project/plugins.sbt +++ b/server/project/plugins.sbt @@ -2,4 +2,5 @@ addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.0.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("de.gccc.sbt" % "sbt-jib" % "1.3.7") +addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1") libraryDependencies += "com.google.cloud.tools" % "jib-core" % "0.27.2" diff --git a/server/web-server/src/main/resources/prod/application.conf b/server/web-server/src/main/resources/prod/application.conf index 32ff42ce..dae190d6 100644 --- a/server/web-server/src/main/resources/prod/application.conf +++ b/server/web-server/src/main/resources/prod/application.conf @@ -2,12 +2,12 @@ include required(classpath("amony-common.conf")) amony { - amony-home = "/amony" + amony-home = "/app" amony-home = ${?AMONY_HOME} api { host-name = localhost - web-client-path = ${amony.amony-home}"/app/web-client" + web-client-path = ${amony.amony-home}"/web-client" } solr { @@ -39,7 +39,7 @@ amony { type = "local-directory-config" # location of your media - path = "/amony/media" + path = "/media" # path where to write derived resources such as thumbnails and video fragments relative-cache-path = ".amony/cache"