'JIB with GitHub Actions

Introduction

I am currently create a GitHub Actions with that build a container automatically.

And I'm wondering if it's possible to create a GitHub action that automatically builds the container without adding JIB in the project's pom.xml ?

If we can t do this, can you show me how?



Solution 1:[1]

In Maven, you can run a goal of a plugin without adding the plugin to pom.xml. For example,

mvn compile com.google.cloud.tools:jib-maven-plugin:3.2.0:build -Djib.to.image=foo

For Gradle, one can use a trick to use initscript:

      # Adds Gradle init script that applies the Jib Gradle plugin.
      echo "initscript {
              repositories { maven { url 'https://plugins.gradle.org/m2' } }
              dependencies { classpath 'gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:3.2.0' }
            }
            rootProject {
              afterEvaluate {
                if (!project.plugins.hasPlugin('com.google.cloud.tools.jib')) {
                  project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin
                }
              }
            }" > "$HOME"/init-script.gradle
      # Runs the Gradle Jib build.
      gradle jib \
        --init-script="$HOME"/init-script.gradle \
        -Djib.to.image=foo

You can find an example here.


Another option that may be applicable to you is Jib CLI, which has a feature to build a container from an existing JAR.

jib jar --target=my-registry.example.com/jar-app myapp.jar

There's also a Java library called Jib Core with which you can write a Java program to build a container. Jib Maven and Gradle plugins and Jib CLI are based on Jib Core.

Solution 2:[2]

We are obliged to configure the pom.xml, we cannot do otherwise.

You can go here: https://github.com/GoogleContainerTools/jib to get more information about JIB.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chanseok Oh
Solution 2