简体   繁体   English

如何使用Heroku管理多个Spring配置文件

[英]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. 我正在为我的应用程序设置一个新环境,我们只有“ prod”环境,我想创建一个测试环境,为此,我配置了两个Spring配置文件“ test”和“ prod”,并创建了一个新分支称为“测试”,我们想要拥有测试环境并将该分支推向生产,就像​​对产品的“促销”一样。 This is a extract of our application.yml 这是我们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. 我们正在使用Heroku从AzureDevOps部署我们的应用程序和存储库,我们还有一个在将提交推送到master时运行的管道,该管道将AzureDevOps master分支推送到Heroku存储库。 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). 在Heroku中,我们有一个基于“ staging”创建的应用程序,我们还没有添加“ production”应用程序(不确定它是否相关,但是我想澄清一下)。

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: 要指定配置文件,我在Java项目中使用Procfile文件,其中包含以下内容:

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? 如您所见,我不是Heroku专家,所以我不知道如何进行操作,所以我的问题是,如何指定每种环境使用哪种配置文件? There is a way to accomplish that using AzureDevOps pipelines? 有没有一种方法可以使用AzureDevOps管道来实现?

Azure Devops might be able to accomplish that, but it would be complicated. Azure Devops可能能够完成此任务,但是这很复杂。

It will be easier to achieve this with heroku. 用heroku会更容易实现这一目标。 Heroku itself provides ways to control which profile is active either by cli, dashboard,or api. Heroku本身提供了通过cli,仪表板或api控制哪个配置文件处于活动状态的方法。 for details check here 详情请点击这里

Hope i point to the right direction. 希望我指出正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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