首页 > 其他分享 >多环境打包部署

多环境打包部署

时间:2023-05-03 22:55:56浏览次数:43  
标签:03 12596 05 部署 54 环境 19 main 打包

参考资料:

(180条消息) maven-assembly-plugin插件_dependencysets_Doctor舒畅的博客-CSDN博客

虽然前面的工程已经可以提供接口了,但是还不算完整的具备基础工程能力。

工程包含CICD,能够适配多环境配置和打出可用的二进制包才算完整

  • 配置文件
  • pom多profile配置
  • 其他打包配置
  • 常见启动命令
  • 手工发包部署(本质上自动化程序只不过是手工上的封装而已)

config目录下增加配置文件

  • application.properties
  • application-sit.properties

也有一些喜欢使用yml,但是经过自动化发现,并不太好用。

  • yml 层次分明,但是格式要求严格
  • properties没有缩进问题,但是不太好归类

application.properties

[email protected]@
server.servlet.context-path=/test
server.port=10004
server.servlet.encoding.charset=utf-8

application-sit.properties暂时空白

启动:

配置已经生效了

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.8.RELEASE)

2023-05-03 19:54:00.553  INFO 12596 --- [           main] com.wht.test.TestAppStart                : Starting TestAppStart on DESKTOP-TVKIOH9 with PID 12596 (D:\workspace\java\SpringBootWebTest\target\classes started by 13355 in D:\workspace\java\SpringBootWebTest)
2023-05-03 19:54:00.553  INFO 12596 --- [           main] com.wht.test.TestAppStart                : No active profile set, falling back to default profiles: default
2023-05-03 19:54:01.708  INFO 12596 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 10004 (http)
2023-05-03 19:54:01.724  INFO 12596 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-05-03 19:54:01.724  INFO 12596 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2023-05-03 19:54:01.823  INFO 12596 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/test]   : Initializing Spring embedded WebApplicationContext
2023-05-03 19:54:01.823  INFO 12596 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1222 ms
2023-05-03 19:54:01.978  INFO 12596 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2023-05-03 19:54:02.137  INFO 12596 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 10004 (http) with context path '/test'
2023-05-03 19:54:02.153  INFO 12596 --- [           main] com.wht.test.TestAppStart                : Started TestAppStart in 2.027 seconds (JVM running for 2.509)

pom中体现多环境

这样就支持多环境了

    <profiles>
        <profile>
            <id>sit</id>
            <properties>
                <profies.active>sit</profies.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
    </profiles>

打包支持多环境

主要build这里有大量的插件,后续补充基础基础知识

    <build>
        <finalName>test</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/*.xlsx</exclude>
                    <exclude>application.properties</exclude>
                    <exclude>application-sit.properties</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*.xlsx</include>
                </includes>

            </resource>
            <resource>
                <directory>config</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xlsx</include>
                    <include>application.properties</include>
                    <include>application-sit.properties</include>
                </includes>
                <targetPath>${project.build.directory}/config</targetPath>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>/src/main/assembly/descriptor.xml</descriptor>
                    </descriptors>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <type>jar</type>
                            <includeTypes>jar</includeTypes>
                            <outputDirectory>${project.build.directory}/libs</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

descriptor.xml配置

为了支持打出jar包和tar.gz包

<assembly>
    <id>descriptor</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>./src/main/shell</directory>
            <outputDirectory>/libs</outputDirectory>
            <fileMode>755</fileMode>
            <includes>
                <include>*.sh</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>./target</directory>
            <outputDirectory>/libs</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>./target/config</directory>
            <outputDirectory>/libs/config</outputDirectory>
            <includes>
                <include>*.properties</include>
                <include>*.ds</include>
            </includes>
            <directoryMode>0600</directoryMode>
            <fileMode>0600</fileMode>
        </fileSet>
    </fileSets>
</assembly>

启动脚本control.sh

每个包中放一个启动脚本是否方便OS类部署

对于自动化部署可以参考

#!/bin/bash
JAR_NAME=test.jar
CURPATH=$(cd "$(dirname "$0")";pwd)

cd $CURPATH

pid=`ps -ef|grep ${JAR_NAME}|grep -V grep|grep -v kill |awk '{print $2}'`
if [ ${pid} ]; then
  echo "strop ${JAR_NAME}....................."
  kill -9 $pid
else
  echo "${JAR_NAME} is not running.................."
fi
sleep 2

pid=`ps -ef|grep ${JAR_NAME}|grep -V grep|grep -v kill |awk '{print $2}'`
if [ ${pid} ]; then
  echo "${JAR_NAME} still running....................."
else
  echo "${JAR_NAME} is not running.................."
fi
sleep 2

nohup java -jar -Dserver.port=1005 ${JAR_NAME} --spring.profiles.active=$1 >test.log 2>&1 &
echo "start ${JAR_NAME} ..............."
sleep 3
tail -1000f test.log

linux手工部署

访问验证

问题记录及处理

1、打包失败 lombak无法编译

mvn clean package -Psit
  • lombak内部写死了很多虚拟机基础工具,他的编译依赖javac真正的版本
  • mvn说白了立即窗口可以运行是因为他是外部软件,依赖windows path中指定的java版本
  • windows中有个默认的oracle下的jre,可能是17版本,要从系统环境变量配置path中删除
  • 配置自己的java版本的环境变量
  • 再次运行 mv命令

2、配置文件变量没替换

3、idea中缺少springboot启动配置

标签:03,12596,05,部署,54,环境,19,main,打包
From: https://www.cnblogs.com/hcgk/p/17369854.html

相关文章

  • Tomcat7安装基于jdk 1.7环境
    这篇文章着重讲解tomcat7的安装,首先需要下载tomcat包和相应的jdk,如果你的系统是32位,那么下载x86的jdk,如果是64位的系统,那么下载X64的JDK。tomcat7安装1、查看系统版本 #uname–a//是64位系统,那么我们选择64位的JDKLinux2.6.32-71.el6.x86_64#1SMPFriMay2003......
  • Tomcat7安装基于jdk 1.7环境
    这篇文章着重讲解tomcat7的安装,首先需要下载tomcat包和相应的jdk,如果你的系统是32位,那么下载x86的jdk,如果是64位的系统,那么下载X64的JDK。tomcat7安装1、查看系统版本 #uname–a//是64位系统,那么我们选择64位的JDKLinux2.6.32-71.el6.x86_64#1SMPFriMay2003......
  • Tomcat7安装基于jdk 1.7环境
    这篇文章着重讲解tomcat7的安装,首先需要下载tomcat包和相应的jdk,如果你的系统是32位,那么下载x86的jdk,如果是64位的系统,那么下载X64的JDK。tomcat7安装1、查看系统版本 #uname–a//是64位系统,那么我们选择64位的JDKLinux2.6.32-71.el6.x86_64#1SMPFriMay2003......
  • linux-kubernetes(二进制部署)
    参考笔记:https://www.cnblogs.com/yinzhengjie/p/17069566.html一、环境准备准备5台机器,二进制部署K8S高可用集群:主机ipk8s-master0110.0.0.201k8s-master0210.0.0.202k8s-master0310.0.0.203k8s-node0110.0.0.204k8s-node0210.0.0.205二、K8S......
  • linux-部署harbor的https认证
    一、安装docker1.下载docker的rpm包[[email protected]~]#ll-rw-r--r--1rootroot101239922Apr1215:29docker-rpm-20_10_24.tar.gz2.解压并安装软件包[[email protected]~]#tarxfdocker-rpm-20_10_24.tar.gz[[email protected]~]#......
  • Windows环境安装Elasticsearch和Kibana
    目录1Elasticsearch1.1下载1.2解压并添加环境变量1.3访问1.4cmd命令1.5中文分词器1.5.1下载1.5.2安装1.5.2.1命令安装1.5.2.2手动安装1.5.2.3验证分词1.6使用curl批量导入2安装kibana2.1下载kibana2.2中文界面2.3操作索引2.3.1增加索引2.3.1.1单条新增2.3.1.2......
  • 魔兽服务端编译部署NPCBots和机器人模块教程
    魔兽服务端编译部署NPCBots和机器人模块教程大家好,我是艾西。在平时自己一个人玩魔兽的时候是不是会比较无聊,因为游戏机制或副本难度自己一个人无法进行快乐的玩耍。今天艾西教大家编译部署NPCBots和Al机器人模块,直接一个人玩魔兽也不孤单首先到GIT去下载ai机器人以及bots模块解压......
  • AI 作画火了,如何用 Serverless 函数计算部署 Stable Diffusion?
    作者:寒斜立即体验基于函数计算部署StableDiffusion:https://developer.aliyun.com/topic/aigcAIGC领域目前大火,除了Chatgpt,在文生图领域StableDiffusion大放异彩,深刻的地影响着绘画、视频制作等相关领域。利用这项技术,普通人也可以制作出令人惊叹的艺术作品。今天我们将......
  • 虚拟机环境下,LVS DR模式实现(极简模式)
    环境准备总共使用5台虚拟机进行模拟实现:Client1台,用以模仿访问服务的终端路由服务器1台,用以连接LVS集群和进行访问转发LVS服务器1台后端Web服务器2台IP分配和网络拓扑如下:注:共有3个网段:客户端访问(192.168.0.0),访问LVS服务器,Web服务器,路由器所用的RIP网段(192.168.127.0),VIP网段(19......
  • kubevirt实验部署:k8s1.23.17+kube-ovn+nfs+kubevirt+ceph 集成使用
    标签(空格分隔):kubernetes系列一:kubevirt的简介KubeVirt是一个Kubernetes插件,它为Kubernetes提供了在与容器相同的基础结构上提供、管理和控制虚拟机的能力。KubeVirt是由云原生计算基金会(CNCF)赞助的开源项目,目前正处于孵化阶段。KubeVirt使Kubernetes能够使用与容器化工作负......