jib에 대해 알아보자
spring으로 rest 서버를 만들어서 활용을 할 생각이여서 간단하게 만들고 개인 서버에 배포하려고 하는데
문득 spring은 사용자들이 많으니 컨테이너 빌드도 효율성 있게 하는 방법 있을까봐 찾아봤더니
역시나 구글에서 만든 jib이란 빌더를 발견했습니다.
그래서 써보니 cache도 없고 (docker build 시에 설정할 수 있지만) 빠르게 build가 가능해서 소개해보려 합니다.
jib이란??
Jib은 애플리케이션을 컨테이너 이미지로 패키징하는 모든 단계를 처리하는 빠르고 간단한 컨테이너 이미지 빌더입니다.
플러그인을 빌드에 추가하기만 하면 즉시 Java 애플리케이션을 컨테이너화할 수 있으며,
Docker파일을 작성하거나 Docker를 설치할 필요가 없고 Maven과 Gradle에 직접 통합됩니다.
Docker build flow:
Jib build flow:
Jib는 애플리케이션을 종속 항목, 리소스, 클래스 등 별개의 레이어로 구성하고 Docker 이미지 레이어 캐싱을 활용하여 변경사항만 다시 빌드함으로써 빌드를 빠르게 유지합니다.
Jib 레이어 구성과 작은 기본 이미지는 전체 이미지 크기를 작게 유지하여 성능과 휴대성을 향상시킵니다.
방법
저는 gradle을 사용하기 때문에 build.gradle 파일에 이런식으로 추가했습니다.
1
2
3
plugins {
id 'com.google.cloud.tools.jib' version '3.4.1'
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def jsonFile = file('config.json')
def parsedJson = new groovy.json.JsonSlurper().parseText(jsonFile.text)
def parseImage = parsedJson.get('base_path') + '/' + parsedJson.get('rest_tag') ?: parsedJson.get('base_path') + '/' + parsedJson.get('default_rest_tag')
def parseAllowInsecureRegistries = parsedJson.get('allow_insecure_registries') ?: false
jib {
from {
image = 'openjdk:21-slim'
platforms {
platform{
os = 'linux'
architecture = 'amd64'
}
}
}
to {
image = parseImage // 개인 repostiory를 사용해서 config 파일에서 추출해서 사용했습니다.
}
container {
allowInsecureRegistries = parseAllowInsecureRegistries
}
}
실행
1
./gradlew jib
자세한 사용법은 밑 참고란에 github을 참고하시면 되겠습니다.
참고
This post is licensed under CC BY 4.0 by the author.