diff --git a/docs/docker-deployment-guide.md b/docs/docker-deployment-guide.md new file mode 100644 index 00000000..a7bd21fc --- /dev/null +++ b/docs/docker-deployment-guide.md @@ -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: \ + -f frontend/Dockerfile frontend \ + --push +``` + +## 2) Run locally + +```bash +docker run -d \ + --name econo-recruit-fe \ + -p 3000:3000 \ + econo-recruit-fe: +``` + +## 3) Push to registry + +먼저 Docker Hub Push 권한을 관리자에게 요청 부탁드립니다. + +```bash +docker tag econo-recruit-fe: leeyunseong/econo-recruit-fe: +docker push leeyunseong/econo-recruit-fe: +``` + +## 4) Run on EC2 + +```bash +docker pull leeyunseong/econo-recruit-fe: +docker run -d \ + --name econo-recruit-fe \ + --restart unless-stopped \ + -p 3000:3000 \ + leeyunseong/econo-recruit-fe: +``` + +## 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`). diff --git a/docs/local-docker-start-guide.md b/docs/local-docker-start-guide.md new file mode 100644 index 00000000..4c2dc1ef --- /dev/null +++ b/docs/local-docker-start-guide.md @@ -0,0 +1,49 @@ +# 로컬 실행 가이드 for BE + +이 문서는 백엔드 개발자를 위해 로컬에서 도커를 실행시켜 API를 테스트 해볼 수 있게 로컬에서 구축할 수 있는 방법을 제공합니다. + +# 실행 환경 + +- 실행하려는 machine에 docker가 준비되어있어야 합니다. + +## 1. 환경변수 세팅 + +먼저, `/frontend` 디렉토리에 `.env.production` 파일을 다음과 같이 생성하세요. + +```text +NEXT_PUBLIC_API_URL="/api/v1" +NEXT_PUBLIC_API_URL_V2="/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: \ + -f frontend/Dockerfile frontend \ +``` + +## 3. 컨테이너 올리기 + +컨테이너를 실행시킵니다. + +```sh +docker run -d \ + --name econo-recruit-fe \ + -p 3000:3000 \ + econo-recruit-fe: +``` diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 00000000..a2d8ad34 --- /dev/null +++ b/frontend/.dockerignore @@ -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 diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 00000000..6cf9d7f5 --- /dev/null +++ b/frontend/Dockerfile @@ -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 + +EXPOSE 3000 +CMD ["pnpm", "run", "start:no-db"] diff --git a/frontend/package.json b/frontend/package.json index 31e0c250..e202a6e8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,6 +6,7 @@ "dev": "next dev", "build": "next build", "start": "node database.js && next start", + "start:no-db": "next start", "lint": "next lint", "cy:open": "cypress open" },