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 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 Jun 14, 2019
…定端口,避免与宿主机上的原有端口占用冲突

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

This comment has been minimized.

Copy link
Contributor Author

xzxiaoshan commented Jun 17, 2019

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

@xzxiaoshan

This comment has been minimized.

Copy link
Contributor Author

xzxiaoshan commented Jun 17, 2019

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

@nobodyiam

This comment has been minimized.

Copy link
Collaborator

nobodyiam commented Jun 17, 2019

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

@xzxiaoshan

This comment has been minimized.

Copy link
Contributor Author

xzxiaoshan commented Jun 17, 2019

冲突已处理

@codecov-io

This comment has been minimized.

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

This comment has been minimized.

Copy link

coveralls commented Jun 17, 2019

Coverage Status

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

Copy link
Collaborator

nobodyiam left a comment

LGTM

@nobodyiam nobodyiam merged commit 3bfed3c into ctripcorp:master Jun 18, 2019
2 of 4 checks passed
2 of 4 checks passed
codecov/project 49.97% (-0.08%) compared to b84f5b3
Details
coverage/coveralls Coverage decreased (-0.06%) to 53.552%
Details
codecov/patch Coverage not affected when comparing b84f5b3...03c2c00
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@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
Projects
None yet
4 participants
You can’t perform that action at this time.