From 0b98f82179e6e28973fe4313f3e778fdd519153d Mon Sep 17 00:00:00 2001 From: wooh Date: Tue, 26 May 2026 11:54:14 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20Docker=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=20=EB=B0=A9=EC=8B=9D=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile 내부 Gradle 빌드를 제거하고 사전 빌드된 bootJar를 이미지에 복사하도록 변경 - CI Docker Build 단계에서 bootJar 생성 후 Docker 이미지를 빌드하도록 수정 - Deploy 이미지 빌드 전에도 bootJar를 생성하도록 워크플로우 수정 - Docker context에 build/libs jar 파일이 포함되도록 .dockerignore 예외 추가 - Docker 빌드 중 Maven Central 403으로 의존성 다운로드가 실패하던 문제 방지 --- .dockerignore | 5 ++++- .github/workflows/ci.yml | 13 +++++++++++++ .github/workflows/deploy.yml | 13 +++++++++++++ Dockerfile | 13 +------------ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index 345b52e..bd0215b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,7 +2,10 @@ .github .gradle .idea -build +build/* +!build/libs +build/libs/* +!build/libs/*.jar out *.iml *.iws diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28fa465..26d8c32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,5 +44,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + cache: gradle + + - name: Grant Gradle permission + run: chmod +x ./gradlew + + - name: Build application jar + run: ./gradlew --no-daemon clean bootJar -x test + - name: Build Docker image run: docker build -t jobdri-api:${{ github.sha }} . diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 556e069..5e5ef1e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,6 +22,19 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + cache: gradle + + - name: Grant Gradle permission + run: chmod +x ./gradlew + + - name: Build application jar + run: ./gradlew --no-daemon clean bootJar -x test + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/Dockerfile b/Dockerfile index 03fe4f3..0e31ba8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,10 @@ -FROM eclipse-temurin:21-jdk-alpine AS builder - -WORKDIR /workspace - -COPY gradlew settings.gradle build.gradle ./ -COPY gradle ./gradle -RUN chmod +x gradlew - -COPY src ./src -RUN ./gradlew --no-daemon clean bootJar -x test - FROM eclipse-temurin:21-jre-alpine WORKDIR /app RUN addgroup -S jobdri && adduser -S jobdri -G jobdri -COPY --from=builder /workspace/build/libs/*.jar app.jar +COPY build/libs/*.jar app.jar USER jobdri