Skip to content

Commit

Permalink
Adding maven docker plugin
Browse files Browse the repository at this point in the history
- Updating spring boot to latest 2.3.0.M4
- Add Maven plugin that build, tag, and push image with maven verify goal.
- Adding some control properties to control dockerization stages.
- Some other enhancements.
  • Loading branch information
mohamed-taman committed Apr 5, 2020
1 parent 29428ca commit 4296fb5
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 21 deletions.
13 changes: 9 additions & 4 deletions product-composite-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
# ------------------------
# Build image based on JDK 14 base image, based on latest debian buster OS
FROM openjdk:14-slim-buster
MAINTAINER Mohamed Taman <[email protected]>

# Set image information
LABEL version="0.1.beta" name="Product Service"
# Set image information, but could be set to different location from command line
ARG IMAGE_VERSION="0.0.1-SNAPSHOT"
ARG IMAGE_NAME="Product Composite Service"
ARG MAINTAINER="Mohamed Taman <[email protected]>"

LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}

# Limiting security access to not user root user
RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
Expand All @@ -41,7 +44,9 @@ COPY --from=builder temp/application/ ./
# Expose current application to port 8080
EXPOSE 8080

# Run the application
ARG JAVA_OPTS=""

# Run the application with JVM configs if any
ENTRYPOINT ["bash", "-c", \
"java -server --enable-preview -XX:+UseContainerSupport \
-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
Expand Down
5 changes: 5 additions & 0 deletions product-composite-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<name>Product Composite Service</name>
<description>Product Composite Service Spring Boot based project</description>

<properties>
<skip.dockerization>false</skip.dockerization>
<skip.image.build>false</skip.image.build>
</properties>

</project>
14 changes: 10 additions & 4 deletions product-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM openjdk:14-slim-buster as builder
WORKDIR temp

# Could be set to different jar file location
# Fatjar location, but could be set to different location from command line
ARG JAR_FILE=target/*.jar

# Copy fat jar file to current image builder
Expand All @@ -20,8 +20,12 @@ RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
FROM openjdk:14-slim-buster
MAINTAINER Mohamed Taman <[email protected]>

# Set image information
LABEL version="0.1.beta" name="Product Service"
# Set image information, but could be set to different location from command line
ARG IMAGE_VERSION="0.0.1-SNAPSHOT"
ARG IMAGE_NAME="Product Service"
ARG MAINTAINER="Mohamed Taman <[email protected]>"

LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}

# Limiting security access to not user root user
RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
Expand All @@ -41,7 +45,9 @@ COPY --from=builder temp/application/ ./
# Expose current application to port 8080
EXPOSE 8080

# Run the application
ARG JAVA_OPTS=""

# Run the application with JVM configs if any
ENTRYPOINT ["bash", "-c", \
"java -server --enable-preview -XX:+UseContainerSupport \
-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
Expand Down
5 changes: 5 additions & 0 deletions product-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<name>Product Service</name>
<description>Product Service Spring Boot based project</description>

<properties>
<skip.dockerization>false</skip.dockerization>
<skip.image.build>false</skip.image.build>
</properties>

</project>
12 changes: 9 additions & 3 deletions recommendation-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
FROM openjdk:14-slim-buster
MAINTAINER Mohamed Taman <[email protected]>

# Set image information
LABEL version="0.1.beta" name="Review Service"
# Set image information, but could be set to different location from command line
ARG IMAGE_VERSION="0.0.1-SNAPSHOT"
ARG IMAGE_NAME="Recommendation Service"
ARG MAINTAINER="Mohamed Taman <[email protected]>"

LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}

# Limiting security access to not user root user
RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
Expand All @@ -41,7 +45,9 @@ COPY --from=builder temp/application/ ./
# Expose current application to port 8080
EXPOSE 8080

# Run the application
ARG JAVA_OPTS=""

# Run the application with JVM configs if any
ENTRYPOINT ["bash", "-c", \
"java -server --enable-preview -XX:+UseContainerSupport \
-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
Expand Down
5 changes: 5 additions & 0 deletions recommendation-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<name>Recommendation Service</name>
<description>Recommendation Service Spring Boot based project</description>

<properties>
<skip.dockerization>false</skip.dockerization>
<skip.image.build>false</skip.image.build>
</properties>

</project>
12 changes: 9 additions & 3 deletions review-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
FROM openjdk:14-slim-buster
MAINTAINER Mohamed Taman <[email protected]>

# Set image information
LABEL version="0.1.beta" name="Review Service"
# Set image information, but could be set to different location from command line
ARG IMAGE_VERSION="0.0.1-SNAPSHOT"
ARG IMAGE_NAME="Review Service"
ARG MAINTAINER="Mohamed Taman <[email protected]>"

LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}

# Limiting security access to not user root user
RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
Expand All @@ -41,7 +45,9 @@ COPY --from=builder temp/application/ ./
# Expose current application to port 8080
EXPOSE 8080

# Run the application
ARG JAVA_OPTS=""

# Run the application with JVM configs if any
ENTRYPOINT ["bash", "-c", \
"java -server --enable-preview -XX:+UseContainerSupport \
-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
Expand Down
5 changes: 5 additions & 0 deletions review-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
<name>Review Service</name>
<description>Review Service Spring Boot based project</description>

<properties>
<skip.dockerization>false</skip.dockerization>
<skip.image.build>false</skip.image.build>
</properties>

</project>
2 changes: 1 addition & 1 deletion store-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Libraries versions -->
<spring.boot.dependencies.version>2.2.3.BUILD-SNAPSHOT</spring.boot.dependencies.version>
<spring.boot.dependencies.version>2.3.0.M3</spring.boot.dependencies.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M4</maven.failsafe.plugin.version>
Expand Down
80 changes: 75 additions & 5 deletions store-chassis/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?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"
<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>
<!-- FIXME change this version to 2.3.0.M4 that fixes ASM8_EXPERIMENTAL when using JDK 14
record feature -->
<version>2.3.0.M2</version>
<version>2.3.0.M4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -31,6 +30,19 @@
<java.version>14</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Dependencies versions properties -->
<dockerfile-maven-version>1.4.13</dockerfile-maven-version>

<!-- Custom properties -->
<maintainer.name>Mohamed Taman</maintainer.name>
<maintainer.email>[email protected]</maintainer.email>
<docker.repo.image.prefix>siriusxi</docker.repo.image.prefix>
<docker.image.default.tag>latest</docker.image.default.tag>
<skip.dockerization>true</skip.dockerization>
<skip.image.build>true</skip.image.build>
<skip.image.tag>true</skip.image.tag>
<skip.image.push>true</skip.image.push>
</properties>

<dependencies>
Expand Down Expand Up @@ -101,7 +113,9 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- Make final jar, a layered jar -->
<layout>LAYERED_JAR</layout>
<layers>
<enabled>true</enabled>
</layers>
</configuration>
</plugin>

Expand All @@ -127,6 +141,62 @@
</configuration>
</plugin>

<!-- Start docker image build plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-version}</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<skipBuild>${skip.image.build}</skipBuild>
<repository>${docker.repo.image.prefix}/${project.artifactId}</repository>
<tag>${docker.image.default.tag}</tag>
</configuration>
</execution>
<execution>
<id>tag-image</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<skipTag>${skip.image.tag}</skipTag>
<tag>${project.version}</tag>
</configuration>
</execution>
<execution>
<id>push-image</id>
<phase>verify</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<skipPush>${skip.image.push}</skipPush>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
<configuration>
<skip>${skip.dockerization}</skip>
<dockerfile>Dockerfile</dockerfile>
<repository>${docker.repo.image.prefix}/${project.artifactId}</repository>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
<IMAGE_VERSION>${project.version}</IMAGE_VERSION>
<IMAGE_NAME>${project.name}</IMAGE_NAME>
<MAINTAINER>"${maintainer.name} (${maintainer.email})"</MAINTAINER>
</buildArgs>
</configuration>
</plugin>
<!-- End docker image build plugin -->

</plugins>
</build>

Expand Down
2 changes: 1 addition & 1 deletion store-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Libraries versions -->
<spring.boot.dependencies.version>2.2.3.BUILD-SNAPSHOT</spring.boot.dependencies.version>
<spring.boot.dependencies.version>2.3.0.M3</spring.boot.dependencies.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M4</maven.failsafe.plugin.version>
Expand Down

0 comments on commit 4296fb5

Please sign in to comment.