anjia0532 opened a new issue #6143: URL: https://github.com/apache/apisix/issues/6143
### Issue description 目前官方已经支持了基于环境的配置文件的区分,文档: [基于环境变量进行配置文件切换](https://apisix.apache.org/zh/docs/apisix/profile) 看文档描述初衷是为了应对变化,但是个人感觉实际使用中,更多的是80%-90%的文件不变,少量是地址,密码,用户这种的变更。简单翻看了下源码 [apisix/core/profile.lua](https://github.com/apache/apisix/blob/master/apisix/core/profile.lua) ,应该只是基于 `APISIX_PROFILE ` 来读取不同的文件(类似加后缀),意味着要维护两份绝大多数一样,少部分不一样的配置文件。好处是隔离风险,坏处是,久了容易导致配置割裂越来越严重。 出于最小化改动,不引入破坏性更新,及摒弃无用功能引入的想法,参考但不是照搬spring boot profile,提出以下提议: 以 `conf/config.yaml` 为例 ```yaml apisix: node_listen: 8000 # APISIX listening port etcd: host: "http://foo:2379" # etcd address ``` `conf/config-dev.yaml` ```yaml etcd: host: "http://dev:2379" # dev etcd address ``` `conf/config-prod.yaml` ```yaml etcd: host: "http://prod:2379" # prod etcd address ``` `APISIX_PROFILE=prod` 最终的apisix读取到的配置为 ```yaml apisix: node_listen: 8000 # APISIX listening port etcd: host: "http://prod:2379" # prod etcd address ``` 而不是现在的 ```yaml etcd: host: "http://prod:2379" # prod etcd address ``` 基于此可以实现动静分离,比如,把upstreams这种常见易变配置摘出来,配置成 `config/apisix-dynamic.yaml`,加上静态配置 `config/apisix.yaml` 技术难点就是lua table merge 参考 [how-to-merge-two-tables-overwriting-the-elements-which-are-in-both](https://stackoverflow.com/questions/1283388/how-to-merge-two-tables-overwriting-the-elements-which-are-in-both) 没必要跟spring boot profile 那样支持表达式(SpEL),多种数据文件(yaml,properties),多文件混织 `spring.profiles.active=foo,bar,dev`(同时读取 application.yml,application-foo.yml,application-bar.yml,application-dev.yml) ### Environment - apisix version (cmd: `apisix version`): - OS (cmd: `uname -a`): - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): - apisix-dashboard version, if have: - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner): - luarocks version, if the issue is about installation (cmd: `luarocks --version`): -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
