Skip to content

Commit

Permalink
fix(fga-eps-mds/2024.2-ARANDU-DOC#42): modifies docker configuration …
Browse files Browse the repository at this point in the history
…and its files
  • Loading branch information
gabrielm2q committed Dec 4, 2024
1 parent 04fae21 commit 99bb629
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
.dockerignore

# Build dependencies
dist.do
node_modules
node_module
# dist.do
# node_modules
# node_module

# Misc
.eslintrc.js
Expand Down
19 changes: 0 additions & 19 deletions .env.dev

This file was deleted.

14 changes: 14 additions & 0 deletions .env.dev.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MONGODB_URI=
EMAIL_USER=
EMAIL_PASS=
SENDGRID_API_KEY=
JWT_SECRET=
JWT_EXPIRATION=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=
MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
MICROSOFT_TENANT_ID=
MICROSOFT_CALLBACK_URL=
FRONTEND_URL=
14 changes: 14 additions & 0 deletions .env.prod.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MONGODB_URI=
EMAIL_USER=
EMAIL_PASS=
SENDGRID_API_KEY=
JWT_SECRET=
JWT_EXPIRATION=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=
MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
MICROSOFT_TENANT_ID=
MICROSOFT_CALLBACK_URL=
FRONTEND_URL=
36 changes: 30 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
FROM node:22-alpine

WORKDIR /app
FROM node:22-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat

COPY package*.json ./
WORKDIR /app

RUN npm install
COPY package.json package-lock.json* ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

COPY .env .env
RUN npm run build

CMD ["npm", "run", "start:dev"]
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs \
&& adduser -S arandu -u 1001

COPY --chown=arandu:nodejs --from=builder /app/dist ./dist
COPY --chown=arandu:nodejs --from=builder /app/node_modules ./node_modules

USER arandu

EXPOSE 3000

ENV PORT=3000

CMD ["node", "dist/main.js"]
38 changes: 38 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:22-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json package-lock.json* ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

COPY .env.prod.template .env
RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs \
&& adduser -S arandu -u 1001

COPY --chown=arandu:nodejs --from=builder /app/dist ./dist
COPY --chown=arandu:nodejs --from=builder /app/node_modules ./node_modules

USER arandu

EXPOSE 3000

ENV PORT=3000

CMD ["node", "dist/main.js"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: build
build:
docker compose build

.PHONY: start
start:
docker compose up

.PHONY: run
run:
docker compose up --build

.PHONY: stop
stop:
docker compose down
18 changes: 8 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ services:
user-api:
container_name: user-api
restart: on-failure
build: .
environment:
- NODE_ENV=development
ports:
- 3000:3000
volumes:
- ./src:/app/src
- ./test:/app/test
build:
context: .
dockerfile: Dockerfile
image: user-api
env_file:
- .env
ports:
- "3000:3000"
networks:
- calculus-network
- arandu-network

networks:
calculus-network:
arandu-network:
driver: bridge
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { UsersModule } from './users/users.module';

import { AuthModule } from './auth/auth.module';
import * as Joi from 'joi';
import { AuthModule } from './auth/auth.module';

@Module({
imports: [
Expand Down

0 comments on commit 99bb629

Please sign in to comment.