Skip to content

ci: cache Gradle work during Docker image builds#98

Merged
tlarbals824 merged 1 commit intodevelopfrom
fix/cache-gradle-docker-build
May 5, 2026
Merged

ci: cache Gradle work during Docker image builds#98
tlarbals824 merged 1 commit intodevelopfrom
fix/cache-gradle-docker-build

Conversation

@tlarbals824
Copy link
Copy Markdown
Collaborator

@tlarbals824 tlarbals824 commented May 5, 2026

문제

기존 release 이미지 빌드는 Dockerfile 내부에서 Gradle build를 수행했습니다.

docker build
└─ ./gradlew bootJar

이 구조에서는 CI가 제공하는 Gradle cache를 직접 활용하기 어렵고, Docker image build와 애플리케이션 컴파일이 강하게 묶입니다. 그 결과 소스만 조금 바뀌어도 Docker build 안에서 Gradle 의존성/빌드 캐시 재사용이 제한될 수 있습니다.

CI build workflow도 actions/cachegradle/actions/setup-gradle을 함께 사용하고 있어 캐시 책임이 중복되어 있었습니다.

수정 내용

1. Dockerfile을 jar-only runtime image로 단순화

Dockerfile에서 Gradle build stage를 제거하고, CI에서 만든 JAR만 이미지에 복사하도록 변경했습니다.

FROM eclipse-temurin:25-jre-alpine

ARG JAR_FILE=build/libs/app.jar
COPY ${JAR_FILE} app.jar

이제 Docker image build는 런타임 이미지 구성만 담당합니다.

2. release workflow에서 먼저 JAR 빌드

release job에서 Docker build 전에 Gradle로 bootJar를 생성합니다.

- uses: gradle/actions/setup-gradle@v4

- name: 애플리케이션 JAR 빌드
  run: |
    ./gradlew bootJar --no-daemon --build-cache
    BOOT_JAR=$(find build/libs -maxdepth 1 -type f -name '*.jar' ! -name '*-plain.jar' | head -n 1)
    test -n "$BOOT_JAR"
    cp "$BOOT_JAR" build/libs/app.jar

app.jar로 고정해서 Dockerfile의 wildcard ambiguity도 제거했습니다.

3. Docker build context 최소화

.dockerignore를 추가해 Docker build context를 런타임 이미지 생성에 필요한 파일로 제한했습니다.

*
!Dockerfile
!build/
!build/libs/
!build/libs/app.jar

4. CI build cache 정리

ci-push, ci-pr에서 수동 actions/cache 단계를 제거하고 gradle/actions/setup-gradle@v4에 캐시 책임을 일원화했습니다.

그리고 Gradle build cache 사용을 명시했습니다.

./gradlew build --build-cache

프로젝트 기본값으로도 build cache를 켰습니다.

org.gradle.caching=true

기대 효과

  • CI Gradle cache를 release build와 CI build에서 직접 활용
  • Docker image build는 COPY app.jar 중심으로 단순화
  • Docker build context 축소
  • Docker 내부 Gradle build 제거로 빌드/패키징 책임 분리
  • 불필요한 OAuth secret env 제거

검증

  • ./gradlew build --build-cache --no-daemon
  • docker build --no-cache -t ject-server:jar-only-runtime-test .
  • 컨테이너 내부 /app/app.jar, BusyBox wget 확인
  • git diff --check

참고

로컬에 actionlint가 없어 workflow 정적 검사는 수행하지 못했습니다. GitHub Actions cache round-trip은 CI 실행에서 최종 확인하면 됩니다.

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
@tlarbals824 tlarbals824 force-pushed the fix/cache-gradle-docker-build branch from b79a35b to 2262074 Compare May 5, 2026 07:10
@tlarbals824 tlarbals824 merged commit e3a99cb into develop May 5, 2026
@github-actions github-actions Bot deleted the fix/cache-gradle-docker-build branch May 5, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant