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

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)

Related

Create React App env variables undefined when using Craco build in Heroku

I'm deploying an Express app (Node.js/React) to Heroku and have set my env vars in Heroku using the config vars in Settings in the Heroku Dashboard. On the server side, I can access them using process.env without any problems. However, in my client, my process.env vars are returning undefined.
I have prefixed them with REACT_APP, and the issue seems to be related to the craco build script in my client/package.json that is called during the build stage of the Heroku deployment. If I set this to react-scripts build, the environment variables behave as expected, however, my TailwindCSS config then fails.
I can also have a .env file in the client, but I need different values depending on the stage of the Heroku pipeline, and NODE_ENV is always "production" once deployed to Heroku so I can't think of a way to have different values depending on the stage.
Is there a way for craco build to get the REACT_APP vars from the Heroku config vars during deployment in the same way react-scripts build does?
There is a npm package specifically build to use .env variables with craco: https://github.com/djdmbrwsk/dotenv-cra

Heroku - environment variable for Srping Boot DB connect

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}

Heroku: deploy jhipster project with `gitlab-ci` get crashed because of `Procfile` command

I had ask this issue on jhipster-generator Github issue before.
But still don't get solutions yet.
(See more at Example Repository on my Gitlab and Github issue#9426)
I think it related to the final commands in the Procfile that I got from the generator which defined like these:
web: java $JAVA_OPTS -Xmx256m -jar target/*.war --spring.profiles.active=prod,heroku,no-liquibase --server.port=$PORT
release: cp -R src/main/resources/config config && ./mvnw liquibase:update -Pheroku
on release: the command cp -R ... can't be executed because from the last job of gitlab-ci which work fine and get green response. But when I see log in Heroku deploy instance, I got the src/main/resource/config not found. Then I try to investigate more with added ls * -ltr to release: and found that even src directory is not found. Only target directory is over there.
So I tried remove the release: row from Procfile the try again, then I got crashed messages from Heroku server running the application.
Some part from Log
2019-03-26T03:18:10.547189+00:00 app[web.1]: 03:18:10.536 [localhost-startStop-1] ERROR org.springframework.boot.SpringApplication - Application run failed
2019-03-26T03:18:10.547217+00:00 app[web.1]: java.util.ServiceConfigurationError: javax.cache.spi.CachingProvider: Provider org.redisson.jcache.JCachingProvider not a subtype
...
2019-03-26T03:18:10.567009+00:00 app[web.1]: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
But if I run with the command jhipster heroku it will deploy with different method from the command defined in .gitlab-ci.yml file. And can be run successfully.
So due to the Heroku deployment documentation which I think it is the most related to the issue I found right now, what should I fix on the Procfile to get the final deployment on Heroku can work as it should be?
Any help will be appreciate and thank you in advance.
TLDR;
I do these things and then the CI-CD with Gitlab -> Heroku can do CI-CD properly.
at Procfile, remove the release: line, because what the .gitlab-ci.yml file do when deploy-to-production state was performed is deploy the JAR file, not include the whole project directories, so, it's not important to copy files from project's directories anymore.
Now you can run CI-CD with all green on Gitlab pipeline and Deployed succeed on Heroku
But there are some issues will block your app from running properly. And here what I found.
# ===================================================================
# Spring Boot configuration for the "heroku" profile.
#
# This configuration overrides the application.yml file.
# ===================================================================
# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================
eureka:
instance:
hostname: jhip-cicd-bug.herokuapp.com
non-secure-port: 80
prefer-ip-address: false
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}
hikari:
maximumPoolSize: 8
data:
jest:
uri: ${BONSAI_URL}
The application-heroku.yml file, the reference to environment variables ${JDBC_DATABASE_URL}, ${JDBC_DATABASE_USERNAME}, ${JDBC_DATABASE_PASSWORD}, is not created, only thing be created is DATABASE_URL that contains with postgres://[generated-user]:[generated-secret]#[generated-url]:5432/[generated-dbname]
It's wrong on
Not started with jdbc:
Environment variable name is different as defined above DATABASE_URL (created) not equals to JDBC_DATABASE_URL, and the ${JDBC_DATABASE_USERNAME}, ${JDBC_DATABASE_PASSWORD} were not created. Then my workaround is create those environment variables on Heroku settings -> Config vars and edit their value properly, like...
key JDBC_DATABASE_URL value jdbc:postgres://[url]:5432/[dbname]
key JDBC_DATABASE_USERNAME value [username]
key JDBC_DATABASE_PASSWORD value [password]
Or you might change this url: ${JDBC_DATABASE_URL} to url: jdbc:${DATABASE_URL} (never try before, not confident for the result).

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.

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