-
Notifications
You must be signed in to change notification settings - Fork 2
build: docker build setting and make guideline #318
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Docker Deployment Guide | ||
|
|
||
| ## 1) Build image | ||
|
|
||
| **레포지토리 루트**에서 실행하세요. 먼저, 반드시 .env.production 파일을 준비해야 합니다. | ||
|
|
||
| ```bash | ||
| docker buildx build \ | ||
| --platform linux/amd64,linux/arm64 \ | ||
| -t leeyunseong/econo-recruit-fe:<version> \ | ||
| -f frontend/Dockerfile frontend \ | ||
| --push | ||
| ``` | ||
|
|
||
| ## 2) Run locally | ||
|
|
||
| ```bash | ||
| docker run -d \ | ||
| --name econo-recruit-fe \ | ||
| -p 3000:3000 \ | ||
| econo-recruit-fe:<version> | ||
| ``` | ||
|
|
||
| ## 3) Push to registry | ||
|
|
||
| 먼저 Docker Hub Push 권한을 관리자에게 요청 부탁드립니다. | ||
|
|
||
| ```bash | ||
| docker tag econo-recruit-fe:<version> leeyunseong/econo-recruit-fe:<version> | ||
| docker push leeyunseong/econo-recruit-fe:<version> | ||
| ``` | ||
|
|
||
| ## 4) Run on EC2 | ||
|
|
||
| ```bash | ||
| docker pull leeyunseong/econo-recruit-fe:<version> | ||
| docker run -d \ | ||
| --name econo-recruit-fe \ | ||
| --restart unless-stopped \ | ||
| -p 3000:3000 \ | ||
| leeyunseong/econo-recruit-fe:<version> | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - Default app port in container: `3000`. | ||
| - `NEXT_PUBLIC_*` values are baked into assets at image build time. | ||
| - Docker build will fail fast if required public vars are missing. | ||
| - Keep runtime `--env-file` as well if server routes read non-public env values. | ||
| - Ensure EC2 Security Group allows inbound traffic on the service port (for example `80` or `3000`). | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||||||||
| # 로컬 실행 가이드 for BE | ||||||||||||
|
|
||||||||||||
| 이 문서는 백엔드 개발자를 위해 로컬에서 도커를 실행시켜 API를 테스트 해볼 수 있게 로컬에서 구축할 수 있는 방법을 제공합니다. | ||||||||||||
|
|
||||||||||||
| # 실행 환경 | ||||||||||||
|
|
||||||||||||
| - 실행하려는 machine에 docker가 준비되어있어야 합니다. | ||||||||||||
|
|
||||||||||||
| ## 1. 환경변수 세팅 | ||||||||||||
|
|
||||||||||||
| 먼저, `/frontend` 디렉토리에 `.env.production` 파일을 다음과 같이 생성하세요. | ||||||||||||
|
|
||||||||||||
| ```text | ||||||||||||
| NEXT_PUBLIC_API_URL="<YOUR_API_ENDPOINT>/api/v1" | ||||||||||||
| NEXT_PUBLIC_API_URL_V2="<YOUR_API_ENDPOINT>/api/v2" | ||||||||||||
| NEXT_PUBLIC_STAGE="development" | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| 예를 들어 서버가 localhost:8080에서 실행되고 있다면, 환경변수는 다음과 같습니다. | ||||||||||||
|
|
||||||||||||
| ```bash | ||||||||||||
| NEXT_PUBLIC_API_URL="http://localhost:8080/api/v1" | ||||||||||||
| NEXT_PUBLIC_API_URL_V2="http://localhost:8080/api/v2" | ||||||||||||
| ... | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ## 2. Docker 이미지 빌드 | ||||||||||||
|
|
||||||||||||
| 그다음 **레포지토리 루트**에서 docker image를 빌드합니다. | ||||||||||||
|
|
||||||||||||
| 주의사항: platform은 본인 운영체제에 맞는 버전으로 빌드해야합니다. 따라서 자유롭게 수정해주시기 바랍니다. | ||||||||||||
|
|
||||||||||||
| ```sh | ||||||||||||
| docker buildx build \ | ||||||||||||
| --platform linux/amd64,linux/arm64 \ | ||||||||||||
| -t econo-recruit-fe:<version> \ | ||||||||||||
| -f frontend/Dockerfile frontend \ | ||||||||||||
|
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로컬 개발 환경에서 이미지를 빌드하는 경우, 보통 현재 사용 중인 아키텍처(e.g., 로컬 실행 가이드인 만큼, 개발자들이 더 간단하게 사용할 수 있도록
Suggested change
|
||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ## 3. 컨테이너 올리기 | ||||||||||||
|
|
||||||||||||
| 컨테이너를 실행시킵니다. | ||||||||||||
|
|
||||||||||||
| ```sh | ||||||||||||
| docker run -d \ | ||||||||||||
| --name econo-recruit-fe \ | ||||||||||||
| -p 3000:3000 \ | ||||||||||||
| econo-recruit-fe:<version> | ||||||||||||
| ``` | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| node_modules | ||
| .next | ||
| .git | ||
| .gitignore | ||
| .DS_Store | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| coverage | ||
| cypress | ||
| *.local |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| FROM node:20-bookworm-slim AS deps | ||
| WORKDIR /app | ||
| ENV PNPM_HOME="/pnpm" | ||
| ENV PATH="$PNPM_HOME:$PATH" | ||
| RUN corepack enable | ||
|
|
||
| COPY package.json pnpm-lock.yaml ./ | ||
| RUN pnpm install --frozen-lockfile | ||
|
|
||
| FROM node:20-bookworm-slim AS builder | ||
| WORKDIR /app | ||
| ENV PNPM_HOME="/pnpm" | ||
| ENV PATH="$PNPM_HOME:$PATH" | ||
| RUN corepack enable | ||
|
|
||
|
|
||
| COPY --from=deps /app/node_modules ./node_modules | ||
| COPY . . | ||
| COPY .env.production ./.env.production | ||
| RUN pnpm run build | ||
|
|
||
| FROM node:20-bookworm-slim AS runner | ||
| WORKDIR /app | ||
| ENV NODE_ENV=production | ||
| ENV PORT=3000 | ||
| ENV PNPM_HOME="/pnpm" | ||
| ENV PATH="$PNPM_HOME:$PATH" | ||
| RUN corepack enable | ||
|
|
||
| COPY package.json pnpm-lock.yaml ./ | ||
| RUN pnpm install --frozen-lockfile --prod | ||
|
|
||
| COPY --from=builder /app/.next ./.next | ||
| COPY --from=builder /app/public ./public | ||
| COPY --from=builder /app/next.config.js ./next.config.js | ||
| COPY --from=builder /app/.env.production ./.env.production | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최종
Next.js는 하지만 따라서 이 라인을 제거하여 런타임 환경 변수에 의존하도록 수정하는 것을 강력히 권장합니다.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docker run -p 3000:3000 \
--env-file frontend/.env.production \
econo-recruit-fe:versiongemini 리뷰처럼 --env-file 추가해서 배포할때 env 를 숨기면 어떨까요? |
||
|
|
||
| EXPOSE 3000 | ||
| CMD ["pnpm", "run", "start:no-db"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "node database.js && next start", | ||
| "start:no-db": "next start", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 배포할때 db.js 없이 실행하는 이유가 있을까요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 백업용이라 production에서는 필요없을 듯 합니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 별도의 sqlite가 서버에 셋팅되고 있지않아서, no-db옵션을 추가한 것도 있습니다 ㅎㅎ
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 답변 감사합니당!! |
||
| "lint": "next lint", | ||
| "cy:open": "cypress open" | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배포 가이드의 내용이 일부 혼란스럽게 작성되어 있어 사용자가 따라하기 어려울 수 있습니다. 현재 가이드는 빌드, 로컬 실행, 푸시 단계가 서로 일관되지 않고 중복되는 부분이 있습니다.
leeyunseong/...)와 2번에서 실행하려는 이미지(econo-recruit-fe) 이름이 다릅니다.build --push와 3번의push가 중복됩니다.명확한 워크플로우를 위해, 빌드와 푸시를 한번에 하는 방법 또는 빌드/테스트/푸시를 단계별로 하는 방법 중 하나로 통일하여 안내하는 것을 권장합니다.
또한,
leeyunseong/econo-recruit-fe와 같이 개인 Docker Hub 사용자 이름을 사용하는 대신,<YOUR_DOCKERHUB_USERNAME>/<IMAGE_NAME>과 같은 플레이스홀더를 사용하거나 조직의 리포지토리를 사용하도록 안내하는 것이 좋습니다.