Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个docker包,支持部署无数个环境。不再需要不同环境打不同的包。 #2343

Merged
merged 4 commits into from
Jun 18, 2019

Conversation

xzxiaoshan
Copy link
Contributor

@xzxiaoshan xzxiaoshan commented Jun 17, 2019

1、maven编译,不再需要为每个config环境都修改build.sh(bat),只需要进行一次maven编译。一次docker打包。
2、原本需要再build.sh(bat)中配置的参数 portal 的数据库连接信息、config和admin的数据库连接信息、metaserver信息,都将不需要了。
3、这些信息,都提取到环境变量中来配置。不管你是普通部署还是docker部署,都可以通过环境变量来配置信息。
完全杜绝同环境不同包的问题。一次编译,多次运行!

下面是一个完全通过env配置的docker-compose.yml示例,包括了数据库和MetaServer的配置:

version: '3'
services:
  apollo-portal:
    image: docker.io/xzxiaoshan/apollo-portal:1.4.0
    container_name: apollo-portal
    network_mode: "host"
    environment: 
      SERVER_PORT: 5555
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
      # Environmental variable declaration (meta server url, different environments should have different meta server addresses)
      DEV_META: "http://dev.shanhy.com:6666"
      FAT_META: ""
      UAT_META: ""
      LPT_META: ""
      PRO_META: "http://pro.shanhy.com:6666"
    depends_on:
      - apollo-adminservice
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
        
  apollo-configservice:
    image: docker.io/xzxiaoshan/apollo-configservice:1.4.0
    container_name: apollo-configservice
    network_mode: "host"
    environment:
      SERVER_PORT: 6666
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloConfigDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
        
  apollo-adminservice:
    image: docker.io/xzxiaoshan/apollo-adminservice:1.4.0
    container_name: apollo-adminservice
    network_mode: "host"
    environment:
      SERVER_PORT: 6667
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloConfigDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
    depends_on:
      - apollo-configservice
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

shanhongyu added 3 commits June 14, 2019 15:30
…定端口,避免与宿主机上的原有端口占用冲突

2.对docker CMD入口的startup.sh文件,增加可执行授权指令,防止在某些时候该文件被打包进入后没有执行权限的麻烦(已实际遇到,又回头重新打包)
2、原本需要再build.sh(bat)中配置的参数 portal 的数据库连接信息、config和admin的数据库连接信息、metaserver信息,都将不需要了。
3、这些信息,都提取到环境变量中来配置。不管你是普通部署还是docker部署,都可以通过环境变量来配置信息。
完全杜绝同环境不同包的问题。一次编译,多次运行!
------------------------------------------------------------------------------------------
version: '3'
services:
  apollo-portal:
    image: docker.io/xzxiaoshan/apollo-portal:1.4.0
    container_name: apollo-portal
    network_mode: "host"
    environment:
      SERVER_PORT: 5555
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
      # Environmental variable declaration (meta server url, different environments should have different meta server addresses)
      DEV_META: "http://dev.shanhy.com:6666"
      FAT_META: ""
      UAT_META: ""
      LPT_META: ""
      PRO_META: "http://pro.shanhy.com:6666"
    depends_on:
      - apollo-adminservice
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  apollo-configservice:
    image: docker.io/xzxiaoshan/apollo-configservice:1.4.0
    container_name: apollo-configservice
    network_mode: "host"
    environment:
      SERVER_PORT: 6666
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  apollo-adminservice:
    image: docker.io/xzxiaoshan/apollo-adminservice:1.4.0
    container_name: apollo-adminservice
    network_mode: "host"
    environment:
      SERVER_PORT: 6667
      # DataSource Info
      DS_URL: "jdbc:mysql://pro.shanhy.com:3306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "shanhy"
      DS_PASSWORD: "xzxiaoshan@123"
    depends_on:
      - apollo-configservice
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
@xzxiaoshan
Copy link
Contributor Author

如果用户没有做任何配置,从使用角度来说其使用方法和结果与本次修改前一样。本次修改是一种完全兼容式修改。无任何副作用。

@xzxiaoshan
Copy link
Contributor Author

示例 docker-compose.yml 中的dockerhub镜像,是基于1.4.0 tag+fork修改后(pull request是master),直接build打包的。未做任何二次配置。打包后直接docker-compose直接使用。也就是说,打包前0配置,打包后通过环境变量配置。

@nobodyiam
Copy link
Member

代码有冲突,麻烦解决一下

@xzxiaoshan
Copy link
Contributor Author

冲突已处理

@codecov-io
Copy link

codecov-io commented Jun 17, 2019

Codecov Report

Merging #2343 into master will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2343      +/-   ##
============================================
- Coverage     50.05%   49.97%   -0.08%     
+ Complexity     1992     1990       -2     
============================================
  Files           404      404              
  Lines         12429    12429              
  Branches       1275     1275              
============================================
- Hits           6221     6212       -9     
- Misses         5765     5773       +8     
- Partials        443      444       +1
Impacted Files Coverage Δ Complexity Δ
...work/apollo/biz/message/DatabaseMessageSender.java 56.25% <0%> (-10.42%) 6% <0%> (-2%)
...mework/apollo/portal/component/PortalSettings.java 65.07% <0%> (-4.77%) 5% <0%> (ø)
.../apollo/internals/RemoteConfigLongPollService.java 79.01% <0%> (-0.62%) 27% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b84f5b3...03c2c00. Read the comment docs.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 53.552% when pulling 03c2c00 on xzxiaoshan:dockerport into b84f5b3 on ctripcorp:master.

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nobodyiam nobodyiam merged commit 3bfed3c into apolloconfig:master Jun 18, 2019
@nobodyiam nobodyiam added this to the 1.5.0 milestone Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants