close

Filter

loading table of contents...

Deployment Manual / Version 2107

Table Of Contents

3.1.1 The Maven Structure

Each Spring-Boot applications has the following Maven module structure involved in building Docker images:

Filesystem Layout. 

apps
 `- <application name>
   |- docker
   |  |- <application name>
   |  |  |- Dockerfile
   |  |  |- src
   |  |  |  `- docker
   |  |  `- pom.xml
   |  `- pom.xml
   `- pom.xml

  • The Dockerfile defines the Docker build process. In it, all available Dockerfile directives are available. Please visit Dockerfile Reference for more details. Be aware, that only files beside and beneath the folder where the Dockerfile resides, can be copied or added to the Docker image.

  • The contents of the src/docker folder will be copied as-is into the /coremedia within the image. This copying is done by the Dockerfile directive:

    COPY --chown=coremedia:coremedia src/docker /coremedia
  • apps/<application name>/docker/<application naem>/pom.xml

    This is the Maven module that build the image. It should define the plugin executions to copy artifact to the Maven build dir to be processed from there by the Dockerfile. For the cae-live application this looks like the following snippets:

    Maven pom.xml - dependencies. 

    <dependencies>
       <dependency>
         <groupId>${blueprint.boot.groupId}</groupId>
         <artifactId>cae-live-app</artifactId>
         <version>${blueprint.boot.version}</version>
         <scope>runtime</scope>
       </dependency>
    </dependencies>

    Maven pom.xml - build. 

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-boot-jar</id>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <phase>generate-resources</phase>
          <configuration>
            <includeArtifactIds>cae-live-app</includeArtifactIds>
            <stripVersion>true</stripVersion>
            <outputDirectory>target</outputDirectory>
            <excludeTransitive>true</excludeTransitive>
          </configuration>
        </execution>
      </executions>
    </plugin>

    Docker Dockerfile

    COPY --chown=coremedia:coremedia target/cae-live-app.jar /coremedia/application.jar

  • apps/<application name>/docker/pom.xml

    This Maven module encapsulates the build process of the fabric8-maven-plugin. The following list of Maven properties can be configured:

    • docker.repository.prefix

      This property defines the docker registry part of the Docker image name. By default, it is set to coremedia and results in an image name of coremedia/${project.build.finalName} for example, for the cae-live coremedia/cae-live.

    • docker.image.tag

      This property defines the tag of the image. By default, latest is used. In a CI environment, you should set this property with a reasonable value. Good candidates are Git hashes or the incremental build number of the build job. Do not use running tags like latest or stable in production.

    • docker.java-application-base-image.repo

      This property defines the image repository for the java-application-base image, which is the base image for all Spring-Boot application images for CoreMedia.

    • docker.java-application-base-image.tag

The java-application-base properties are passed as build args to the Docker build process. This is defined in the fabric8-maven-plugin definition:

Maven pom.xml - fabric8-maven-plugin - here with shortened property names. 

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <images>
      <image>
        <name>${docker.repository.prefix}/${docker.repository.suffix}</name>
        <build>
          <dockerFileDir>${project.basedir}</dockerFileDir>
          <args>
            <JAVA_APPLICATION_BASE_IMAGE_REPO>${docker.java-application-base-image.repo}</JAVA_APPLICATION_BASE_IMAGE_REPO>
            <JAVA_APPLICATION_BASE_IMAGE_TAG>${docker.java-application-base-image.tag}</JAVA_APPLICATION_BASE_IMAGE_TAG>
          </args>
          <tags>
            <tag>${docker.image.tag}</tag>
          </tags>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

And consumed in the Dockerfile of the application:

Docker Dockerfile - from directive. 

ARG BASE_IMAGE_REPO
ARG BASE_IMAGE_TAG
FROM ${BASE_IMAGE_REPO}:${BASE_IMAGE_TAG}

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.