Skip to content

Commit

Permalink
Maven Docker Build improvements (#151)
Browse files Browse the repository at this point in the history
* Maven Docker Build improvements

* Fixing build.

* Match docker healthcheck port with application running port.

---------

Co-authored-by: Oweis Al-Agtash <[email protected]>
  • Loading branch information
oalagtash and oalagtash authored Dec 12, 2023
1 parent 97e2aee commit eca2af2
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 451 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.vs
/.vscode
/.idea
**.iml
launchSettings.json
.project
*.pubxml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ ARG JAR_FILE=target/*-exec.jar
COPY ${JAR_FILE} basyxExecutable.jar
COPY src/main/resources/application.properties application.properties
ARG PORT=8081
EXPOSE ${PORT}
ENV SERVER_PORT=${PORT}
EXPOSE ${SERVER_PORT}
HEALTHCHECK --interval=30s --timeout=3s --retries=3 --start-period=15s CMD curl --fail http://localhost:${SERVER_PORT}/actuator/health || exit 1
ENTRYPOINT ["java","-jar","basyxExecutable.jar"]
107 changes: 46 additions & 61 deletions basyx.aasdiscoveryservice/basyx.aasdiscoveryservice.component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,78 +111,63 @@
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<!-- Build the docker image -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.43.0</version>
<configuration>
<images>
<image>
<name>${docker.username}/${docker.image.name}</name>
<build>
<tags>
<tag>${docker.image.tag}</tag>
</tags>
<contextDir>${project.basedir}</contextDir>
</build>
<run>
<ports>
<port>${docker.host.port}:${docker.container.port}</port>
</ports>
<wait>
<url>${docker.container.waitForEndpoint}</url>
<time>60000</time>
</wait>
</run>
</image>
</images>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker-compose-up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-compose-down</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>docker</id>
<activation>
<property>
<name>docker.namespace</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<run>
<ports>
<port>${docker.host.port}:${docker.container.port}</port>
</ports>
<wait>
<url>${docker.container.waitForEndpoint}</url>
<time>60000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-docker</id>
</execution>
<execution>
<id>push-docker</id>
</execution>
<execution>
<id>docker-compose-up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-compose-down</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Expand Down
102 changes: 43 additions & 59 deletions basyx.aasenvironment/basyx.aasenvironment.component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,74 +114,58 @@
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<!-- Build the docker image -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.43.0</version>
<configuration>
<images>
<image>
<name>${docker.namespace}/${docker.image.name}</name>
<build>
<tags>
<tag>${docker.image.tag}</tag>
</tags>
<contextDir>${project.basedir}</contextDir>
</build>
<run>
<ports>
<port>
${docker.host.port}:${docker.container.port}</port>
</ports>
<wait>
<url>${docker.container.waitForEndpoint}</url>
<time>60000</time>
</wait>
</run>
</image>
</images>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker-compose-up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-compose-down</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>docker</id>
<activation>
<property>
<name>docker.namespace</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<run>
<ports>
<port>${docker.host.port}:${docker.container.port}</port>
</ports>
<wait>
<url>${docker.container.waitForEndpoint}</url>
<time>60000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-docker</id>
</execution>
<execution>
<id>push-docker</id>
</execution>
<execution>
<id>docker-compose-up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-compose-down</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -191,4 +175,4 @@
</build>
</profile>
</profiles>
</project>
</project>
81 changes: 14 additions & 67 deletions basyx.aasregistry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</parent>

<properties>
<docker.image.version>2.0.0-SNAPSHOT</docker.image.version>
<lombok.maven-plugin.version>1.18.20.0</lombok.maven-plugin.version>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand All @@ -30,12 +29,7 @@
<maven-plugin.version>3.6.0</maven-plugin.version>
<maven-project.version>3.0-alpha-2</maven-project.version>
<mustache.compiler.version>0.9.4</mustache.compiler.version>
<snakeyaml.version>2.2</snakeyaml.version>
<docker.maven.plugin.version>0.43.4</docker.maven.plugin.version>
<docker.image.name>${project.artifactId}</docker.image.name>
<docker.pull.registry>docker.io</docker.pull.registry>
<docker.target.platforms>linux/amd64,linux/arm64</docker.target.platforms>
<docker.registry>docker.io</docker.registry>
<openapitools.version>6.6.0</openapitools.version>
<openapitools.jacksonnullable.version>0.2.6</openapitools.jacksonnullable.version>
<jsr305.version>3.0.2</jsr305.version>
Expand Down Expand Up @@ -100,11 +94,6 @@
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapitools.version}</version>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.maven.plugin.version}</version>
</plugin>
<plugin>
<groupId>de.dfki.cos.basys.common</groupId>
<artifactId>jsonpatch-maven-plugin</artifactId>
Expand Down Expand Up @@ -258,8 +247,7 @@
<profile>
<id>dockerbuild</id>
<activation>
<!-- This profile is always active if there is a Dockerfile and a user
name is given -->
<!-- This profile is always active if there is a Dockerfile and docker.namespace property is given -->
<file>
<exists>src/main/docker/Dockerfile</exists>
</file>
Expand Down Expand Up @@ -289,66 +277,25 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<build>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<dockerFile>Dockerfile</dockerFile>
<contextDir>${project.basedir}/src/main/docker</contextDir>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-docker</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<images>
<image>
<name>${docker.namespace}/${docker.image.name}</name>
<build>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<tags>
<tag>${docker.image.version}</tag>
</tags>
<dockerFile>Dockerfile</dockerFile>
<contextDir>${project.basedir}/src/main/docker</contextDir>
<!-- building non buildx image here to speed up build -->
<noCache>true</noCache>
</build>
</image>
</images>
</configuration>
</execution>
<execution>
<id>push-docker</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
<configuration>
<images>
<image>
<name>${docker.namespace}/${docker.image.name}</name>
<!-- needs to be set to this registry https://github.com/fabric8io/docker-maven-plugin/pull/1578 -->
<registry>https://index.docker.io/v1/</registry>
<build>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<tags>
<tag>${docker.image.version}</tag>
</tags>
<dockerFile>Dockerfile</dockerFile>
<contextDir>${project.basedir}/src/main/docker</contextDir>
<buildx>
<platforms>${docker.target.platforms}</platforms>
<attestations>
<provenance>${docker.provenance}</provenance>
</attestations>
</buildx>
<noCache>true</noCache>
</build>
</image>
</images>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Loading

0 comments on commit eca2af2

Please sign in to comment.