Springboot automated deployment to docker logback by day and generate a log

 

 Dockerfile

FROM java:8
VOLUME /tmp
ADD maven/sms-0.0.1-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

application.properties

# tomcat
server.port=8088
server.max-http-header-size=10000000

logback.xml

<? XML Version = "1.0" encoding = "UTF-. 8" ?> 
< Configuration Debug = "to false" > 
    <-! Storage address defined in LogBack log files do not use a relative path configuration -> 
    < Property name = "LOG_HOME" value = "/ SMS"  /> 
    <-! console output -> 
    < the appender name = "STDOUT" class = "ch.qos.logback.core.ConsoleAppender" > 
        < Encoder class = "CH. qos.logback.classic.encoder.PatternLayoutEncoder " > 
            <!- Formatting Output:% d represents the date,% thread indicates that the thread name,% - 5level: Level 5 show left character width% msg: log messages,% n newline -> 
            <pattern > % {D the MM-dd-YYYY HH: mm: ss.SSS} -% n-MSG% </ pattern > 
        </ Encoder > 
    </ the appender > 
    <-! accordance log files are generated per day -> 
    < the appender name = "the FILE"   class = "ch.qos.logback.core.rolling.RollingFileAppender" > 
        < File > $ {} /sms.log LOG_HOME </ File > 
        < rollingPolicy class = "ch.qos.logback.core.rolling. TimeBasedRollingPolicy " > 
            <-! filename of the log file output -> 
            <FileNamePattern>LOG_HOME /sms.%d {} {$-YYYY} .log the MM-dd </ FileNamePattern > 
            <-! Log files remain for several days -> 
            < MaxHistory > 30 </ MaxHistory > 
        </ rollingPolicy > 
        < Encoder class = " ch.qos.logback.classic.encoder.PatternLayoutEncoder " > 
            <-! format output:% d represents the date,% thread indicates that the thread name,% - 5level: level 5 show left character width% msg: log message, % n newline -> 
            < pattern > % {D the mM-dd-YYYY HH: mm: ss.SSS} - MSG% n% </ pattern > 
        </ Encoder > 
        ! <- the maximum size of the log file
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>-->
    </appender>

    <!-- 日志输出级别 -->
    <root level="INFO">
        <!--<appender-ref ref="STDOUT" />-->
        <appender-ref ref="FILE" />
    </root>
</configuration>

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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.abc</groupId>
    <artifactId>sms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>sms</name>
    <description>短信api</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba / fastjson-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>
        <!--springfox的核心jar包-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <!--springfox-ui的jar包(里面包含了swagger的界面静态文件)-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.30.0</version>
                <configuration>
                    <dockerHost>http://192.168.80.16:2375</dockerHost>
                    <images>
                        <image>
                            <name>${project.name}</name>
                            <alias>${project.name}</alias>
                            <build>
                                <dockerFileDir>${project.basedir}/src/main/docker/</dockerFileDir>
                                <assembly>
                                    <descriptorRef>artifact</descriptorRef > 
                                </ Assembly > 
                                < Tags > 
                                    < Tag > Latest </ Tag > 
                                </ Tags > 
                            </ Build > 
                            < RUN > 
                                <-! data volume, hanging in the address file, such as the output log items -> 
                                < Volumes > 
                                    < the bind > 
                                        < Volume > / the root / SMS: / SMS </ Volume > 
                                    </ the bind > 
                                </ Volumes > 
                                < the namingStrategy, >alias </namingStrategy>
                                <!--端口映射-->
                                <ports>
                                    <port>0.0.0.0:8088:8088</port>
                                </ports>
                                <restartPolicy>
                                    <name>always</name>
                                </restartPolicy>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Finally, the following command Qiaoxia

mvn clean package docker:stop docker:remove docker:build -DskipTests docker:run

Guess you like

Origin www.cnblogs.com/DurantSimpson/p/11510796.html