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/apphtml
ENTRYPOINT ["/bin/sh","/usr/scripts/start.sh"]java
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:nginx
variables:
PROJECT_NAME: visagit
build_test_docker:
stage: build
script:web
- 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
- docker stack deploy -c deploy/deploy.test.yml visa_service_test
tags:
- cyjavatest
only:
- /^release-*/
build_master_docker:
stage: build
script:shell
- 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: json
- 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:vim
- "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
這裏的配置中心採用nginx 的autoindex on 這個功能tomcat
寫一個dockerfile: docker-compose.yml
nginx:
image: nginx
privileged: false
restart: always
ports:
- 80:80
- 1001:1001
- 1002:1002
- 1003:1003
- 1004:1004
- 1005:1005
- 1006:1006
- 1007:1007
volumes:
- ./data/conf.d:/etc/nginx/conf.d
- ./data/html:/usr/share/nginx/html