Skip to content

Instantly share code, notes, and snippets.

@tzolov
Created January 31, 2020 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzolov/91d2315e11478ae85b4b80a3e680bb57 to your computer and use it in GitHub Desktop.
Save tzolov/91d2315e11478ae85b4b80a3e680bb57 to your computer and use it in GitHub Desktop.
Generate Docker Images with Boot Metadata Configuration labels
<?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 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.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>my-log</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-log</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<dockerfile-maven-plugin.version>1.4.13</dockerfile-maven-plugin.version>
<my.docker.image.prefix>tzolov</my.docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-configuration-metadata-encoder</artifactId>
<version>0.0.2.BUILD-SNAPSHOT</version>
<configuration>
<metadataFile>${project.build.outputDirectory}/META-INF/spring-configuration-metadata.json</metadataFile>
<encodedMetadataFile>${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties</encodedMetadataFile>
<encodedPropertyName>spring.configuration.metadata.encoded</encodedPropertyName>
</configuration>
<executions>
<execution>
<id>encode-metadata</id>
<phase>process-classes</phase>
<goals>
<goal>encode</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-dockerfile-template</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<outputDirectory>${project.build.outputDirectory}/META-INF/</outputDirectory>
<filters>
<filter>
${project.build.outputDirectory}/META-INF/spring-configuration-metadata-encoded.properties
</filter>
</filters>
<resources>
<resource>
<directory>${basedir}/src/main/resources/templates</directory>
<includes>
<include>**/Dockerfile</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-plugin.version}</version>
<configuration>
<repository>${my.docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
<tag>${project.version}</tag>
<dockerfile>${project.build.outputDirectory}/META-INF/Dockerfile</dockerfile>
</configuration>
<executions>
<execution>
<id>build-tag-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
FROM springcloud/openjdk:2.0.1.RELEASE
ENV LANG=C.UTF-8
ARG JAR_FILE
ADD target/${JAR_FILE} my-log-sink.jar
LABEL spring.configuration.metadata=@spring.configuration.metadata.encoded@
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/my-log-sink.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment