maven,git python脚本 自动化 部署 spring boot进销存系统

准备环境

虚拟机两台

centos 7.2 192.168.255.128

centos 7.2 192.168.255.129

maven 3.0.5

java 1.8.0_181

git version 1.8.3.1

安装 git 
yum install git
初始化git
git  config  --global  user.name  "laoqian666"
git  config  --global  user.email  "[email protected]"
ssh-keygen  -t  rsa  -C  "[email protected]"
将Git 证书配置到github 上,保证linux服务器与码云 之间可以
  头像 -- 设置 -- >>
  cd ~/.ssh  把公钥文件粘贴到对话框中

Python 2.7.5

项目地址:https://gitee.com/shenduedu/JXC.git 要在自行配好数据库环境

centos 192.168.255.128 装上 maven,java,git

centos 192.168.255.129 装上 java

环境安装  此处不再累赘

注意:

1 因为要远程执行,所以要在两台虚拟机上配置ssh key

ssh-keygen -t rsa

一路按回车,然后将生成的公钥复制到 129机器上

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

2 要在码云好配置好公钥

因为要用git 拉代码

执行任务时主要流程是

1 先从git 上pull 代码 到指定文件夹

2 然后 用maven 进行打包

3 使用scp 把打包后的文件 复制到对应服务器上

4 然后执行

为可方便演示,我代码都是采用硬编码的方式,请读者们谅解

python 脚本

# -*- coding: UTF-8 -*-

import os
import sys

if os.path.exists('/usr/local/deployer.lock'):
    print '程序正在执行.................'
    sys.exit(1)

file = open('/usr/local/' + 'deployer' + '.lock','w')
file.close()


res = os.system('rm -rf /usr/local/gitsource/*')
if res != 0:
    print 'delete gitsource files fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('cd /usr/local/gitsource/ &&  git clone https://gitee.com/shenduedu/JXC.git')
if res != 0:
    print 'https://gitee.com/shenduedu/JXC.git fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('cd /usr/local/gitsource/JXC/ &&  mvn clean package')
if res != 0:
    print 'mvn package fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('ssh [email protected] "rm -rf /opt/project/*"')

res = os.system('scp /usr/local/gitsource/JXC/target/JXC-0.0.1-SNAPSHOT.war 192.168.255.129:/opt/project/')

res = os.system('ssh [email protected] "cd /opt/project && java -jar JXC-0.0.1-SNAPSHOT.war"')

res =os.remove('/usr/local/deployer.lock')

此时 执行http://192.168.255.129/

欢迎加入 微服务交流群

222700500

猜你喜欢

转载自blog.csdn.net/weixin_39639119/article/details/82828906