ci: cache Gradle work during Docker image builds#98
Merged
tlarbals824 merged 1 commit intodevelopfrom May 5, 2026
Merged
Conversation
Move release Docker publishing to a jar-only runtime image and use Gradle's CI cache for the application build. This keeps Docker focused on packaging and lets setup-gradle own dependency and build-cache reuse across CI jobs.\n\nConstraint: Docker-internal Gradle builds could not directly reuse the host Gradle cache used by CI.\nRejected: BuildKit-only Gradle cache inside Docker | improves the old shape but still couples compilation to image construction.\nConfidence: high\nScope-risk: moderate\nDirective: Keep release image builds jar-only unless runtime packaging needs source-aware image generation.\nTested: ./gradlew build --build-cache --no-daemon; docker build --no-cache -t ject-server:jar-only-runtime-test .; container app.jar/wget BusyBox smoke; git diff --check\nNot-tested: actionlint unavailable locally; GitHub Actions cache round-trip
b79a35b to
2262074
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제
기존 release 이미지 빌드는 Dockerfile 내부에서 Gradle build를 수행했습니다.
이 구조에서는 CI가 제공하는 Gradle cache를 직접 활용하기 어렵고, Docker image build와 애플리케이션 컴파일이 강하게 묶입니다. 그 결과 소스만 조금 바뀌어도 Docker build 안에서 Gradle 의존성/빌드 캐시 재사용이 제한될 수 있습니다.
CI build workflow도
actions/cache와gradle/actions/setup-gradle을 함께 사용하고 있어 캐시 책임이 중복되어 있었습니다.수정 내용
1. Dockerfile을 jar-only runtime image로 단순화
Dockerfile에서 Gradle build stage를 제거하고, CI에서 만든 JAR만 이미지에 복사하도록 변경했습니다.
이제 Docker image build는 런타임 이미지 구성만 담당합니다.
2. release workflow에서 먼저 JAR 빌드
release job에서 Docker build 전에 Gradle로 bootJar를 생성합니다.
app.jar로 고정해서 Dockerfile의 wildcard ambiguity도 제거했습니다.3. Docker build context 최소화
.dockerignore를 추가해 Docker build context를 런타임 이미지 생성에 필요한 파일로 제한했습니다.4. CI build cache 정리
ci-push,ci-pr에서 수동actions/cache단계를 제거하고gradle/actions/setup-gradle@v4에 캐시 책임을 일원화했습니다.그리고 Gradle build cache 사용을 명시했습니다.
프로젝트 기본값으로도 build cache를 켰습니다.
org.gradle.caching=true기대 효과
COPY app.jar중심으로 단순화검증
./gradlew build --build-cache --no-daemondocker build --no-cache -t ject-server:jar-only-runtime-test ./app/app.jar, BusyBoxwget확인git diff --check참고
로컬에
actionlint가 없어 workflow 정적 검사는 수행하지 못했습니다. GitHub Actions cache round-trip은 CI 실행에서 최종 확인하면 됩니다.