Fabric8io plugin with Gitlab CI

479 views Asked by At

I'm just learning and new to Gitlab, but already have some tasks important for my work. One of them is building java project (maven build stage) and copying artifacts to the docker image with Fabric8io plugin. I'm using Gitlb CI for my task, and what I already can do is successfully passing pipeline of maven stages (build, test, deploy at this moment) and building a docker image and pushing it to repo with Fabric8io maven plugin. But now this proceses are separate from each other. I've spent a few days searching for the solution to add maven artifacts to docker image, but with no success. Settings in pom.xml point to the gitlab repository files, but not artifacts in maven container (the example below is from my .pom file, fabric8io section, I just experimented with different values and variables with no success).

    <file>                                  
        <source>${project.build.directory}/313test.war</source>   
        <source>target/313test.war</source>
        <outputDirectory>./</outputDirectory>
        <destName>testapp.war</destName>
    </file>

Had anyone any experience with this stack? Is there any working solution? Thank You in advance.

1

There are 1 answers

0
Denis Kvashnin On

Well, I suppose a got it. Using execution of commands in .gitlab-ci.yml works like I needed:

    deploy:
        stage: deploy
        script:
            - mvn clean package docker:build docker:start docker:push

In addition, I commented some tags in pom.xml, so my build section now looks like this:

    <build>
       <!-- <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
       <dockerFile>Dockerfile</dockerFile> -->
             <assembly>
                   <descriptorRef>artifact</descriptorRef>
                   <mode>dir</mode>
                   <targetDir>/opt/demo/</targetDir>
                   <!--  <files>
                        <file>
                              <source>${project.build.directory}/313test.war</source>   
                              <source>target/313test.war</source>
                              <outputDirectory>./</outputDirectory>
                              <destName>testapp.jar</destName>
                        </file>
                   </files>     -->
             </assembly>
    </build>

So, running ls in run section of pom.xml file shows a WAR file in /opt/demo directory inside a built docker image

    <run>
        <cmd>ls -l /opt/demo/</cmd>
            <wait>
                <time>10000</time>
            </wait>
    </run>

Thanks everyone )