简体   繁体   中英

How to manage multiple Spring profiles with Heroku

I'm setting up a new environment for my application, we only have "prod" environment, I want to create a testing environment, for that, I configured two Spring profiles, "test" and "prod", and created a new branch called "test" where we want to have the test environment and push that branch to master like a kind of "promotion" to production. This is a extract of our application.yml

spring:
  profiles: test
 {some properties...}

---

spring:
  profiles: prod
 {some properties...}

We are using Heroku to deploy our app and repositories from AzureDevOps, where we also have a pipeline that runs when we push commits to master, this pipeline push the AzureDevOps master branch to the Heroku repository. In Heroku we have an application created on "staging", we didn't add a "production" application yet (not sure if it's relevant but I wanted to clarify that).

This is the pipeline:

git checkout $(Build.SourceBranchName)
git remote add heroku https://heroku:$(pat)@git.heroku.com/app-hto.git
git push heroku $(Build.SourceBranchName)

To specify the profile I'm using the Procfile file in my Java project, where we have this:

web: java -Dspring.profiles.active=prod -Dserver.port=$PORT $JAVA_OPTS -jar target/api-0.0.1-SNAPSHOT.jar

As you can see I'm not a Heroku expert so I don't know how to proceed, so, my question is, how can I specify which profile use for each environment? There is a way to accomplish that using AzureDevOps pipelines?

Azure Devops might be able to accomplish that, but it would be complicated.

It will be easier to achieve this with heroku. Heroku itself provides ways to control which profile is active either by cli, dashboard,or api. for details check here

Hope i point to the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM