NestJS 기반 모노레포에서 api-gateway 앱을 npm run build로 빌드하고, Docker를 통해 배포 가능한 상태로 만드는 것이 목적임.
/
├── apps/
│ └── api-gateway/
├── libs/
├── proto/
├── Dockerfile
├── .env
├── tsconfig.base.json
npm run build api-gateway
docker build -t api-gateway -f apps/api-gateway/Dockerfile .
docker run -p 5010:3000 -e PORT=3000 api-gateway
import x from "../../../../libs/..." 형태로 작성된 코드가 빌드 후에도 유지되며 오류 발생tsconfig.json에 path alias 추가{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@grpc-types/*": ["libs/grpc-types/*"],
"@rest-dto/*": ["libs/rest-dto/*"],
"@graphql/*": ["libs/graphql/*"]
}
}
}
import { LoginRequest } from "@grpc-types/auth";
.js, .js.map 파일 생성tsconfig.json에서 "outDir"이 설정되지 않았거나, sourcemap:true 였기 때문.tsconfig.build.json에 outDir을 명확히 지정하고 ,sourcemap: false 로 변경{
"compilerOptions": {
"outDir": "./dist"
},
"exclude": ["node_modules", "dist"]
}
문제: 빌드된 Docker 이미지 내에서 proto 폴더가 없다는 오류 발생
해결:
COPY ./proto ./proto
COPY .env ./
런타임 이미지에서도 .proto가 필요하면 아래처럼 추가 복사
COPY --from=builder /app/proto ./proto
Cannot find module '../../../../libs/grpc-types/auth'.js 파일 확인 → require('../../../../libs/...')로 바뀌어 있으면 alias 적용 실패tsconfig 설정을 다시 확인하고 nest build로 빌드하여 해결docker builder prune 또는 --no-cache 옵션 사용@nestjs/cli/commands 모듈 오류.env 누락JwtStrategy requires a secret or key 오류 발생 → .env 명시적으로 복사ufw allow 5000 설정으로 해결 sudo ufw status numbered
sudo ufw delete <제일 앞의 index 번호>curl http://<서버 IP>:5000
docker run --name api-gateway -p 5000:3000 api-gateway