Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#869 [Refactor] Docker 이미지 사이즈 줄이기 #870

Merged
merged 4 commits into from
Mar 13, 2025

Conversation

injoonH
Copy link
Member

@injoonH injoonH commented Mar 6, 2025

Summary

It closes #869

  • Multi-stage builds 이용해 사이즈를 2.99GB → 256MB로 줄였습니다. (약 91% 감소)

  • ECR에 표시되는 기존 이미지의 사이즈는 1,136MB인데, 이는 압축된 크기입니다. (Ref.)

    Starting with Docker version 1.9, the Docker client compresses image layers before pushing them to a V2 Docker registry. The output of the docker images command shows the uncompressed image size. Therefore, keep in mind that Docker might return a larger image than the image shown in the AWS Management Console.

  • 빌드 시간이 단축되었습니다.

    • AS-IS

      docker build --no-cache -t taxi-front:latest .  # 3m 31s (0/15 cache)
      docker build -t taxi-front:latest .             # 2m 29s (5/15 cache)
    • TO-BE

      docker build --no-cache -t taxi-front:latest .  # 2m 08s (2/20 cache)
      docker build -t taxi-front:latest .             # 1m 09s (8/20 cache)
  • pnpm buildtscvite가 사용되기 때문에 pnpm fetch, pnpm install--prod flag를 사용하지 않았습니다.

Images or Screenshots

image image image

Further Work

  • 디펜던시 설치 및 빌드 시 --prod flag를 사용하면 빌드 시간을 더욱 단축할 수 있습니다.
  • GitHub Actions environment variables를 설정해 테스트 환경과 라이브 환경에서의 URL을 다르게 배포할 수 있습니다.

@injoonH injoonH requested review from 14KGun and SnowSuno March 6, 2025 11:57
@injoonH injoonH self-assigned this Mar 6, 2025
@injoonH injoonH linked an issue Mar 6, 2025 that may be closed by this pull request
3 tasks
@injoonH injoonH added the 🔨refactoring 기존의 코드를 리팩토링합니다 label Mar 6, 2025
Copy link

netlify bot commented Mar 6, 2025

Deploy Preview for taxi-dev-preview ready!

Name Link
🔨 Latest commit 76a4713
🔍 Latest deploy log https://app.netlify.com/sites/taxi-dev-preview/deploys/67ce5c4c64636300092099d4
😎 Deploy Preview https://deploy-preview-870--taxi-dev-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@injoonH injoonH requested a review from kmc7468 March 6, 2025 12:25
@injoonH injoonH marked this pull request as ready for review March 7, 2025 06:42
@@ -3,7 +3,7 @@ server {
listen [::]:80;

location ~ ^/invite/(?<room_id>[^/]+) {
root /root/serve;
root /app/serve;
Copy link
Member

Choose a reason for hiding this comment

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

왜 root -> app으로 변경했나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nginx를 사용하기 위해 chmod +x를 해야 하는데, 이를 /root에서 실행하기보다 필요한 파일만 존재하는 디렉토리에 실행하는 것이 낫다고 생각하였습니다.

Comment on lines +11 to +16
ARG FRONT_URL
ARG BACK_URL
ARG OG_IMAGE_URL
ENV REACT_APP_FRONT_URL=$FRONT_URL
ENV REACT_APP_BACK_URL=$BACK_URL
ENV REACT_APP_OG_URL=$OG_IMAGE_URL
Copy link
Member

Choose a reason for hiding this comment

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

이만큼이 두 번 반복돼서 불편해여

Copy link
Member Author

Choose a reason for hiding this comment

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

Multi-stage builds를 사용할 경우 stage마다 ARG를 다시 선언해야 합니다. (Ref.)

Build arguments declared in the global scope of a Dockerfile aren't automatically inherited into the build stages. They're only accessible in the global scope.

@kmc7468 kmc7468 changed the title #869 Refactor: Reduce docker image size #869 [Refactor] Docker 이미지 사이즈 줄이기 Mar 9, 2025
Copy link
Member

@14KGun 14KGun left a comment

Choose a reason for hiding this comment

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

LGTM ❤️

Copy link
Member

@kmc7468 kmc7468 left a comment

Choose a reason for hiding this comment

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

LGTM! 작업해 주셔서 감사합니다! 엄청난 용량 절약이네요..

@kmc7468 kmc7468 merged commit 682059a into dev Mar 13, 2025
4 checks passed
@kmc7468 kmc7468 deleted the #869-reduce-docker-image-size branch March 13, 2025 11:42
@kmc7468
Copy link
Member

kmc7468 commented Mar 13, 2025

image

ㅋㅋㅋㅋㅋㅋ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨refactoring 기존의 코드를 리팩토링합니다
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] Docker 이미지 사이즈 줄이기
4 participants