본문 바로가기
IT Knowledge/빌드도구

Jib개요 및 사용법(with maven, gradle)

by Seok. 2023. 8. 14.
반응형

Jib github : https://github.com/GoogleContainerTools

개요

Jib application 컨테이너 이미지로 패키징 하는 모든 단계를 처리하는 빠르고 간단한 컨테이너 이미지 빌더 입니다.

Docker daemon 이나 docker 대한 심층적인 숙달 없이도, Java Application 위해 최적화된 Docker or OCI 이미지를 구축 있도록 합니다.

Maven Gradle 플러그인과 Java 라이브러리로 사용할 있습니다.

  • Jib Core : Java용 범용 컨테이너 구축 라이브러리입니다.
  • Jib CLI : Jib Core를 사용하는 이미지를 빌드하기 위한 명령줄 인터페이스입니다.

 

기존 Docker Build Flow :

Jib build Flow

 목표

  • Fast - Deploy your changes fast. Jib separates your application into multiple layers, splitting dependencies from classes. Now you don’t have to wait for Docker to rebuild your entire Java application - just deploy the layers that changed.
  • Reproducible - Rebuilding your container image with the same contents always generates the same image. Never trigger an unnecessary update again.
  • Daemonless - Reduce your CLI dependencies. Build your Docker image from within Maven or Gradle and push to any registry of your choice. No more writing Dockerfiles and calling docker build/push.

Jib 사용하여 application 컨테이너 하는 방법.

Maven(Maven 3.5 이상 필요)

https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin

<pom.xml>

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <version>0.9.0</version>
  <configuration>
    <to>
      <image>gcr.io/my-project/image-built-with-jib</image>
    </to>
  </configuration>
</plugin>

빌드시 명령어

# Builds to a container image registry.
$ mvn compile jib:build

# Builds to a Docker daemon.
$ mvn compile jib:dockerBuild

 

Gradle

https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin

<Build.gradle>

plugins {
  id 'com.google.cloud.tools.jib' version '0.9.0'
}
jib.to.image = 'gcr.io/my-project/image-built-with-jib'

빌드시 명령어

# Builds to a container image registry.
$ gradle jib

# Builds to a Docker daemon.
$ gradle jibDockerBuild

 

Gradle 예제

jib {
    from {
        image='remote_repository/alpine-image:1.1.1'
    }
    to {
        image = "${docker_registry}/${project}:${tag}"
    }
    container {
        creationTime = "USE_CURRENT_TIMESTAMP"
        jvmFlags = ['-Djava.security.egd=file:/dev/./urandom', '-Duser.timezone=Asia/Seoul', "-Dspring.profile.active="+profile]
        labels = ['support.example.com']

    }
}

Extended Usage

 

Extended configuration options provide additional options for customizing the image build.

Field Type Default Description
to to Required Configures the target image to build your application to.
from from See from Configures the base image to build your application on top of.
container container See container Configures the container that is run from your image.
extraDirectories extraDirectories See extraDirectories Configures the directories used to add arbitrary files to the image.
outputPaths outputPaths See outputPaths Configures the locations of additional build artifacts generated by Jib.

 

 

[From]

Property Type Default Description
image string eclipse-temurin:{8,11,17}-jre (or jetty for WAR) The image reference for the base image. The source type can be specified using a special type prefix.
auth auth None Specifies credentials directly (alternative to credHelper).

 

[To]

Property Type Default Description
image string Required The image reference for the target image. This can also be specified via the -Dimage command line option. If the tag is not present here :latest is implied.
auth auth None Specifies credentials directly (alternative to credHelper).
tags list None Additional tags to push to.

 

mvn clean compile jib:build -Djib.to.auth.username=account -Djib.to.auth.password=password

gradle jib -Djib.to.auth.username=account -Djib.to.auth.password=password

 

 

 

[container]

Property Type Default Description
appRoot string /app The root directory on the container where the app's contents are placed. Particularly useful for WAR-packaging projects to work with different Servlet engine base images by designating where to put exploded WAR contents; see WAR usage as an example.
args list None Additional program arguments appended to the command to start the container (similar to Docker's CMD instruction in relation with ENTRYPOINT). In the default case where you do not set a custom entrypoint, this parameter is effectively the arguments to the main method of your Java application.
creationTime string EPOCH Sets the container creation time. (Note that this property does not affect the file modification times, which are configured using <filesModificationTime>.) The value can be EPOCH to set the timestamps to Epoch (default behavior), USE_CURRENT_TIMESTAMP to forgo reproducibility and use the real creation time, or an ISO 8601 date-time parsable with DateTimeFormatter.ISO_DATE_TIME such as 2019-07-15T10:15:30+09:00 or 2011-12-03T22:42:05Z.
entrypoint list None The command to start the container with (similar to Docker's ENTRYPOINT instruction). If set, then jvmFlagsmainClassextraClasspath, and expandClasspathDependencies are ignored. You may also set <entrypoint>INHERIT</entrypoint> (<entrypoint><entry>INHERIT</entry></entrypoint> in old Maven versions) to indicate that the entrypoint and args should be inherited from the base image.*
environment map None Key-value pairs for setting environment variables on the container (similar to Docker's ENV instruction).
extraClasspath list None Additional paths in the container to prepend to the computed Java classpath.
expandClasspathDependencies boolean false  
filesModificationTime string EPOCH_PLUS_SECOND Sets the modification time (last modified time) of files in the image put by Jib. (Note that this does not set the image creation time, which can be set using <creationTime>.) The value should either be EPOCH_PLUS_SECOND to set the timestamps to Epoch + 1 second (default behavior), or an ISO 8601 date-time parsable with DateTimeFormatter.ISO_DATE_TIME such as 2019-07-15T10:15:30+09:00 or 2011-12-03T22:42:05Z.
format string Docker Use OCI to build an OCI container image.
jvmFlags list None Additional flags to pass into the JVM when running your application.
labels map None Key-value pairs for applying image metadata (similar to Docker's LABEL instruction).
mainClass string Inferred** The main class to launch the application from.
ports list None Ports that the container exposes at runtime (similar to Docker's EXPOSE instruction).
user string None The user and group to run the container as. The value can be a username or UID along with an optional groupname or GID. The following are all valid: useruiduser:groupuid:giduid:groupuser:gid.
volumes list None Specifies a list of mount points on the container.
workingDirectory string None The working directory in the container.

 

 

출처: <https://cloudplatform.googleblog.com/2018/07/introducing-jib-build-java-docker-images-better.html>

출처: <https://github.com/GoogleContainerTools>

반응형

'IT Knowledge > 빌드도구' 카테고리의 다른 글

Gradle install 방법  (2) 2023.08.14
Gradle의 이해  (0) 2023.08.14
Maven Wrapper의 이해와 사용법  (0) 2023.08.14
Maven 의 이해  (0) 2023.08.14
Gradle increase read timeout 조치방안  (4) 2022.06.17

댓글