Fabric8 Docker Maven plugin not working for compose.yml on Multi module project

Viewed 1673

I trying to use Fabric8 docker-maven-plugin, though I was successful in configuring plugin for individual module and run docker:build docker:start Maven goal without using docker-compose.yml, however I needed externalize ports and link the different module, hence I intended to use docker-compose.yml. Below is my project structure.

--kp-parent
      |
      --- docker-compose.yml
      --- pom.xml
      |
      ---- rest1
      |       |
      |       -- .maven-dockerignore
      |       -- pom.xml
      |       -- Dockerfile
      ---- rest2
      |       |
      |       -- .maven-dockerignore
      |       -- pom.xml
      |       -- Dockerfile

Here are my configurations

Dockerfile[both rest1 and rest2 use identical file except the different port]

FROM openjdk:8-jdk-alpine
MAINTAINER 'Karthik Prasad'

ARG IMAGE_VERSION
ARG JAR_FILE
ENV JAVA_OPTS=""

LABEL version = IMAGE_VERSION

VOLUME /tmp
ADD /maven/${JAR_FILE}.jar app.jar


ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
EXPOSE 8000

.maven-dockerignore[In both child modules identical file]

target/**

pom.xml [Both rest1 and rest2 pom files are same except the artifcatid and name of the project]

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>rest2</artifactId>
    <packaging>jar</packaging>

    <name>rest2</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>com.kp.swasthik</groupId>
        <artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- https://mvnrepository.com/artifact/io.fabric8/docker-maven-plugin -->
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                    <images>
                        <image>
                            <external>
                                <type>compose</type>
                                <basedir>../</basedir>
                                <ignoreBuild>true</ignoreBuild>
                            </external>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

parent pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.kp.swasthik</groupId>
    <artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>kp-docker-multimodule-fabric8-parent</name>
    <description>Microservice Parent Pom file</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <modules>
        <module>rest1</module>
        <module>rest2</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <docker.image.prefix>kp-ms</docker.image.prefix>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.22.1</version>
                    <configuration>
                        <skip>true</skip>
                        <images>
                            <image>
                                <alias>${project.artifactId}</alias>
                                <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
                                <build>
                                    <dockerFileDir>${project.basedir}</dockerFileDir>
                                    <assembly>
                                        <inline>
                                            <id>default</id>
                                            <fileSet>
                                                <directory>${project.build.directory}</directory>
                                                <outputDirectory>/</outputDirectory>
                                                <includes>
                                                    <include>*.jar</include>
                                                </includes>
                                            </fileSet>

                                        </inline>
                                    </assembly>
                                </build>
                            </image>
                        </images>
                        <buildArgs>
                            <IMAGE_VERSION>${project.version}</IMAGE_VERSION>
                            <JAR_FILE>${project.artifactId}-${project.version}</JAR_FILE>
                        </buildArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

And finally docker-compose.yml

version: '2'
services:
  rest1:
    image: kp-ms/rest1:0.0.1-SNAPSHOT
    ports:
    - 8000:8000
  rest2:
    image: kp-ms/rest2:0.0.1-SNAPSHOT
    ports:
    - 8001:8001
    links:
    - rest1

When I run the docker:build docker:start I get below error.

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:start (default-cli) on project rest1: I/O Error: Unable to pull 'kp-ms/rest2:0.0.1-SNAPSHOT' : repository kp-ms/rest2 not found: does not exist or no pull access (Not Found: 404) -> [Help 1]
[ERROR]

However If I remove rest2 section in docker-compose.yml, build goes fine and I'm able to find the container start successfully.

Another problem I noticed is that even if do not give image name in docker-compose.yml build fails with error image is null. However I'm not sure why I need to provide image can't the plugin map from plugin configuration as I had provided alias. As you can notice I'm trying to generate image name dynamically.

0 Answers
Related