I have created a simple application with DockerPlugin in sbt file and it uses my default application.conf file to load resources. But now, I will need to change this configurations depend on environment (other for dev, other one for prod). Is it possible to tell docker which configuration file should be used? I tried to separate application.conf data into prod and dev and load files in case of given environment in path, but I don't think so it is good solution.
Related
have several java servlet projects. Each one uses a different configuration file. The servlet use and environment variable to find the config file. I have several different run time configurations. One for each project.
Is there a way to set the default run time configuration for each project. I loose a lot of time because I try to debug and accidentally select the wrong profile
Kind regards
Andy
I am using sbt for my scala project, i want to create build for different environment like local, development, stage and production. these build will have different property file, log4j file and token files. So to handle this i need different folders with files under src/main/resources like local, dev, stage and prod. Based on the build environment it should pick files from respective folders. Can you guide me to do this using sbt.
Instead of create different files use environment variables inside https://github.com/typesafehub/config , for instance:
akka {
loglevel = "DEBUG"
loglevel = ${?LOGLEVEL}
}
If LOGLEVEL is not set "DEBUG" is the default config. Anyway, if you want to include different files making jars you can use different configuration for the sbt-assembly plugging.
I have a pretty standard Scalatra project using Logback for logging.
Following the logback manual I have added a logback-test.xml for my development configuration (logs of debugs), whilst maintaining a production logback.xml.
However, in development while using the xsbt-web-plugin to run a container with code reloading, my app only seems to pick up the logback.xml.
How do I get the desired behavior?:
In development mode (./sbt container:start) the app uses logback-test.xml
When assembled into a zip using SBT-assembly, exclude the test config.
Currently neither of these seems to work.
You're misusing logback-test.xml. It's intended for unit-like tests only and should be placed in src/test/resources (which is automatically excluded from prod). To achieve what you want - you may set up path to your logback-dev.xml by system property:
javaOptions in container += "-Dlogback.configurationFile=/some/path/logback-dev.xml"
This path may be relative. See, https://stackoverflow.com/a/26538449/1809978
In my practice we don't pack logback.xml even in prod (it's pointed to some external place) to have ability to change logging configuration ad-hoc.
P.S. If you're also interested about excluding files from sbt-assembly - this may help
I have a Play 2 application that uses some external Java libraries. Some of these (e.g. the Paypal merchant sdk) depend on having a properties file for configuration (e.g. sdk_config.properties) which I have put into the conf directory.
When deploying this application to a different environment using play dist is there a sensible way to swap out properties files for each environment? For the main configuration in application.conf this is straightforward e.g. start -Dconfig.resource=prod.conf, but I am not sure how to do something similar for the properties files.
The support for specifying config.resource (and a lot of other nice stuff) is built into the typesafe config lib that comes with play. Other third party libs that depend on properties files on the classpath may or may not accept something like that, so if you are lucky then there is a lib specific way to point it to a separate config file.
If they do not then the only option is to somehow provide a different file on the classpath for the different environments. This could basically be done in two ways:
A. To not ship the file with the artifact and instead provide it per environment and add that on the classpath when starting play.
B. To create different artifacts for the different configurations, this would require you to customize dist to create one artifact per distinct env.
I would go for A since it allows there to be one artifact that can be run anywhere, but it might add some annoyances to running the app in a dev env etc.
I built a universal tarball using sbt-native-packager.
How do I load configuration files like c3p0 and application.conf from /etc/myapp or anyother custom location when I start the app.
I don't want the config files to be part of the distribution tarball itself.
I believe you can use typesafe config's "include" feature to grab from a direct location.
See https://github.com/typesafehub/config#features-of-hocon
That said, this would require you to create different configurations based on where you're installing, if you wanted a global file as the config file.