Maven specifies the configuration file mirror

1. Create dockerFile

FROM bladex/alpine-java:openjdk8-openj9_cn_slim

MAINTAINER [email protected]

RUN mkdir -p /blade

WORKDIR /blade

EXPOSE 8088
EXPOSE 8888
EXPOSE 5005

ADD ./target/full-course-disease-api.jar ./app.jar

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 ","app.jar"]

CMD ["--spring.profiles.active=prod","-Ddruid.mysql.usePingMethod=false"]

Modify the pom file and set up the build plugin

 <build>
        <finalName>${bladex.project.id}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugin Management>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.version}</version>
                    <configuration>
                        <finalName>${project.build.finalName}</finalName>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>${docker.plugin.version}</version>
                    <configuration>
                        <username>${docker.username}</username>
                        <password>${docker.password}</password>
                        <repository>${docker.registry.url}/${docker.namespace}/${project.build.finalName}</repository>
                        <tag>${docker. tag}</tag>
                        <!-- <tag>1.0.0-SNAPSHOT</tag>-->
                        <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                        <!-- dockerfile file -->
                        <dockerfile>${dockerConfigFilePath}</dockerfile>
                        <buildArgs>
                            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                        </buildArgs>
                    </configuration>
                    <!--Add the following configuration, run the mvn deploy command and the image will be automatically packaged -->
                    <!--<executions>
                        <execution>
                            <id>default</id>
                            <goals>
                                <goal>build</goal>
                                <goal>push</goal>
                            </goals>
                        </execution>
                    </executions>-->
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>aliyun-repos</id>
            <url>https://maven.aliyun.com/repository/public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>rdc-releases</id>
            <name>Release Repository</name>
            <url>https://packages.aliyun.com/maven/repository/2251575-release-ExJpmm/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>aliyun-plugin</id>
            <url>https://maven.aliyun.com/repository/public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

Modify the pom file and set the configuration enabled in different environments

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
                <docker.tag>${project.version}-SNAPSHOT</docker.tag>
                <dockerConfigFilePath>Dockerfile_test</dockerConfigFilePath>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
                <docker.tag>${project.version}-SNAPSHOT</docker.tag>
                <dockerConfigFilePath>Dockerfile_test</dockerConfigFilePath>
            </properties>
        </profile>
        <profile>
            <!-- Grayscale test environment -->
            <id>pre</id>
            <properties>
                <profiles.active>pre</profiles.active>
                <docker.tag>${project.version}-SNAPSHOT</docker.tag>
                <dockerConfigFilePath>Dockerfile_test</dockerConfigFilePath>
            </properties>
        </profile>
        <profile>
            <!-- Online -->
            <id>prod</id>
            <properties>
                <profiles.active>prod</profiles.active>
                <docker.tag>${project.version}.RELEASE</docker.tag>
                <dockerConfigFilePath>Dockerfile_prod</dockerConfigFilePath>
            </properties>
        </profile>
        <profile>
            <!-- nx -->
            <id>nx</id>
            <properties>
                <profiles.active>nx</profiles.active>
                <docker.tag>${project.version}.nx</docker.tag>
                <dockerConfigFilePath>Dockerfile_nx</dockerConfigFilePath>
            </properties>
        </profile>
    </profiles>

pom configuration mirror server address

 <properties>
        <bladex.project.id>${project.artifactId}</bladex.project.id>
        <bladex.project.version>3.0.1.RELEASE</bladex.project.version>

        <java.version>1.8</java.version>
        <maven.plugin.version>3.8.1</maven.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <spring.boot.version>2.7.1</spring.boot.version>
        <spring.platform.version>Cairo-SR8</spring.platform.version>

        <!-- Harbor is recommended -->
        <docker.registry.url>192.168.2.111:5500</docker.registry.url>
        <docker.username>admin</docker.username>
        <docker.password>Harbor12345</docker.password>
        <docker.namespace>full-course-disease</docker.namespace>
        <docker.plugin.version>1.4.13</docker.plugin.version>
    </properties>

mvn packaging command

mvn clean package dockerfile:build dockerfile:push -P dev -Dmaven.test.skip=true