Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ jobs:
push: true
tags: ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }}


- name: Set image build result
if: always()
id: image-build-result
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM openjdk:21-jdk as builder
FROM --platform=linux/arm64 openjdk:21-jdk as builder
WORKDIR /workspace/app

# JAR 파일을 레이어별로 추출
COPY build/libs/*SNAPSHOT.jar app.jar
RUN java -Djarmode=layertools -jar app.jar extract

FROM openjdk:21-jdk
FROM --platform=linux/arm64 openjdk:21-jdk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

플랫폼을 linux/arm64로 하드코딩하면 x86_64 (amd64) 아키텍처에서 Docker 이미지를 빌드하거나 실행할 때 에뮬레이션으로 인해 성능이 크게 저하될 수 있습니다.

Dockerfile을 여러 아키텍처에서 유연하게 사용할 수 있도록 ARG를 사용하여 플랫폼을 동적으로 설정하는 것을 권장합니다. Docker는 빌드 시 TARGETPLATFORM이라는 특별한 ARG를 자동으로 제공하여 이를 쉽게 처리할 수 있습니다.

다음과 같이 수정하면 빌드 환경에 맞는 최적의 이미지를 생성할 수 있습니다. ${TARGETPLATFORM:-linux/amd64} 구문은 TARGETPLATFORM 인자가 없을 경우 기본값으로 linux/amd64를 사용하도록 합니다.

ARG TARGETPLATFORM
FROM --platform=${TARGETPLATFORM:-linux/amd64} openjdk:21-jdk as builder
WORKDIR /workspace/app

# JAR 파일을 레이어별로 추출
COPY build/libs/*SNAPSHOT.jar app.jar
RUN java -Djarmode=layertools -jar app.jar extract

FROM --platform=${TARGETPLATFORM:-linux/amd64} openjdk:21-jdk

WORKDIR /dnd_13th_5team_dev

COPY --from=builder /workspace/app/spring-boot-loader/ ./
Expand Down
Loading