easier-framework-parent
Used in:
components
- OverviewOverview
- VersionsVersions
- DependentsDependents
- DependenciesDependencies
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-parent</artifactId>
<version>2.7.2023.1</version>
</dependency><?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/>
</parent>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-parent</artifactId>
<version>2.7.2023.1</version>
<packaging>pom</packaging>
<url>https://github.com/lizhian/easier-framework</url>
<licenses>
<license>
<name>GNU General Public License version 3</name>
<url>https://opensource.org/licenses/GPL-3.0</url>
</license>
</licenses>
<scm>
<url>https://github.com/lizhian/easier-framework</url>
<connection>https://github.com/lizhian/easier-framework.git</connection>
</scm>
<developers>
<developer>
<id>lizhian</id>
<name>lizhian</name>
<email>503457938@qq.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<modules>
<module>easier-framework-core</module>
<module>easier-framework-starter-env</module>
<module>easier-framework-starter-jackson</module>
<module>easier-framework-starter-cache</module>
<module>easier-framework-starter-job</module>
<module>easier-framework-starter-logging</module>
<module>easier-framework-starter-rpc</module>
<!--<module>easier-framework-starter-inner-request</module>-->
<!--<module>easier-framework-starter-gateway</module>-->
<!--<module>easier-framework-starter-mock</module>-->
<module>easier-framework-starter-mq</module>
<module>easier-framework-starter-mybatis</module>
<!--<module>easier-framework-starter-swagger</module>-->
<module>easier-framework-starter-doc</module>
<module>easier-framework-starter-auth</module>
<module>easier-framework-starter-discovery</module>
<module>easier-framework-starter-web</module>
<module>easier-framework-application</module>
<module>easier-framework-application-web</module>
<module>user-center-interfaces</module>
<module>user-center-application</module>
<module>easier-framework-maven-plugin</module>
<!--<module>easier-framework-test</module>-->
</modules>
<properties>
<!--构建.sh文件时候用到的参数-->
<jvm>-Xms64m -Xmx256m</jvm>
<env/>
<args/>
<!--构建jar.sh文件的参数-->
<jar.sh.application>${project.build.finalName}.jar</jar.sh.application>
<jar.sh.jvm>${jvm}</jar.sh.jvm>
<jar.sh.env>${env}</jar.sh.env>
<jar.sh.args>${args}</jar.sh.args>
<jar.sh.log_file>logs/console.log</jar.sh.log_file>
<jar.sh.output>/dev/null</jar.sh.output>
<!--执行docker build的参数-->
<docker.skip>false</docker.skip>
<docker.registry/>
<!--暴露端口多个时候使用空格间隔-->
<docker.expose_ports>0</docker.expose_ports>
<docker.from>eclipse-temurin:8-jre-focal</docker.from>
<docker.workdir>/home</docker.workdir>
<docker.application-jar>${project.build.finalName}.jar</docker.application-jar>
<docker.image>${project.groupId}/${project.artifactId}</docker.image>
<!--suppress UnresolvedMavenProperty -->
<docker.tag>${yyyy}.${MM}${dd}.${HH}${mm}</docker.tag>
<docker.dockerfile-command1/>
<docker.dockerfile-command2/>
<docker.dockerfile-command3/>
<docker.dockerfile-command4/>
<docker.dockerfile-command5/>
<docker.build-command1/>
<docker.build-command2/>
<docker.build-command3/>
<docker.build-command4/>
<docker.build-command5/>
<docker.push-command/>
<!--构建docker.sh文件的参数-->
<docker.sh.application>${project.artifactId}</docker.sh.application>
<docker.sh.image>${docker.image}</docker.sh.image>
<docker.sh.tag>${docker.tag}</docker.sh.tag>
<docker.sh.jvm>${jvm}</docker.sh.jvm>
<docker.sh.env>${env}</docker.sh.env>
<docker.sh.args>${args}</docker.sh.args>
<docker.sh.expose_ports>${docker.expose_ports}</docker.sh.expose_ports>
<docker.sh.workdir>${docker.workdir}</docker.sh.workdir>
<!--项目配置-->
<java.version>1.8</java.version>
<kotlin.version>1.8.20</kotlin.version>
<resource.delimiter>@</resource.delimiter>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.7.12</spring-boot.version>
<spring-boot-admin.version>2.7.10</spring-boot-admin.version>
<spring-cloud.version>2021.0.7</spring-cloud.version>
<easier-framework.version>2.7.2023.1</easier-framework.version>
<sa-token.version>1.34.0</sa-token.version>
<hutool.version>5.8.19</hutool.version>
<guava.version>32.0.1-jre</guava.version>
<oshi-core.version>6.4.3</oshi-core.version>
<plumelog.version>3.5.3</plumelog.version>
<hessian.version>4.0.66</hessian.version>
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
<mybatis-plus-ext.version>${mybatis-plus.version}-EXT420</mybatis-plus-ext.version>
<mybatis-plus-join.version>1.4.5</mybatis-plus-join.version>
<dynamic-datasource.version>3.6.1</dynamic-datasource.version>
<redisson.version>3.23.4</redisson.version>
<okhttps.version>4.0.1</okhttps.version>
<okio.version>2.8.0</okio.version>
<jasypt.version>3.0.5</jasypt.version>
<reactor.version>3.5.3</reactor.version>
<reactor-core.version>${reactor.version}</reactor-core.version>
</properties>
<dependencyManagement>
<dependencies>
<!--项目依赖-->
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-core</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-env</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-jackson</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-job</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-cache</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<!--<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-inner-request</artifactId>
<version>${easier-framework.version}</version>
</dependency>-->
<!--<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-gateway</artifactId>
<version>${easier-framework.version}</version>
</dependency>-->
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-web</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<!--<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-mock</artifactId>
<version>${easier-framework.version}</version>
</dependency>-->
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-mq</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-mybatis</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<!--<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-swagger</artifactId>
<version>${easier-framework.version}</version>
</dependency>-->
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-doc</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-auth</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-logging</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-starter-discovery</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-application</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<dependency>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-application-web</artifactId>
<version>${easier-framework.version}</version>
</dependency>
<!--项目依赖 end-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-dependencies</artifactId>
<version>${sa-token.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-core</artifactId>
<version>${sa-token.version}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>${sa-token.version}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-oauth2</artifactId>
<version>${sa-token.version}</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>${oshi-core.version}</version>
</dependency>
<dependency>
<groupId>com.plumelog</groupId>
<artifactId>plumelog-core</artifactId>
<version>${plumelog.version}</version>
</dependency>
<dependency>
<groupId>com.plumelog</groupId>
<artifactId>plumelog-logback</artifactId>
<version>${plumelog.version}</version>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>${hessian.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-magic</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-annotation</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-autotable-annotation</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-datasource-annotation</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-bind-annotation</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-condition-annotation</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.tangzc</groupId>
<artifactId>mybatis-plus-ext-boot-starter</artifactId>
<version>${mybatis-plus-ext.version}</version>
</dependency>
<dependency>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-annotation</artifactId>
<version>${mybatis-plus-join.version}</version>
</dependency>
<dependency>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join-boot-starter</artifactId>
<version>${mybatis-plus-join.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>${dynamic-datasource.version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>okhttps</artifactId>
<version>${okhttps.version}</version>
</dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>okhttps-jackson</artifactId>
<version>${okhttps.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>${okio.version}</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${jasypt.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<javaParameters>true</javaParameters>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>lombok</plugin>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-lombok</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-to-config-folder</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/config</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/application*.yml</include>
<include>**/application*.yaml</include>
<include>**/application*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>local</env>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>generate-jar-sh</id>
<build>
<plugins>
<plugin>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-maven-plugin</artifactId>
<version>${easier-framework.version}</version>
<executions>
<execution>
<id>generate-jar-sh</id>
<phase>package</phase>
<goals>
<goal>generate-file</goal>
</goals>
<configuration>
<conditionOnPlugin>spring-boot-maven-plugin</conditionOnPlugin>
<outputDirectory>${project.build.directory}</outputDirectory>
<fileName>jar.sh</fileName>
<content><![CDATA[
#!/bin/bash
application=${jar.sh.application}
env="${jar.sh.env}"
jvm="${jar.sh.jvm}"
args="${jar.sh.args}"
output=${jar.sh.output}
log_file=${jar.sh.log_file}
tail_f=false
tail_keyword=""
#查看状态
status() {
PID=$(pgrep -f $application)
if [ -n "$PID" ]; then
echo && echo "已找到应用进程 $application -> $PID"
ps aux | grep -v grep | grep " PID \| $PID "
else
echo && echo "未找到应用进程 $application"
fi
}
#启动
start() {
PID=$(pgrep -f $application)
if [ -n "$PID" ]; then
status
echo "启动应用失败"
exit 1
fi
echo && echo "开始启动应用 $application"
# 输出 JVM 参数设置
if [ -n "$jvm" ]; then
echo "jvm 参数: $jvm"
fi
# 设置 Spring Boot 的启动环境
if [ -n "$env" ]; then
echo "env 参数: $env"
args="--spring.profiles.active=$env $args"
fi
# 设置 Spring Boot 的启动参数
if [ -n "$args" ]; then
echo "启动参数: $args"
fi
echo && echo "启动应用指令: nohup java $jvm -jar $application $args > $output 2>&1 &"
nohup java $jvm -jar $application $args > $output 2>&1 &
sleep 3
PID=$(pgrep -f $application)
if [ -n "$PID" ]; then
status
echo && echo "启动应用成功"
if [ "$tail_f" = true ]; then
log
fi
else
echo && echo "启动应用失败"
exit 1
fi
}
#停止
stop() {
PID=$(pgrep -f $application)
if [ -n "$PID" ]; then
status
echo && echo "开始停止应用..."
kill -TERM "$PID"
# 使用 while 循环等待进程停止
while ps -p "$PID" > /dev/null; do
echo "等待应用停止..."
sleep 0.2
done
sleep 1
echo && echo "已停止应用进程 $application -> $PID"
else
echo && echo "未找到应用进程 $application"
fi
}
#重启
restart() {
stop
start
}
#查看日志
log() {
if [ -n "$tail_keyword" ]; then
tail -10000 $log_file | grep $tail_keyword
else
tail -1000f $log_file
fi
}
case $1 in
"start")
if [ "$2" = "-f" ]; then
tail_f=true
fi
start
;;
"restart")
if [ "$2" = "-f" ]; then
tail_f=true
fi
restart
;;
"status")
status
;;
"stop")
stop
;;
"log")
tail_keyword=$2
log
;;
*)
echo "使用方法: $0 {status|start [-f]|stop|restart [-f]|log [keyword]}"
exit 1
;;
esac
]]></content>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker-push</id>
<properties>
<docker.registry>127.0.0.1:5000</docker.registry>
<docker.image>${docker.registry}/${project.groupId}/${project.artifactId}</docker.image>
<docker.push-command>docker image push ${docker.image}:${docker.tag}</docker.push-command>
</properties>
</profile>
<profile>
<id>docker-build</id>
<build>
<plugins>
<plugin>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-maven-plugin</artifactId>
<version>${easier-framework.version}</version>
<executions>
<execution>
<id>docker-build</id>
<phase>install</phase>
<goals>
<goal>build-time-format</goal>
<goal>generate-file</goal>
<goal>exec</goal>
</goals>
<configuration>
<skip>${docker.skip}</skip>
<conditionOnPlugin>spring-boot-maven-plugin</conditionOnPlugin>
<outputDirectory>${project.build.directory}</outputDirectory>
<fileName>Dockerfile</fileName>
<content><![CDATA[
FROM ${docker.from}
#工作目录
WORKDIR ${docker.workdir}
# 环境参数
ENV JVM="" \
ARGS="" \
TZ=Asia/Shanghai
RUN mkdir -p ${docker.workdir}/logs \
&& ln -fs /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
#挂载宿主机/tmp
VOLUME /tmp
# 复制相关文件
COPY ${docker.application-jar} ${docker.workdir}/application.jar
COPY config/ ${docker.workdir}/config/
# 暴露端口
EXPOSE ${docker.expose_ports}
${docker.dockerfile-command1}
${docker.dockerfile-command2}
${docker.dockerfile-command3}
${docker.dockerfile-command4}
${docker.dockerfile-command5}
#执行命令
ENTRYPOINT ["sh", "-c", "java $JVM -jar application.jar $ARGS"]
]]></content>
<workingDirectory>${project.build.directory}</workingDirectory>
<commands>
<command>docker --version</command>
<command>
docker
build
${docker.build-command1}
${docker.build-command2}
${docker.build-command3}
${docker.build-command4}
${docker.build-command5}
-t ${docker.image}:${docker.tag}
.
</command>
<command>
docker save -o image.tar ${docker.image}:${docker.tag}
</command>
<command>${docker.push-command}</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-docker-sh</id>
<build>
<plugins>
<plugin>
<groupId>io.github.lizhian</groupId>
<artifactId>easier-framework-maven-plugin</artifactId>
<version>${easier-framework.version}</version>
<executions>
<execution>
<id>generate-docker-sh</id>
<phase>install</phase>
<goals>
<goal>generate-file</goal>
</goals>
<configuration>
<conditionOnPlugin>spring-boot-maven-plugin</conditionOnPlugin>
<outputDirectory>${project.build.directory}</outputDirectory>
<fileName>docker.sh</fileName>
<!--suppress UnresolvedMavenProperty -->
<content><![CDATA[
#!/bin/bash
application=${docker.sh.application}
image=${docker.sh.image}
tag=${docker.sh.tag}
env=${docker.sh.env}
jvm="${docker.sh.jvm}"
args="${docker.sh.args}"
expose_ports="${docker.sh.expose_ports}"
workdir=${docker.sh.workdir}
# 对端口参数进行处理
port_args=""
# expose_ports="-p 8080:8080 -p 9090:9090"
if [ "${expose_ports:0:2}" = "-p" ]; then
port_args=$expose_ports
# expose_ports="0"
elif [ "$expose_ports" = "0" ]; then
port_args=""
# expose_ports="8080 9090"
else
IFS=' ' read -ra ports_array <<< "$expose_ports"
for port in "${ports_array[@]}"; do
port_args="$port_args -p $port:$port"
done
fi
# 日志关键词
log_keyword=""
# 查找运行容器 ID
container_id=$(docker ps -aqf "name=$application")
running_container_id=$(docker ps -qf "name=$application")
reload_container_id() {
container_id=$(docker ps -aqf "name=$application")
running_container_id=$(docker ps -qf "name=$application")
}
#状态
status() {
# 重新获取运行容器主键
reload_container_id
# 检查容器是否运行中
if [ -z "$container_id" ]; then
echo "未找到应用容器: $application"
exit 1
fi
echo "找到应用容器: $application -> $container_id"
docker ps -af "id=$container_id"
if [ -n "$running_container_id" ]; then
echo "应用容器状态: 运行中"
else
echo "应用容器状态: 已停止"
fi
}
#详情
detail() {
status
echo && echo "使用镜像:"
docker image inspect --format='{{range .RepoTags}}{{println .}}{{end}}' $(docker inspect -f '{{.Image}}' $container_id)
echo "环境变量:"
docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' $container_id
echo "端口绑定: 主机 -> 容器"
docker inspect --format '{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}} -> {{$p}}{{"\n"}}{{end}}' $container_id
echo "文件绑定: 主机 -> 容器"
docker inspect --format '{{range .Mounts}}{{printf "%s -> %s\n" .Source .Destination}}{{end}}' $container_id
echo "工作目录: "
docker inspect --format '{{.Config.WorkingDir}}' $container_id
echo && echo "运行脚本: "
docker inspect --format '{{.Args}}' $container_id
}
#启动
start() {
reload_container_id
# 检查容器是否运行中
if [ -n "$running_container_id" ]; then
status
echo && echo "启动应用失败"
exit 1
fi
# 存在容器,但是容器已停止
if [ -n "$container_id" ]; then
status
echo && echo "启动应用指令: docker start $container_id"
docker start $container_id
sleep 5
reload_container_id
echo
status
if [ -n "$running_container_id" ]; then
echo && echo "启动应用成功"
exit 0
else
echo && echo "启动应用失败"
exit 1
fi
fi
# 不存在应用容器,初始化启动
echo "开始启动应用 $application"
# 获取脚本文件所在的目录
script_dir=$(cd "$(dirname "$0")" && pwd)
echo && echo "当前路径: $script_dir"
if [ -n "$jvm" ]; then
echo "jvm 参数: $jvm"
fi
if [ -n "$env" ]; then
echo "env 参数: $env"
args="--spring.profiles.active=$env $args"
fi
if [ -n "$args" ]; then
echo "启动参数: $args"
fi
if [ -n "$port_args" ]; then
echo "端口参数: $port_args"
fi
echo && echo "启动应用指令: docker run -d --name $application $port_args -e JVM=\"$jvm\" -e ARGS=\"$args\" -v $script_dir/config/:$workdir/config/ -v $script_dir/logs/:$workdir/logs/ $image:$tag"
docker run -d --name $application $port_args -e JVM="$jvm" -e ARGS="$args" -v $script_dir/config/:$workdir/config/ -v $script_dir/logs/:$workdir/logs/ $image:$tag
sleep 5
echo ""
status
if [ -n "$running_container_id" ]; then
echo && echo "启动应用成功"
exit 0
else
echo && echo "启动应用失败"
exit 1
fi
}
#停止
stop(){
reload_container_id
if [ -z "$container_id" ]; then
echo "应用未启动: $application"
return 0
fi
status
# 容器已经停止
if [ -z "$running_container_id" ]; then
return 0
fi
# 停止容器
echo && echo "停止应用指令: docker stop $container_id"
docker stop "$container_id"
sleep 2
echo && status
}
#重启
restart(){
echo "执行操作: stop" && echo
stop
echo && echo "执行操作: start" && echo
start
}
#清除容器和镜像
clean(){
reload_container_id
if [ -z "$container_id" ]; then
echo "未找到应用容器: $application"
return 1
fi
stop
echo && echo "删除容器: docker rm $container_id"
docker rm $container_id
remove_images=$(docker images -q $image)
if [ -n "$remove_images" ]; then
echo && echo '删除镜像: docker rmi $(docker images -q '$image')'
docker rmi $(docker images -q $image)
fi
remove_images=$(docker images -f "dangling=true" -q)
if [ -n "$remove_images" ]; then
echo && echo '删除镜像: docker rmi $(docker images -f "dangling=true" -q)'
docker rmi $(docker images -f "dangling=true" -q)
fi
}
#初始化
init(){
clean
if [ -f "image.tar" ]; then
echo && echo "导入镜像: docker load -i image.tar"
docker load -i image.tar
fi
echo ""
start
}
#查看日志
log(){
reload_container_id
if [ -z "$container_id" ]; then
echo "未找到应用容器: $application"
exit 1
fi
if [ -n "$log_keyword" ]; then
docker logs $container_id --tail 10000 | grep "$log_keyword"
else
docker logs $container_id -f --tail 1000
fi
}
case $1 in
"status")
status
;;
"detail")
detail
;;
"start")
start
;;
"stop")
stop
;;
"clean")
clean
;;
"restart")
restart
;;
"init")
init
;;
"log")
log_keyword=$2
log
;;
*)
echo "使用方法: $0 {status|detail|start|stop|restart|clean|init|log [keyword]}"
exit 1
;;
esac
]]></content>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ossrh</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<useAgent>false</useAgent>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>