spring cloud+docker+jenkins 自动化构建(4)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.在eureka job中添加shell推送到docker registry

docker tag sm/eureka:2.0.0-SNAPSHOT 192.168.226.132:5000/sm/eureka:2.0.0-SNAPSHOT
docker push 192.168.226.132:5000/sm/eureka:2.0.0-SNAPSHOT
  1. 编写部署文件deploy-dev.yml
version: "3"
services:
  peer1:
    image: 192.168.226.132:5000/sm/eureka:2.0.0-SNAPSHOT
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8761:8761"
    networks:
      - springcloud-overlay
    environment:
      - spring.profiles.active=peer1,dev
  peer2:
    image: 192.168.226.132:5000/sm/eureka:2.0.0-SNAPSHOT
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8762:8762"
    networks:
      - springcloud-overlay
    environment:
      - spring.profiles.active=peer2,dev
  peer3:
    image: 192.168.226.132:5000/sm/eureka:2.0.0-SNAPSHOT
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8763:8763"
    networks:
      - springcloud-overlay
    environment:
      - spring.profiles.active=peer3,dev
networks:
  springcloud-overlay:

3.jenkins安装Publish Over SSH

4.配置Publish Over SSH

spring cloud+docker+jenkins 自动化构建(4)_第1张图片

5.新建job eureka_deploy,配置git略

6.构建->执行shell

cd Deploy/2.0/
dos2unix deploy-dev.yml

7.使用Publish Over SSH上传文件并执行远程shell

spring cloud+docker+jenkins 自动化构建(4)_第2张图片

8.查看控制台输出

[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/workspace/eureka_deploy
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://J.SM.MicroService.git # timeout=10
Fetching upstream changes from https://J.SM.MicroService.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress https://J.SM.MicroService.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/feature_v1.8^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/feature_v1.8^{commit} # timeout=10
Checking out Revision dbcadb6ecbb32598250a4daa84e07f5ff9e81b46 (refs/remotes/origin/feature_v1.8)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f dbcadb6ecbb32598250a4daa84e07f5ff9e81b46
 > git rev-list --no-walk dbcadb6ecbb32598250a4daa84e07f5ff9e81b46 # timeout=10
[eureka_deploy] $ /bin/sh -xe /tmp/jenkins5397675522317799624.sh
+ cd Deploy/2.0/
+ dos2unix deploy-dev.yml
dos2unix: converting file deploy-dev.yml to Unix format ...
SSH: Connecting from host [localhost.localdomain]
SSH: Connecting with configuration [docker swarm leader] ...
SSH: EXEC: STDOUT/STDERR from command [cd workspace/Deploy/2.0
docker stack deploy -c deploy-dev.yml sm
] ...
Updating service sm_peer1 (id: gwatimhwbhggoaua9pmsgt2nu)
Updating service sm_peer2 (id: amhjwzy3wf3dvr1ehncrenls0)
Updating service sm_peer3 (id: r0bjgtkdquui4is122x4cookk)
SSH: EXEC: completed after 1,003 ms
SSH: Disconnecting configuration [docker swarm leader] ...
SSH: Transferred 1 file(s)
Finished: SUCCESS

9.访问一下 http://192.168.226.128:8761/

spring cloud+docker+jenkins 自动化构建(4)_第3张图片

转载于:https://my.oschina.net/weidedong/blog/1825485

你可能感兴趣的:(java,运维,git)