1. 程式人生 > >微服務小範圍發布影響小

微服務小範圍發布影響小

size package service run log ble uil deploy main

1 看下項目結構,技術分享圖片首先要有dockerfile,
FROM git.we3tu.com:5000/tomcatmaven:latest
RUN apk --update add wget
RUN mkdir -p /usr/src/app
RUN mkdir -p /usr/scripts
RUN mkdir -p /www
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN unzip /usr/src/app/target/visa.war -d /opt/tomcat/webapps/ROOT
RUN cp /usr/src/app/start.sh /usr/scripts
RUN rm -rf /usr/src/app

ENTRYPOINT ["/bin/sh","/usr/scripts/start.sh"]

2 關於應用的配置文件用變量傳遞下載到測試環境或生產環境
vim start.sh
#! /bin/sh
wget http://$DOMAIN_ENV.config.we3tu.com/$PROJECTNAME/dev/application.properties -O /opt/tomcat/webapps/ROOT/WEB-INF/classes/dev/application.properties 測試環境配置文件路徑
wget http://$DOMAIN_ENV.config.we3tu.com/$PROJECTNAME/pro/application.properties -O /opt/tomcat/webapps/ROOT/WEB-INF/classes/pro/application.properties 生產環境配置文件路徑

wget http://$DOMAIN_ENV.config.we3tu.com/$PROJECTNAME/applicationContext.xml -O /opt/tomcat/webapps/ROOT/WEB-INF/classes/applicationContext.xml
/opt/tomcat/bin/catalina.sh run
3 vim .gitlab-ci.yml
stages:

  • build
  • deploy

variables:
PROJECT_NAME: visa

build_test_docker:
stage: build
script:

  • mvn package -Dmaven.test.skip=true
  • docker build -f Dockerfile -t $PROJECT_NAME .
  • docker tag $PROJECT_NAME git.we2tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
  • docker push git.we3tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
    tags:
  • cyjavatest
    only:
  • /^release-*/

deploy_test_docker:
stage: deploy
script:

  • docker stack deploy -c deploy/deploy.test.yml visa_service_test
    tags:
  • cyjavatest
    only:
  • /^release-*/

build_master_docker:
stage: build
script:

  • mvn clean package -Dmaven.test.skip=true
  • docker build -f Dockerfile -t $PROJECT_NAME .
  • docker tag $PROJECT_NAME git.we2tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
  • docker tag $PROJECT_NAME git.we2tu.com:5000/$PROJECT_NAME:latest
  • docker push git.we3tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
  • docker push git.we3tu.com:5000/$PROJECT_NAME:latest
    tags:
  • erpjavabuild
    only:
  • master

deploy_prod_docker:
stage: deploy
script:

  • docker stack deploy -c deploy/deploy.prod.yml visa_service
    tags:
  • erpprodshell
    only:
  • master
    4 部署的路徑怎麽部署:
    vim deploy.test.yml
    version: ‘3‘
    services:
    visa_service_test:
    image: git.we3tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
    environment:
    • "DOMAIN_ENV=test"
    • "PROJECTNAME=visa"
    • "QUARTZ_ENV=noquartz"
      logging:
      driver: syslog
      options:
      syslog-address: "tcp://x.x.x.x:5514"
      tag: $PROJECT_NAME
      ports:
    • 8021:8080
      deploy:
      replicas: 1
      update_config:
      parallelism: 1
      delay: 10s
      restart_policy:
      condition: any
      networks:
    • docker-cy-test
      networks:
      docker-cy-test:
      external: true

5 vim deploy.prod.yml
version: ‘3‘
services:
visa_service:
image: git.we3tu.com:5000/$PROJECT_NAME:$CI_COMMIT_REF_NAME
environment:

  • "DOMAIN_ENV=prod"
  • "PROJECTNAME=visa"
  • "QUARTZ_ENV=noquartz"
    logging:
    driver: json-file
    ports:
  • 8021:8080
    deploy:
    replicas: 2
    update_config:
    parallelism: 1
    delay: 10s
    restart_policy:
    condition: any
    max_attempts: 10
    networks:
  • prod-net
    networks:
    prod-net:
    external: true

微服務小範圍發布影響小