Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

GoogleContainerTools/jib-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This repository contains extensions to theJib Maven and Gradle build plugins.

The Jib Extension Framework enables anyone to easily extend Jib's behavior to their needs. Jib extensions are supported from Jib Maven 2.3.0 and Jib Gradle 2.4.0.

Table of Contents

What Part of Jib Does the Extension Framework Allow to Tweak?

TheContainer Build Plan originally prepared by Jib plugins. The build plan describes in a declarative way how it plans to build a container image. If you are interested in writing an extension, seeUpdating Container Build Plan for more details.

Using Jib Plugin Extensions

Maven

  1. Add extensions as dependencies to the Jib<plugin> block inpom.xml.
  2. Specify extension implementation classes with<pluginExtensions> in Jib's<configuration>.

The following example adds and runs theJib Layer-Filter Extension.

  <plugin>    <groupId>com.google.cloud.tools</groupId>    <artifactId>jib-maven-plugin</artifactId>    <version>3.4.3</version><!-- 1. have extension classes available on Jib's runtime classpath-->    <dependencies>      <dependency>        <groupId>com.google.cloud.tools</groupId>        <artifactId>jib-layer-filter-extension-maven</artifactId>        <version>0.3.0</version>      </dependency>    </dependencies>    <configuration>      ...      <pluginExtensions><!-- 2. specify extension implementation classes to load-->        <pluginExtension>          <implementation>com.google.cloud.tools.jib.maven.extension.layerfilter.JibLayerFilterExtension</implementation>        </pluginExtension>      </pluginExtensions>    </configuration>  </plugin>

When properly configured and loaded, Jib outputs the loaded extensions in the log. When you configure multiple<pluginExtension>s, Jib runs the extensions in the given order.

[INFO] --- jib-maven-plugin:3.4.3:build (default-cli) @ helloworld ---[INFO] Running extension: com.google.cloud.tools.jib.maven.extension.layerfilter.JibLayerFilterExtension

Some extensions may expect you to provide extension-specific user configuration.

  • For extensions that accept simple string properties (map), use<pluginExtension><properties>. For example,
    <pluginExtension>  <implementation>com.example.ExtensionAcceptingMapConfig</implementation>  <properties>    <customFlag>true</customFlag>    <layerName>samples</layerName>  </properties></pluginExtension>
  • For extensions that define a complex configuration, use<pluginExtension><configuration implementation=...> (not Jib's<configuration>). Note that the class for theimplementation XML attribute should be the extension-supplied configuration class and not the main extension class. For example,
    <pluginExtension>  <implementation>com.google.cloud.tools.jib.maven.extension.layerfilter.JibLayerFilterExtension</implementation>  <configurationimplementation="com.google.cloud.tools.jib.maven.extension.layerfilter.Configuration">    <filters>      <filter>        <glob>**/google-*.jar</glob>        <toLayer>google libraries</toLayer>      </filter>      <filter>        <glob>/app/libs/in-house-*.jar</glob>        <toLayer>in-house dependencies</toLayer>      </filter>    </filters>  </configuration></pluginExtension>

Gradle

  1. Have extensions available to the build script (build.gradle) by adding them withbuildscript.dependencies at the beginning of the build script.
  2. Configure extension implementation classes withjib.pluginExtensions.

The following example adds and runs theJib Layer-Filter Extension.

// should be at the top of build.gradlebuildscript {  dependencies {    classpath('com.google.cloud.tools:jib-layer-filter-extension-gradle:0.3.0')  }}...jib {...  pluginExtensions {    pluginExtension {      implementation='com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension'    }  }}

When properly configured and loaded, Jib outputs the loaded extensions in the log. When you configure multiplejib.pluginExtensions, Jib runs the extensions in the given order.

Running extension: com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension

Some extensions may expect you to provide extension-specific user configuration.

  • For extensions that accept simple string properties (map), usepluginExtension.properties. For example,
    pluginExtensions {  pluginExtension {    implementation='com.example.ExtensionAcceptingMapConfig'    properties= [customFlag:'true',layerName:'samples']  }}
  • For extensions that define a complex configuration, usepluginExtension.configuration. For example,
    • Groovy
      pluginExtension {  implementation='com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension'  configuration {    filters {      filter {        glob='**/google-*.jar'        toLayer='google libraries'      }      filter {        glob='/app/libs/in-house-*.jar'        toLayer='in-house dependencies'      }    }  }}
    • Kotlin
      pluginExtension {  implementation="com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension"  configuration(Action<com.google.cloud.tools.jib.gradle.extension.layerfilter.Configuration> {    filters {      filter {        glob="**/google-*.jar"        toLayer="google libraries"      }      filter {        glob="/app/libs/in-house-*.jar"        toLayer="in-house dependencies"      }    }  })}

Writing Your Own Extensions

It is easy to write an extension! If you have written a useful extension, let us know and we will put a link in this repo underthird-party/. Or, consider contributing to this repo. Either way, Jib users will greatly appreciate it!

Project Setup

  1. Create a new Java project and add Jib Maven/Gradle Plugin Extension API to the project dependencies.
    <dependencies>   <dependency>     <groupId>com.google.cloud.tools</groupId>     <artifactId>jib-maven-plugin-extension-api</artifactId>     <version>0.4.0</version>     <scope>provided</scope>   </dependency></dependencies>
    • Gradle:jib-gradle-plugin-extension-api usingcompileOnly. Also applyjava-gradle-plugin (as the Extension API allows you to access the Gradle project being containerized via Gradle API); if your extension does access the Gradle project via Gradle API, ideally you should use a Gradle version that is compatible with what the Jib plugin uses at image building time. (SeeVersion Matrix.)
    plugins {  id'java-gradle-plugin'...}dependencies {  compileOnly'com.google.cloud.tools:jib-gradle-plugin-extension-api:0.4.0'}
  2. Add a text filesrc/main/resources/META-INF/services/com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension (Maven) /src/main/resources/META-INF/services/com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension (Gradle) and list your classes that implements the Jib Maven/Gradle Plugin Extension API below. See theMaven andGradle examples.
  3. ImplementJibMavenPluginExtension (Maven) /JibGradlePluginExtension (Gradle).

Using Dependency Injection (Maven)

The approach described above uses JDK service loader to create the instance of the extension. With Maven you can alternatively let your extension being created by theMaven dependency injection container. This allows you to inject shared Maven components into you extension to perform more sophisticated tasks.

  1. Instead ofsrc/main/resources/META-INF/services/com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension, create a text filesrc/main/resources/META-INF/sisu/javax.inject.Named and list your classes that implements the Jib Maven Plugin Extension API. Maven dependency injection container needs this file to find the classes to consider. See an example file injib-layer-filter-extension-maven. Alternatively you can use thesisu-maven-plugin to generate this file, as described in theMaven documentation.

  2. Add the@javax.inject.Named and@javax.inject.Singleton annotations to your classes that implement the Jib Maven Plugin Extension API to make it Maven components. Usejavax.inject.Inject annotation on fields, constructors or methods to get shared Maven components.

@Named@SingletonpublicclassMyExtensionimplementsJibMavenPluginExtension<Configuration> {// example for injected shared Maven component@InjectprivateProjectDependenciesResolverdependencyResolver;}

Updating Container Build Plan

The extension API passes inContainerBuildPlan, which is the container build plan originally prepared by Jib plugins. The build plan describes in a declarative way how it plans to build a container image.

The class is a Java API forContainer Build Plan Specification. The Container Build Plan Specification is a general specification independent of Jib. The Container Build Plan Java API is a light-weight, standalone API implementing the spec, and it is published to Maven Central (jib-build-plan). The Build Plan classes, once instantiated, are all stateless, immutable "value classes" (holding only simple values). You can inspect the values using simple getters, and when you want to "modify" values, usetoBuilder() to create new instances.

Defining Extension-Specific Configuration

Sometimes, you may want to make your extension configurable by the extension end-users. See"Using Jib Plugin Extensions" to understand how end-users can provide extra configuration to an extension.

  • Simple string properties (map): the Extension API has a built-in support for end-users passing simple string map. If your extension does not need complex configuration structure, prefer this approach.

  • Complex configuration structure: define your configuration class and havegetExtraConfigType() return the class. See theMaven andGradle examples.

    • Gradle-specific: your configuration class must have a 1-arg constructor accepting a GradleProject.

Version Matrix

jib-maven-pluginjib-maven-plugin-extension-api
2.5.0 - current0.4.0
2.3.0 - 2.4.00.3.0
jib-gradle-pluginjib-gradle-plugin-extension-apiJib Plugin Runtime Gradle API*
2.5.0 - current0.4.05.2.1
2.4.00.3.05.2.1

* For example, it is recommended to use Gradle 5.2.1 or only use the API available in 5.2.1 to develop an extension for Jib Gradle 2.5.0.

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors24


[8]ページ先頭

©2009-2025 Movatter.jp