Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions docs/docker-deployment-guide.md
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>
```
Comment on lines +8 to +31

Choose a reason for hiding this comment

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

medium

배포 가이드의 내용이 일부 혼란스럽게 작성되어 있어 사용자가 따라하기 어려울 수 있습니다. 현재 가이드는 빌드, 로컬 실행, 푸시 단계가 서로 일관되지 않고 중복되는 부분이 있습니다.

  • 이미지 이름 불일치: 1번 단계에서 빌드한 이미지(leeyunseong/...)와 2번에서 실행하려는 이미지(econo-recruit-fe) 이름이 다릅니다.
  • 푸시 단계 중복: 1번의 build --push와 3번의 push가 중복됩니다.

명확한 워크플로우를 위해, 빌드와 푸시를 한번에 하는 방법 또는 빌드/테스트/푸시를 단계별로 하는 방법 중 하나로 통일하여 안내하는 것을 권장합니다.

또한, leeyunseong/econo-recruit-fe와 같이 개인 Docker Hub 사용자 이름을 사용하는 대신, <YOUR_DOCKERHUB_USERNAME>/<IMAGE_NAME>과 같은 플레이스홀더를 사용하거나 조직의 리포지토리를 사용하도록 안내하는 것이 좋습니다.


## 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`).
49 changes: 49 additions & 0 deletions docs/local-docker-start-guide.md
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

Choose a reason for hiding this comment

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

medium

로컬 개발 환경에서 이미지를 빌드하는 경우, 보통 현재 사용 중인 아키텍처(e.g., amd64 or arm64)에 대해서만 빌드하면 충분합니다. docker buildx를 사용하여 여러 플랫폼용으로 빌드하는 것은 배포용 이미지를 만들 때 더 적합합니다.

로컬 실행 가이드인 만큼, 개발자들이 더 간단하게 사용할 수 있도록 docker build 명령어로 변경하는 것을 제안합니다. 이렇게 하면 --platform 옵션에 대해 고민할 필요가 없고, 빌드된 이미지가 바로 로컬 도커 데몬에 저장되어 실행하기 편리합니다.

Suggested change
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t econo-recruit-fe:<version> \
-f frontend/Dockerfile frontend \
docker build -t econo-recruit-fe:<version> -f frontend/Dockerfile frontend

```

## 3. 컨테이너 올리기

컨테이너를 실행시킵니다.

```sh
docker run -d \
--name econo-recruit-fe \
-p 3000:3000 \
econo-recruit-fe:<version>
```
12 changes: 12 additions & 0 deletions frontend/.dockerignore
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
39 changes: 39 additions & 0 deletions frontend/Dockerfile
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

Choose a reason for hiding this comment

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

high

최종 runner 이미지에 .env.production 파일을 복사하는 것은 몇 가지 문제를 일으킬 수 있습니다.

  • 재사용성 저하: 빌드 시점의 환경 변수 값이 이미지에 하드코딩되어, 다른 환경(e.g., staging, production)에서 동일한 이미지를 다른 설정으로 재사용하기 어렵게 만듭니다.
  • 보안 위험: .env.production 파일에 API 키와 같은 민감한 정보가 포함된 경우, 해당 정보가 이미지 내에 그대로 저장됩니다. 이 이미지가 외부에 노출되면 보안 사고로 이어질 수 있습니다.

Next.js는 NEXT_PUBLIC_으로 시작하는 변수를 빌드 시점에 에셋에 포함시키므로, builder 스테이지에서 .env.production 파일을 사용하는 것은 올바른 접근입니다.

하지만 runner 스테이지에서는 이 파일을 복사하는 대신, docker run 명령어 실행 시 -e 옵션이나 --env-file 옵션을 사용하여 런타임에 환경 변수를 주입하는 것이 좋습니다.

따라서 이 라인을 제거하여 런타임 환경 변수에 의존하도록 수정하는 것을 강력히 권장합니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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:version

gemini 리뷰처럼 --env-file 추가해서 배포할때 env 를 숨기면 어떨까요?


EXPOSE 3000
CMD ["pnpm", "run", "start:no-db"]
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "next dev",
"build": "next build",
"start": "node database.js && next start",
"start:no-db": "next start",
Copy link
Collaborator

Choose a reason for hiding this comment

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

배포할때 db.js 없이 실행하는 이유가 있을까요?
((사실 database.js 가 있는지도 처음 알았네요😭 이제는 사용하지 않는 로직인가요..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

백업용이라 production에서는 필요없을 듯 합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

별도의 sqlite가 서버에 셋팅되고 있지않아서, no-db옵션을 추가한 것도 있습니다 ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

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

아하 답변 감사합니당!!

"lint": "next lint",
"cy:open": "cypress open"
},
Expand Down