Heroku - environment variable for Srping Boot DB connect - spring

I have an app on Spring Boot that running in two environments, local and heroku:
Local - connect to DB is configured by app.properties.
Heroku - app is working w\o app.properties, using one environment variable:
heroku config -a zed-social-network
=== zed-social-network Config Vars
CLEARDB_DATABASE_URL: mysql://{login}:{pass}#host.com/heroku?reconnect=true&useUnicode=true&characterEncoding=UTF-8
Question: how I can configure DB connect in Spring on local machine in same style, with one env variable?

I would use a command line argument:
mvn spring-boot:run -Drun.arguments=--customArgument=custom
so in your case
mvn spring-boot:run -Drun.arguments=--CLEARDB_DATABASE_URL=your_url
--
Alternatively, you could add the url to system variables and then reference it in application.properties like so:
spring.datasource.url=${NAME_OF_THE_SYSTEM_VARIABLE}

Related

Heroku add on ever deploy -Dspring.profiles.active=prod

I have 3 application.yml one for dev and one for prod
application.yml (default set to dev)
application-dev . yml
application-prod . yml
When running this command - Dspring.profiles.active=prod it will use my production, how am I able to get this working in heroku?
Already tried adding -- spring.profiles.active and - Dspring.profiles.active but both are not recognized is there something that i'm missing?
Define a config vars
heroku config:set SPRING_PROFILES_ACTIVE=prod
You can also add it in the Heroku Dashboard (key-value)

Dockerized Spring Boot app can't get JDBC connection string on Heroku

I'm trying to run the Dockerized Spring Boot application on Heroku. I use dockerfile-maven and plugin to create the app I use this commands
heroku apps:create my-app-name --buildpack heroku/java
heroku addons:create heroku-postgresql:hobby-dev --app my-app-name
Notice that I'm using buildpack here.
In application.properties I have such lines
spring.datasource.url=${JDBC_DATABASE_URL:some default jdbc connection string}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
How I understand if I set the heroku/java buildpack for the app the environment variables JDBC_DATABASE_URL should be created but in my case, I see the default connection string in logs. That's mean that JDBC_DATABASE_URL is not set or not available. Why that's could happen?
Worth to mention that DATABASE_URL environment variable is available in the application.

Tell heroku which config file for Play application to load

In Play, you can use multiple config files (application.conf, prod.conf...). Usually you would have a default conf file, i.e. application.conf, and let the other files import it and overload specific values.
One case is for example when you have a production database and wand to overwrite access configuration values set by developers and use credentials only known to the production personnel.
Here is a manual on this topic that say that the wanted config is to be specified as a parameter when running the application
I am deploying my application onto Heroku, which takes care of running the application. The only peace missing here and I can't find is how to tell Heroku which config file to load?
I solved this by using a Procfile with the contents:
web: target/universal/stage/bin/my_app -Dhttp.port=$PORT -Dconfig.resource=my-special.conf
You can define environment variables for your Heroku app, e.g. using the heroku config CLI command:
heroku config:set PLAY_CONFIG_FILE=application.conf
See Heroku config vars.

How to deploy meanjs to heroku

I have tried deploying my meanjs on heroku.
I forked this https://github.com/meanjs/mean
1.) Login to heroku
2.) Deploy and connect github repositor
enabled automatic deploy CI
Click on Manual Deploy
On the build log it says "Bulid succeded"
My question is.
Why am I getting this application error?
When all I did was forked the repository and deployed it on heroku?
https://serkolgame.herokuapp.com/
Did you add a mongoDB to your app? Without it, the startup process is likely to fail.
Here are some options:
If you are using the default dev environment - then just add the mongodb connection string in development.js and restart the server
If you are using the prod environment - then you can use environment variables uri: process.env.MONGOHQ_URL or process.env.MONGOLAB_URI
This is assuming you have a mongoDB sandbox setup somewhere, if you don't, you'll first need a mongodb sandbox (get one from Heroku, Compose.io, or MongoLab).

Heroku is switching my play framework 2 config file

I have a Play! application which is on Heroku.
My config file is different between my local application and the same on Heroku. Especially for the URL of my MongoDB base.
On localhost my base address is 127.0.0.1 and on heroku it's on MongoHQ. So when I push my application to Heroku I modify my config file.
But some times, like this morning Heroku change the config file. I pushed my application correctly configured on Heroku this morning and everything worked until now.
When I watch the logs I see that Heroku changed my config and try to connect to my local MongoDB base.
Is someone knowing what ? I hope I'm clear :)
Thanks everybody !
If there are differences in your application in different environments (e.g. local vs production), you should be using assigning the values with environment variables. For Play apps, you can use environment variables in your application.conf file, like this:
`mongo.url=${MONGO_URL}`
Then, on Heroku you can set the environment variables with config vars, like this (note, this may already be assigned for you by the add-on provider):
$ heroku config:add MONGO_URL=...
Locally, you can use Foreman to run your application with the environment variables stored in an .env file in your project root.

Resources