16

如何打包一个镜像三个环境都可以使用?

 2 years ago
source link: https://www.v2ex.com/t/790104
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如何打包一个镜像三个环境都可以使用? - V2EX

V2EX  ›  DevOps

如何打包一个镜像三个环境都可以使用?

  tyit · 8 小时 19 分钟前 via iPhone · 788 次点击

有个 Java 项目,代码里面有个配置文件写死了 nacos 配置中心的地址以及一些其它参数,如何构建镜像才能实现三个不同的环境使用?或者有没有更灵活的办法呢?

比如三个环境的 nacos 地址

Uat 环境 nacos 地址 uat.nacos.com

Stag 环境 nacos 地址 stag.nacos.com

Prod 环境 nacos 地址 prod.nacos.com

12 条回复    2021-07-17 23:10:11 +08:00

CEBBCAT

CEBBCAT   6 小时 41 分钟前

- 在初始化时根据环境切换配置内容
- 按照文件加载配置

defunct9

defunct9   6 小时 35 分钟前 via iPhone

有,启动 pod 的时候侵入修改

creanme

creanme   6 小时 34 分钟前

蹭主题,顺便问问前端如何打包一次,能在两个环境中使用。代码中有调用其它系统接口,测试环境和生产环境接口不同。之前要么在本地或者 pipeline 中打包两次,分别对应测试环境和生产环境,或者在代码里面根据当前域名来判断是否是生产环境,不过都不太好的样子。

Acoffice

Acoffice   6 小时 28 分钟前 via Android

通过不同变量来加载不同地址。

ruiyi1994

ruiyi1994   6 小时 22 分钟前

通过环境变量的改变来加载配置, 比如设置一个 RUN_ENV=production | stage | testing | dev

ik

ik   6 小时 13 分钟前 via iPhone

写成同样的地址呢, 不同环境配置不同解析?

xuanbg

xuanbg   5 小时 33 分钟前   ❤️ 1

JAVA_OPTIONS="-Dspring.profiles.active=prod"
JAVA_OPTIONS="-Dspring.profiles.active=stag"

clickhouse

clickhouse   5 小时 10 分钟前

常见的就是楼上,指定 spring 的 profiles,配置都放在 jar 包里面。要不然就是启动 jar 的时候,动态传入需要的地址。

Jooooooooo

Jooooooooo   4 小时 54 分钟前

启动的时候有个 pre 脚本

判定当前环境, 然后对应的替换配置文件中的内容

zhzy0077

zhzy0077   4 小时 27 分钟前

所有环境相关的配置,比如数据库连接,配置中心啥的,都应该是容器 /代码无关的,一般是通过环境变量拿进去。
12 factor app 可以看看: III. Config
Store config in the environment

BBCCBB

BBCCBB   4 小时 20 分钟前

通过启动变量.. 或者代码里写好, 根据启动参数里不同的 env 来使用不同的地址..

thet

thet   3 小时 35 分钟前

代码里面通过环境变量取值,镜像构建就不用管这些了,启动镜像的时候注入环境变量

关于   ·   帮助文档   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   1059 人在线   最高记录 5497   ·  

创意工作者们的社区

World is powered by solitude

VERSION: 3.9.8.5 · 17ms · UTC 18:45 · PVG 02:45 · LAX 11:45 · JFK 14:45
♥ Do have faith in what you're doing.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK