I have an sbt project that spins up a server on a specified port. Here is related excerpt from
port in container.Configuration := sys.env.getOrElse("MY_VAR_SEARCH_PORT", 8080).toString.toInt
When I run the project from sbt,
$MY_VAR_SEARCH_PORT gets picked up, and all is good.
However, for prod I use sbt-assembly and run a jar in a docker container, so the launch command looks like this:
docker run -it -p 80:80 -e MY_VAR_SEARCH_PORT=80 mydockerhubrepo/myimageid /docker-entrypoint.sh java -Djava.io.tmpdir=/tmp/jetty -Drun.mode=production -Denv=prod -jar /usr/local/jetty/start.jar
I can see that var gets passed to the container, but it is not being picked up by the jar, as it spins up a server on default port.
What would be a good way to make sbt-assembly jar access environment variables? Or maybe I can pass this var as java argument – then, how to access it from build.sbt file?