Open mathieuleclaire opened 4 years ago
Hi @mathieuleclaire
Thanks for the detailed issue description. Let's unwrap this :smiley:
I assume what you are trying to do is packaging your frontend assets (scalajs) into the resulting server so they can be served. You have split up your build in two modules server
and client where
serverdepends on
client. This is pretty standard stuff so far.
I assume that the assets are not properly being served?
Because the server
depends on the client
, the client
project will be available as a jar in the lib/
directory. So you scalajs resources should be available in the client.jar
and not directly in the server
.
If my assumption about the actual error is correct than you are like me and a lot of other jvm developers :joy: Loading resources from jars on the classpath is somewhat error prone and painful to debug on the jvm.
Can you post the actual problem you are facing if I'm mistaken :smile:
Hi @muuki88, Your are right, I try to build a server application, which serve frontend stuff compiled and gathered with scalajs. This part is OK: I can generate the js I need, pack my js dependency resources and CSSs.
It is pretty easy actually: I need in my docker both my server applicatons and jars as well as my frontend assets in the same place. Something like in /opt/docker/:
Only the first two directories (bin and lib), and not the webapp one.
I try copy my frontend stuff in the /opt/docker/webapp with the mappings
methods. But the resources are not copied.
Note however that I can find them copied locally in the my target/docker/stage/opt/docker/target/webapp
Is the way I do is the way to do ? If yes, what is my mistake ?
Thanks for the clarification @mathieuleclaire :smiley:
Can you show the output of
$ sbt "show server / Docker / mappings"
It should show all files that end up in the docker image. If the files don't appear there, then it's a configuration error, if they do, then there's a bug in native-packager.
Does the client
module generate a jar with the js files included? I haven't used scalajs in ages. Because usually that's what I would recommend that you do less configuration in sbt and rely on the classpath. E.g. if the jar produced by the client
module has the assets under webapp
then you could load an asset with
// or similar
getClass.getClassLoader.getInputStream("/webapp/styles.css")
Most scala http servers have built in support for this, e.g. akka getResourceDirectory
I ran show docker:mappings
in my application project. I get
The thing I observe is the frontend resources are not mapped in the application
directory but in the client
one. Could it be the issue ?
[info] * (/home/mathieu/work/cogit/openmole-connect/application/target/universal/scripts/bin/application,/opt/docker/bin/application)
[info] * (/home/mathieu/work/cogit/openmole-connect/application/target/universal/scripts/bin/application.bat,/opt/docker/bin/application.bat)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/target/scala-2.13/client-jsdeps.min.js,/opt/docker/target/webapp/js/connect-deps.js)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/target/scala-2.13/client-opt.js,/opt/docker/target/webapp/js/connect.js)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/WEB-INF,/opt/docker/target/webapp/WEB-INF)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts,/opt/docker/target/webapp/fonts)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/css,/opt/docker/target/webapp/css)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/img,/opt/docker/target/webapp/img)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/WEB-INF/web.xml,/opt/docker/target/webapp/WEB-INF/web.xml)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/icomoon.ttf,/opt/docker/target/webapp/fonts/icomoon.ttf)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/icomoon.svg,/opt/docker/target/webapp/fonts/icomoon.svg)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/icomoon.woff,/opt/docker/target/webapp/fonts/icomoon.woff)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/glyphicons-halflings-regular.ttf,/opt/docker/target/webapp/fonts/glyphicons-halflings-regular.ttf)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/glyphicons-halflings-regular.woff2,/opt/docker/target/webapp/fonts/glyphicons-halflings-regular.woff2)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/glyphicons-halflings-regular.eot,/opt/docker/target/webapp/fonts/glyphicons-halflings-regular.eot)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/gi.otf,/opt/docker/target/webapp/fonts/gi.otf)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/icomoon.eot,/opt/docker/target/webapp/fonts/icomoon.eot)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/glyphicons-halflings-regular.svg,/opt/docker/target/webapp/fonts/glyphicons-halflings-regular.svg)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/fonts/glyphicons-halflings-regular.woff,/opt/docker/target/webapp/fonts/glyphicons-halflings-regular.woff)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/css/style.css,/opt/docker/target/webapp/css/style.css)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/src/main/resources/webapp/img/logo.png,/opt/docker/target/webapp/img/logo.png)
[info] * (/home/mathieu/work/cogit/openmole-connect/client/target/css/deps.css,/opt/docker/target/webapp/css//deps.css)
Well, I fixed my problem. But I am not very sure how (and I do not like this !)
I essentially changed in Universal
in in Docker
, but it was my very initial config, which did not work.
Thanks anyway !
Here is the working snippet for memory:
val prefix = "/opt/docker/application/target"
lazy val application = project.in(file("application")) settings (defaultSettings) dependsOn(server) enablePlugins (JavaServerAppPackaging) settings(
mappings in Docker ++= Seq(
(dependencyFile in client in Compile).value -> s"$prefix/webapp/js/connect-deps.js",
(fullOptJS in client in Compile).value.data -> s"$prefix/webapp/js/connect.js"
) ++ doMapping((resourceDirectory in client in Compile).value, prefix)
++ doMapping((cssFile in client in target).value, s"$prefix/webapp/css/"),
packageName in Docker := "openmole-connect",
organization in Docker := "openmole"
)
Thanks for sharing. This is strange. The mappings in Docker
should inherit from mappings in Universal
.
The docker plugin is quite complex due to the nature of docker being complex. I'll leave this open as there's something weird going on, but I don't have the time to look deeper into it :cry:
I am trying to package a scala server app into a Docker
Expected behaviour
I am suppose to get my
application
and a directory with some resources in the docker image.Actual behaviour
Only
application
in/opt/docker/bin
and dependency jars inopt/docker/lib
are copied. The resources defined through themappings
mechanism are not copied.Information
I use:
Note: the doMapping function fetch recursively all the resources contained in directories.
Note that my
target/webapp
directory seems to be properly copied intarget/docker/stage/opt/docker/target/webapp
but not in the docker itself.The generated Docker instructions look like this: