Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/litongjava/deploy-server

deploy-server
https://github.com/litongjava/deploy-server

Last synced: about 1 month ago
JSON representation

deploy-server

Awesome Lists containing this project

README

        

# deploy-server
# 1.简介
deploy-server是一款使用go语言开发用于自动部署的服务
主要功能
- 将运行命令通过base54加密发送到服务端,服务器端通过base54进行解密,解密后执行命令
- 支持文件上传和解压(用于部署前端项目)
- 支持文件上传,解压和运行命令(用于部署后台项目)

主要业务逻辑
- 接受上传文件,解压,移动到指定目录,并执行启动命令

# 2.安装
## 2.1.安装服务端
下载
```
mkdir -p /data/package/
cd /data/package/
wget https://github.com/litongjava/deploy-server/releases/download/v0.1.0/deploy-server-linux-amd64.zip
```

解压
```
unzip deploy-server-linux-amd64-1.0.0.zip -d /opt
mv deploy-server-linux-amd64 deploy-server
```

启动
```
cd /opt/deploy-server
chmod u+x deploy-server
/opt/deploy-server/deploy-server
```
测试服务是否启动成功
```
curl http://localhost:10405/status
```

## 2.2.配置开机启动
使用root用户
```
vi /etc/systemd/system/deploy-server.service
```

```
[Unit]
Description=deploy-server
After=network.target

[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
WorkingDirectory = /opt/deploy-server
ExecStart=/opt/deploy-server/deploy-server

[Install]
WantedBy=multi-user.target
```

使用appadmin用户启动
```
vi /etc/systemd/system/deploy-server.service
```

```
[Unit]
Description=deploy-server
After=network.target

[Service]
Type=simple
User=appadmin
Restart=on-failure
RestartSec=5s
WorkingDirectory = /home/appadmin/opt/deploy-server
ExecStart=/home=/home/appadmin/opt/deploy-server/deploy-server

[Install]
WantedBy=multi-user.target
```
启动
```
sudo systemctl daemon-reload
sudo systemctl enable deploy-server
sudo systemctl start deploy-server
sudo systemctl status deploy-server
sudo systemctl stop deploy-server
sudo systemctl restart deploy-server
```
## 2.3.配置nginx
使用nginx代理deploy-server
```
location /deploy-server/ {
proxy_pass http://localhost:10405/;
proxy_pass_header Set-Cookie;
proxy_set_header Host $host;
}
```

测试
```
curl http://localhost/deploy-server/status
```

指定代理前缀路径,代理前缀路径通常是工程命令,例如robot-api
```
location /robot-api/deploy-server/ {
proxy_pass http://localhost:10405/;
proxy_pass_header Set-Cookie;
proxy_set_header Host $host;
}
```

测试
```
curl http://localhost/robot-api/deploy-server/status
```

# 3.使用
## 3.1.部署Spring-boot项目
### 3.1.1.修改Spring-boot项目
添加src/main/resources/loader.properties
```
# 配置启动时外置依赖加载目录,只加载应用根目录下的lib/
loader.path=file:./lib
```

修改pom.xml的properties添加assembly,spring-boot.version和main.class
```
2.5.6
full

com.xxx.ServiceTestApplication

```
修改pom.xml的build的plugins配置
pring-boot-maven-plugin
maven-dependency-plugin
maven-assembly-plugin
```



org.springframework.boot
spring-boot-maven-plugin
${spring-boot.version}


true

${main.class}

ZIP


org.psyduck
psyduck-admin






repackage






org.apache.maven.plugins
maven-dependency-plugin
3.2.0


copy-dependencies
prepare-package

copy-dependencies



${project.build.directory}/lib


org.psyduck



runtime







org.apache.maven.plugins
maven-assembly-plugin
3.3.0


false

assembly-${assembly}.xml




make-assembly
package

single






```
在项目根目录下添加assembly文件
assembly-full.xml
```

zipPackage

zip

false


${project.build.directory}
${file.separator}

*.jar




${project.build.directory}/lib
lib

*.jar



${basedir}/src/main/bin
unix


755

*.sh
*.service


${project.build.directory}/../../native-config
config

*.yml


```
assembly-thin.xml
```

zipPackage

zip

false


${project.build.directory}
${file.separator}

*.jar


${project.build.directory}/../../native-config
config

*.yml


```
### 3.1.2.构建Spring-boot项目

全量包:
```
set JAVA_HOME=D:\\dev_program\\java\\jdk1.8.0_121
mvnd clean package -DskipTests -Dassembly=full
```
瘦子包:
```
set JAVA_HOME=D:\\dev_program\\java\\jdk1.8.0_121
mvnd clean package -DskipTests -Dassembly=thin
```
构建完成后会生成
target\spring-boot-table-to-json-1.0.zip
第一次不是打包成全量包后续部署如果依赖没有变化可以打包成瘦子包
### 3.1.3.基于python脚本部署Spring-Boot项目
添加python脚本到服务器
```
mkdir -p /data/apps/webapps/package/
cd /data/apps/webapps/package/
wget https://raw.githubusercontent.com/litongjava/deploy-server/main/script/deploy-root.py
```

客户端发送命令调用脚本进行部署
添加upload-run.bat内容如下
```
set JAVA_HOME=D:\\dev_program\\java\\jdk1.8.0_121
mvnd clean package -DskipTests -Dassembly=thin
ping-base64-client -url http://192.168.3.9:10405/file/upload-run/ -file target\spring-boot-table-to-json-1.0.zip -m /data/apps/webapps/package -c "python2.7 /data/apps/webapps/package/deploy-root.py -s spring-boot -m spring-boot-table-to-json -pg spring-boot-table-to-json-1.0.zip -p 8021 -a update"
```
输出"success":true 表示部署成功
这里使用了ping-base64-client
https://github.com/litongjava/ping-base64-client

部署的项目是spring-boot-table-to-json
https://github.com/litongjava/table-to-json/tree/main/spring-boot-table-to-json

### 3.1.4.基于Docker部署Spring-Boot项目
首次部署
将文件上传到服务器上,解压并启动docker容器
upload-start-docker.bat
```
ping-base64-client -url http://192.168.3.9:10405/file/upload-run/ -file target\spring-boot-table-to-json-1.0.zip -m /data/apps/webapps/package -d /data/apps/webapps/spring-boot-table-to-json -c "docker run --name spring-boot-table-json -dit -v /data/apps/webapps/spring-boot-table-to-json:/app --net=host -w /app litongjava/jdk:8u211 /usr/java/jdk1.8.0_211/bin/java -jar spring-boot-table-to-json-1.0.jar"
```

执行docker部署命令如下,用于启动工程
```
docker run --name spring-boot-table-json -dit -v /data/apps/webapps/spring-boot-table-to-json:/app --net=host -w /app litongjava/jdk:8u211 /usr/java/jdk1.8.0_211/bin/java -jar spring-boot-table-to-json-1.0.jar
```

更新
将文件上传到服务器上,解压并重启docker容器
```
ping-base64-client -url http://192.168.3.9:10405/file/upload-run/ -file target\spring-boot-table-to-json-1.0.zip -m /data/apps/webapps/package -d /data/apps/webapps/spring-boot-table-to-json -c "docker restart spring-boot-table-json"
```