Gitlab CI and Maven Fabric8 plugin

Currently, we use Fabric8 plugin to build and push Docker images.
The thing is, that this plugin utilizes Maven to build the project and Docker to push the images.
The command looks like this: “mvn clean package docker:build docker:push”.
We use Gitlab Ci to run our Maven builds, but the real goal is to get use of Fabric8 plugin within the .gitlab-ci.yml.
An attempt to just add the above command to .gitlab-ci.yml script section failed.
And the reason why is known: you need to use a correct image.
For example: if I use doker:stable image in .gitlab-ci.yml, I receive “/bin/sh: eval: line 80: mvn: not found”, and if I use image: maven:3-jdk-8, I receive
“/bin/sh: eval: line 80: docker: not found”.
Does the image, which combines Docker and Maven binaries, even exists?
Or, maybe, we just approaching the problem from the wrong end?

Also, it’s worth to mention, that I configured my runner as Docker from Docker by mounting corresponding volume (–docker-volumes /var/run/docker.sock:/var/run/docker.sock) to give access to the hosts’ socket.

Thanks in advance!

Attaching our .gitlab-ci.yml.

image: docker:stable

variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2

stages:

  • Maven build

maven-build:
image: maven:3-jdk-8
stage: Maven build
script:
- cd ./config-service
- mvn clean package docker:build docker:push

1 Like

Try running a docker-in-docker service alongside your maven build:

stages:
  - maven-build

default:
    services:
        - name: docker-19.03-dind
    image: maven:3.6-jdk-8

build:
    stage: maven-build
    tags:
      - dnd
    script: |
        mvn clean package docker:build docker:push

In your pom.xml, you can configure the fabric8 plugin using environment variables that Gitlab provides:

    <configuration>
        <mode>kubernetes</mode>
        <buildStrategy>docker</buildStrategy>
        <dockerHost>${env.DOCKER_PORT}</dockerHost>
        <registry>${env.CI_REGISTRY_IMAGE}</registry>
        <authConfig>
            <username>${env.CI_REGISTRY_USER}</username>
            <password>${env.CI_REGISTRY_PASSWORD}</password>
        </authConfig>
        ...etc...
    </configuration>

I configure the above indirectly using different profiles, in order to support both local developer builds and gitlab-ci.

1 Like