I deployed a Spring Boot project with Docker, enforced Continuous Delivery, and ran into a big problem. The speed and performance of Oracle's VMs were taking too much time to compile and build the spring boot, causing the build to fail in the Github flow.
2024/01/03 15:09:04 Run Command Timeout
While debugging to troubleshoot an issue that was working well locally, but only in a VM deployment, I started to get frustrated with the slow builds, and even though I tried multi-staging and moderately utilizing Docker's cache features, the builds themselves were too slow for a quick fix.
jib {
from {
image = "azul/zulu-openjdk-alpine:21-jre-headless-latest"
}
to {
image = "hojunsong/tripsketch:latest"
}
container {
entrypoint = listOf("java", "-cp", "/app/resources:/app/classes:/app/libs/*", "kr.kro.ApplicationKt")
}
}
The listof syntax is used in Kotlin, so you'll need to use "[]" in Java.
- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Sign up for Docker, get an access token, and log in with secret.
- name: Build and push Docker image with Jib
run: |
./gradlew jib
Having the github workflow do the building for me has also been beneficial in terms of resources.
https://hub.docker.com/r/hojunsong/tripsketch
tripsketch:
build:
context: .
dockerfile: tripsketch.dockerfile
- > After the change
tripsketch:
image: hojunsong/tripsketch:latest
Reduced build time from 10+ minutes to less than a minute.
Layer Separation: Jib divides an application into multiple layers. For example, dependencies, resources, and classes are placed in different layers. By doing this, parts that have not changed do not need to be rebuilt, reducing build time.
Caching Mechanism: Jib stores layers used in previous builds in a cache. If a certain layer has not changed in a new build, Jib reuses the cached layer, shortening the build time.
Container Registry Optimization: Jib can directly push the built image to a container registry. In this process, only the necessary layers are pushed, and existing layers are skipped. This reduces data transfer time.
No Need for Docker Daemon: Jib can operate without a Docker daemon. This simplifies the build process and easily integrates into the build pipeline.
Plugin Integration: Integrated with build tools like Maven or Gradle, Jib works well with the existing Java build process and can be used without additional settings or scripts.
I can skip the dockerfile below and save resources on VM.
FROM azul/zulu-openjdk-alpine:21 as build
RUN apk add git && \
mkdir /tripsketch && \
git clone --branch main https://github.com/trip-sketch/tripsketch /tripsketch
WORKDIR /tripsketch
RUN ./gradlew build -x test --no-daemon --parallel
- Google. “Jib: Build Container Images for Your Java Applications.” https://cloud.google.com/java/getting-started/jib?hl=en.