3

I am trying to test with Github Actions to build my docker container automatically.

In my POM, the version of the docker image that I create with JIB, I extract it from the version of my project.

<groupId>io.xxx.my-proyect</groupId>
<artifactId>my-proyect</artifactId>
<version>0.2.0-SNAPSHOT</version>
<name>my-proyect</name>
 ...

<plugin>
 <groupId>com.google.cloud.tools</groupId>
 ....
   <to>
    <image>XXX/my-proyect:${version}</image>
   </to>
 </plugin>

Github Actions:

- name: package
      run: ./mvnw package jib:dockerBuild
    - name: push
      run:  docker push xxx/my-proyect:VERSION (<-- Extract from version property of my POM)

Anyone have any idea how to do it.

Jose
  • 1,779
  • 4
  • 26
  • 50

1 Answers1

3

You can ask Maven using maven-help-plugin:

mvn help:evaluate -Dexpression=project.version -q -DforceStdout

If the command prints nothing (because -q suppresses all output including the evaluated version), then it's probably because the maven-help-plugin being used is too old. If so, you can pin the version like this:

mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout

Or, you could pin the version 3.2.0 in your pom.xml or in a parent pom.xml (if applicable).

Note that running a Maven command always takes some time, so it may add a few seconds to your build time. Passing --offline may help if it works (or may not so much).


Alternatively, you could run jib:build instead of jib:dockerBuild to have Jib directly push to xxx/my-project:VERSION. Looking at your YAML, there does not seem any good reason to run jib:dockerBuild followed by docker push. Using jib:build in this case will substantially cut your build time, as Jib loses a lot of performance optimizations when pushing to a local Docker daemon.


UDPATE: also, unless you are using Jib's <containerizingMode>packaged configuration, you don't need mvn package. mvn compile jib:... will suffice (and marginally faster).

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63