本章用于讲解如何在walle下构建和运行JavaWeb。主要包含SpringBoot,ScalaAkkaWeb应用,以Java -jar和Docker运行两种方式(Tomcat方式不讲,你们自行研究)
项目中心 > 项目管理 > 新建项目
如下是一份配置好的项目表java
分组 | 项目 | 参考 | 备注 |
---|---|---|---|
基本配置 | 项目名称 | dev-个人JavaDemo项目 | 随便填写,名称不要太长(很差看),最好把环境卸载最前,例如dev(开发环境) |
基本配置 | 环境 | 开发环境 | 提早在环境管理配置好便可 |
基本配置 | Git Repo | git@gitlab.xxx.com:xxx/java-demo.git | Git仓库地址 |
目标集群 | 目标集群 | 192.168.0.122 | 提早配置服务器管理 |
目标集群 | 目标集群部署路径 | /data/walle-build/java-demo | 实际运行的环境 |
目标集群 | 目标集群部署仓库 | /data/walle-run | 会存放多个版本编译后的项目 |
目标集群 | 目标集群部署仓库版本保留数 | 5 | 能够回滚的版本数 |
Java生态下基本脚本大体一致,无细微差异node
任务配置 - 部署包含文件
包含方式python
docker-compose.yml target/${SERVER_NAME}.jar
该方式用于描述从源码包到发布包中,排除/包含的内容。通常java使用target便可linux
任务配置 - 自定义全局变量
# 运行目录 JAVA_HOME=/data/walle-java RUN_ROOT=/data/walle-run SERVER_NAME=java-demo MVN_HOME=/usr/local/maven3 PORT=2223
任务配置 - 高级任务-Deploy前置任务
pwd /usr/local/maven3//bin/mvn -v
任务配置 - 高级任务-Deploy后置任务
${MVN_HOME}/bin/mvn clean compile package -Dmaven.test.skip=true -DartifactId=${SERVER_NAME} # cp target/${SERVER_NAME}.jar . sed -i 's/${container_port}/'${PORT}'/g' docker-compose.yml sed -i 's/${container_name}/'${SERVER_NAME}'/g' docker-compose.yml
任务配置 - 高级任务-Release前置任务
docker-compose -p ${SERVER_NAME} -f ${WEBROOT}/docker-compose.yml down || echo "服务不存在" docker stop ${SERVER_NAME} || echo "服务不存在" docker rm ${SERVER_NAME} || echo "服务不存在" rm -rf ${WEBROOT}
任务配置 - 高级任务-Release后置任务
docker-compose -p ${SERVER_NAME} up -d echo "服务启动完成"
项目 - Maven pom.xml配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <build> <finalName>${artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.walle.main.DevelopToolApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> </execution> </executions> <configuration> <includeScope>system</includeScope> </configuration> </plugin> </plugins> </build> </project>
项目 - docker-compose.yml配置
version: '2' services: web: # 镜像:版本 image: openjdk:8-jdk container_name: ${container_name} ports: - "${container_port}:${container_port}" volumes: - ./target/${container_name}.jar:/usr/local/${container_name}.jar - /etc/localtime:/etc/localtime command: /bin/bash -c "echo "Asia/Shanghai" > /etc/timezone && java -Dserver.port=${container_port} -jar /usr/local/${container_name}.jar"
任务配置 - 高级任务-Deploy前置任务
pwd /usr/local/maven3//bin/mvn -v
任务配置 - 高级任务-Deploy后置任务
${MVN_HOME}/bin/mvn clean scala:compile compile package -Dmaven.test.skip=true -DartifactId=${SERVER_NAME} # cp target/${SERVER_NAME}.jar . sed -i 's/${container_host}/'${HOST}'/g' docker-compose.yml sed -i 's/${container_port}/'${PORT}'/g' docker-compose.yml sed -i 's/${container_name}/'${SERVER_NAME}'/g' docker-compose.yml
任务配置 - 高级任务-Release前置任务
docker-compose -p ${SERVER_NAME} -f ${WEBROOT}/docker-compose.yml down || echo "服务不存在" docker stop ${SERVER_NAME} || echo "服务不存在" docker rm ${SERVER_NAME} || echo "服务不存在" rm -rf ${WEBROOT}
任务配置 - 高级任务-Release后置任务
docker-compose -p ${SERVER_NAME} up -d echo "服务启动完成"
项目 - Maven pom.xml配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <build> <finalName>${artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.walle.main.DevelopToolApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>allinone</shadedClassifierName> <artifactSet> <includes> <include>*:*</include> </includes> </artifactSet> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>reference.conf</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>com.main.Boot</Main-Class> </manifestEntries> </transformer> </transformers> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> </execution> </executions> <configuration> <includeScope>system</includeScope> </configuration> </plugin> </plugins> </build> </project>
如为SpringBoot混合编译,则单独加上scala编译便可git
<plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <version>2.15.2</version> <executions> <execution> <goals> <goal>compile</goal> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>
项目 - docker-compose.yml配置
version: '2' services: web: # 镜像:版本 image: openjdk:8-jdk container_name: ${container_name} ports: - "${container_port}:${container_port}" volumes: - ./target/${container_name}.jar:/usr/local/${container_name}.jar - /etc/localtime:/etc/localtime command: /bin/bash -c "echo "Asia/Shanghai" > /etc/timezone && java -Dserver.port=${container_port} -jar /usr/local/${container_name}.jar"
任务配置 - 高级任务-Deploy前置任务
pwd /usr/local/maven3//bin/mvn -v
任务配置 - 高级任务-Deploy后置任务
${MVN_HOME}/bin/mvn clean scala:compile compile package -Dmaven.test.skip=true -DartifactId=${SERVER_NAME} # cp target/${SERVER_NAME}.jar .
任务配置 - 高级任务-Release前置任务
curl -X POST 127.0.0.1:${PORT}/shutdown || echo "服务不存在" rm -rf ${WEBROOT}
任务配置 - 高级任务-Release后置任务
java -Dserver.port=${PORT} -jar echo "服务启动完成"
上线通知
须要的话开启web
上线单是否开启审核
须要的话开启,会在审核后才能实际发布构建单spring
上诉内容完成后,是没法进行构建发版的。编译发版都是基于walle的docker容器,python下完成的。该环境下无java和maven变量
咱们有两个方式解决 宿主机映射 or 从新打包镜像docker
此处只讲解宿主机映射的方式(更推荐从新打包镜像)apache
咱们在宿主机安装完成maven,java,node等环境,而后修改walle的docker-compose便可npm
# docker version: 18.06.0+ # docker-compose version: 1.23.2+ # OpenSSL version: OpenSSL 1.1.0h version: "3.7" services: python: image: alenx/walle-python:2.1 container_name: walle-python hostname: walle-python env_file: # walle.env需和docker-compose在同级目录 - ./walle.env command: bash -c "ln -sf /data/walle-tool/node-v10.5.0-linux-x64/bin/node /usr/bin/node && ln -sf /data/walle-tool/node-v10.5.0-linux-x64/bin/npm /usr/bin/npm && cd /opt/walle_home/ && /bin/bash admin.sh migration && python waller.py " expose: - "5000" volumes: - /opt/walle_home/plugins/:/opt/walle_home/plugins/ - /opt/walle_home/codebase/:/opt/walle_home/codebase/ - /opt/walle_home/logs/:/opt/walle_home/logs/ - /data/walle-build/:/walle/walle-build/ - /data/walle-java/:/walle/walle-java/ - /usr/local/maven3/:/usr/local/maven3/ - /data/walle-run/:/data/walle-run/ - /usr/bin/netstat:/usr/bin/netstat/ - /root/.ssh:/root/.ssh/ - /data/walle-tool/node-v10.5.0-linux-x64/:/data/walle-tool/node-v10.5.0-linux-x64/
进入从宿主机进入python,查看mvn,java,linux是否可用
链接git
配置git ssh在宿主机(docker-compose-python,映射了ssh目录),保证能免密码拉去代码便可
链接服务器
配置服务器的 ssh在宿主机,保证能免密码登陆各服务器便可
部署管理 - 新建上线单
选择环境和分支便可,回到列表页,点击上线查看详情,再次点击详情页上线便可开始发布