Skip to content

Commit

Permalink
Merge pull request #6 from fga-eps-mds/fix#42/fix-docker
Browse files Browse the repository at this point in the history
[FIX] Modifica configurações do Docker da Aplicação (fga-eps-mds/2024.2-ARANDU-DOC#42)
  • Loading branch information
dartmol203 authored Dec 8, 2024
2 parents 643a2bf + 8706b03 commit c572cb3
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 25 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
3 changes: 0 additions & 3 deletions .env.dev

This file was deleted.

11 changes: 11 additions & 0 deletions .env.dev.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MONGODB_URI=
MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
ME_CONFIG_MONGODB_ADMINUSERNAME=
ME_CONFIG_MONGODB_ADMINPASSWORD=
ME_CONFIG_MONGODB_URL=
ME_CONFIG_BASICAUTH=
ME_CONFIG_BASICAUTH_USERNAME=
ME_CONFIG_BASICAUTH_PASSWORD=
USER_SERVICE_URL=
AUTH_SERVICE_URL=
11 changes: 11 additions & 0 deletions .env.prod.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MONGODB_URI=
MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
ME_CONFIG_MONGODB_ADMINUSERNAME=
ME_CONFIG_MONGODB_ADMINPASSWORD=
ME_CONFIG_MONGODB_URL=
ME_CONFIG_BASICAUTH=
ME_CONFIG_BASICAUTH_USERNAME=
ME_CONFIG_BASICAUTH_PASSWORD=
USER_SERVICE_URL=
AUTH_SERVICE_URL=
24 changes: 21 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
FROM node:22-alpine
FROM node:18 AS base

WORKDIR /app

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

COPY package*.json ./
RUN npm install nodemon --save-dev

FROM base AS builder
WORKDIR /app
RUN npm install

COPY . .

COPY .env .env
RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV=development

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/ ./

EXPOSE 3002

ENV PORT=3002

CMD ["npm", "run", "start:dev"]
32 changes: 32 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM node:18 AS base

WORKDIR /app

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

RUN npm install nodemon --save-dev

FROM base AS builder
WORKDIR /app
RUN npm install
COPY . .

COPY .env .env
RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/ ./

EXPOSE 3002

ENV PORT=3002

CMD ["npm", "run", "start:prod"]
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: build
build:
npm install && docker-compose build --no-cache

.PHONY: start
start:
docker-compose up

.PHONY: run
run:
npm install && docker-compose build --no-cache && docker-compose up

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

networks:
calculus-network:
driver: bridge
arandu-network:
name: arandu-network
external: true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "nest start --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --passWithNoTests --no-cache --runInBand",
"test:all": "npm run test -- --coverage --config jest.config.ts",
Expand Down
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Logger, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ConfigService } from '@nestjs/config';
import { Logger, ValidationPipe } from '@nestjs/common';

const configService = new ConfigService();
const logger = new Logger('Main');
Expand All @@ -10,7 +10,8 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
app.enableCors();
await app.listen(configService.get('PORT'));
logger.log(`Application listening on port ${configService.get('PORT')}`);
await app.listen(configService.get('PORT'), '0.0.0.0', () => {
logger.log(`Application listening on port ${configService.get('PORT')}`);
});
}
bootstrap();

0 comments on commit c572cb3

Please sign in to comment.