Skip to content

Commit f5d055e

Browse files
authored
build: docker build setting and make guideline (#318)
2 parents 7910713 + 10d2ff4 commit f5d055e

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

docs/docker-deployment-guide.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Docker Deployment Guide
2+
3+
## 1) Build image
4+
5+
**레포지토리 루트**에서 실행하세요. 먼저, 반드시 .env.production 파일을 준비해야 합니다.
6+
7+
```bash
8+
docker buildx build \
9+
--platform linux/amd64,linux/arm64 \
10+
-t leeyunseong/econo-recruit-fe:<version> \
11+
-f frontend/Dockerfile frontend \
12+
--push
13+
```
14+
15+
## 2) Run locally
16+
17+
```bash
18+
docker run -d \
19+
--name econo-recruit-fe \
20+
-p 3000:3000 \
21+
econo-recruit-fe:<version>
22+
```
23+
24+
## 3) Push to registry
25+
26+
먼저 Docker Hub Push 권한을 관리자에게 요청 부탁드립니다.
27+
28+
```bash
29+
docker tag econo-recruit-fe:<version> leeyunseong/econo-recruit-fe:<version>
30+
docker push leeyunseong/econo-recruit-fe:<version>
31+
```
32+
33+
## 4) Run on EC2
34+
35+
```bash
36+
docker pull leeyunseong/econo-recruit-fe:<version>
37+
docker run -d \
38+
--name econo-recruit-fe \
39+
--restart unless-stopped \
40+
-p 3000:3000 \
41+
leeyunseong/econo-recruit-fe:<version>
42+
```
43+
44+
## Notes
45+
46+
- Default app port in container: `3000`.
47+
- `NEXT_PUBLIC_*` values are baked into assets at image build time.
48+
- Docker build will fail fast if required public vars are missing.
49+
- Keep runtime `--env-file` as well if server routes read non-public env values.
50+
- Ensure EC2 Security Group allows inbound traffic on the service port (for example `80` or `3000`).

docs/local-docker-start-guide.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 로컬 실행 가이드 for BE
2+
3+
이 문서는 백엔드 개발자를 위해 로컬에서 도커를 실행시켜 API를 테스트 해볼 수 있게 로컬에서 구축할 수 있는 방법을 제공합니다.
4+
5+
# 실행 환경
6+
7+
- 실행하려는 machine에 docker가 준비되어있어야 합니다.
8+
9+
## 1. 환경변수 세팅
10+
11+
먼저, `/frontend` 디렉토리에 `.env.production` 파일을 다음과 같이 생성하세요.
12+
13+
```text
14+
NEXT_PUBLIC_API_URL="<YOUR_API_ENDPOINT>/api/v1"
15+
NEXT_PUBLIC_API_URL_V2="<YOUR_API_ENDPOINT>/api/v2"
16+
NEXT_PUBLIC_STAGE="development"
17+
```
18+
19+
예를 들어 서버가 localhost:8080에서 실행되고 있다면, 환경변수는 다음과 같습니다.
20+
21+
```bash
22+
NEXT_PUBLIC_API_URL="http://localhost:8080/api/v1"
23+
NEXT_PUBLIC_API_URL_V2="http://localhost:8080/api/v2"
24+
...
25+
```
26+
27+
## 2. Docker 이미지 빌드
28+
29+
그다음 **레포지토리 루트**에서 docker image를 빌드합니다.
30+
31+
주의사항: platform은 본인 운영체제에 맞는 버전으로 빌드해야합니다. 따라서 자유롭게 수정해주시기 바랍니다.
32+
33+
```sh
34+
docker buildx build \
35+
--platform linux/amd64,linux/arm64 \
36+
-t econo-recruit-fe:<version> \
37+
-f frontend/Dockerfile frontend \
38+
```
39+
40+
## 3. 컨테이너 올리기
41+
42+
컨테이너를 실행시킵니다.
43+
44+
```sh
45+
docker run -d \
46+
--name econo-recruit-fe \
47+
-p 3000:3000 \
48+
econo-recruit-fe:<version>
49+
```

frontend/.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
.next
3+
.git
4+
.gitignore
5+
.DS_Store
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
pnpm-debug.log*
10+
coverage
11+
cypress
12+
*.local

frontend/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM node:20-bookworm-slim AS deps
2+
WORKDIR /app
3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable
6+
7+
COPY package.json pnpm-lock.yaml ./
8+
RUN pnpm install --frozen-lockfile
9+
10+
FROM node:20-bookworm-slim AS builder
11+
WORKDIR /app
12+
ENV PNPM_HOME="/pnpm"
13+
ENV PATH="$PNPM_HOME:$PATH"
14+
RUN corepack enable
15+
16+
17+
COPY --from=deps /app/node_modules ./node_modules
18+
COPY . .
19+
COPY .env.production ./.env.production
20+
RUN pnpm run build
21+
22+
FROM node:20-bookworm-slim AS runner
23+
WORKDIR /app
24+
ENV NODE_ENV=production
25+
ENV PORT=3000
26+
ENV PNPM_HOME="/pnpm"
27+
ENV PATH="$PNPM_HOME:$PATH"
28+
RUN corepack enable
29+
30+
COPY package.json pnpm-lock.yaml ./
31+
RUN pnpm install --frozen-lockfile --prod
32+
33+
COPY --from=builder /app/.next ./.next
34+
COPY --from=builder /app/public ./public
35+
COPY --from=builder /app/next.config.js ./next.config.js
36+
COPY --from=builder /app/.env.production ./.env.production
37+
38+
EXPOSE 3000
39+
CMD ["pnpm", "run", "start:no-db"]

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "node database.js && next start",
9+
"start:no-db": "next start",
910
"lint": "next lint",
1011
"cy:open": "cypress open"
1112
},

0 commit comments

Comments
 (0)