From 5edc29ee2521b50d7b1c98425e4bc6ebe7bdfd94 Mon Sep 17 00:00:00 2001 From: Kenedy Bok Ephraim Date: Wed, 27 May 2026 16:04:07 +0000 Subject: [PATCH] feat: add Dockerfile for NestJS API (#115) - Multi-stage build: builder stage compiles TypeScript, production stage includes only prod dependencies (npm ci --omit=dev) - Uses node:18-alpine base image - Exposes port 3000 - Add api/.dockerignore to exclude node_modules, dist, coverage, .env files - Add docker-build job to CI workflow --- .github/workflows/ci.yml | 8 ++++++++ api/.dockerignore | 7 +++++++ api/Dockerfile | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 api/.dockerignore create mode 100644 api/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22295bc..f02ae91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,14 @@ jobs: - name: Run Tests run: cd api && npm run test + docker: + name: Docker Build (API) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build Docker image + run: docker build -t carbonchain-api ./api + security: name: Dependency Vulnerability Scan runs-on: ubuntu-latest diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 0000000..4c70ece --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1,7 @@ +node_modules +dist +coverage +.env +.env.* +!.env.example +*.log diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..50383bd --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,24 @@ +# Stage 1: Build +FROM node:18-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Stage 2: Production +FROM node:18-alpine AS production + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci --omit=dev + +COPY --from=builder /app/dist ./dist + +EXPOSE 3000 + +CMD ["node", "dist/main"]