From b94dc328103779fcf46986bd4c57d7c6cc2c6563 Mon Sep 17 00:00:00 2001 From: Kadu Date: Thu, 12 Sep 2024 19:47:58 -0300 Subject: [PATCH 1/2] remove action --- .github/workflows/codesee-arch-diagram.yml | 23 ---------------------- 1 file changed, 23 deletions(-) delete mode 100644 .github/workflows/codesee-arch-diagram.yml diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml deleted file mode 100644 index 806d41d..0000000 --- a/.github/workflows/codesee-arch-diagram.yml +++ /dev/null @@ -1,23 +0,0 @@ -# This workflow was added by CodeSee. Learn more at https://codesee.io/ -# This is v2.0 of this workflow file -on: - push: - branches: - - main - pull_request_target: - types: [opened, synchronize, reopened] - -name: CodeSee - -permissions: read-all - -jobs: - codesee: - runs-on: ubuntu-latest - continue-on-error: true - name: Analyze the repo with CodeSee - steps: - - uses: Codesee-io/codesee-action@v2 - with: - codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} - codesee-url: https://app.codesee.io From 578430f64ee8289634c30773bb66411c4d6dd566 Mon Sep 17 00:00:00 2001 From: Kadu Date: Wed, 14 May 2025 14:31:19 -0300 Subject: [PATCH 2/2] update docker-compose and dockerfile --- .gitignore | 1 + app/backend/Dockerfile | 28 +++++++-- app/backend/Dockerfile.dev | 11 ---- app/backend/tsconfig.json | 15 ++++- app/frontend/Dockerfile | 28 +++++++-- app/whatsapp-api/Dockerfile | 28 +++++++-- app/whatsapp-api/Dockerfile.dev | 11 ---- app/whatsapp-api/tsconfig.json | 14 ++++- docker-compose.dev.yml | 103 -------------------------------- docker-compose.yml | 83 +++++++++++++++---------- 10 files changed, 145 insertions(+), 177 deletions(-) delete mode 100644 app/backend/Dockerfile.dev delete mode 100644 app/whatsapp-api/Dockerfile.dev delete mode 100644 docker-compose.dev.yml diff --git a/.gitignore b/.gitignore index c6bba59..6bc3c91 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,7 @@ web_modules/ .env.test.local .env.production.local .env.local +.env*local # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/app/backend/Dockerfile b/app/backend/Dockerfile index 23d4051..22f787a 100644 --- a/app/backend/Dockerfile +++ b/app/backend/Dockerfile @@ -1,13 +1,31 @@ -FROM node:18 - +# Etapa base +FROM node:20 AS base WORKDIR /app-backend +COPY package*.json ./ -COPY package.json . - +# Etapa de dependências +FROM base AS deps RUN npm install +# Etapa de desenvolvimento +FROM base AS dev +ENV NODE_ENV=development +COPY --from=deps /app-backend/node_modules ./node_modules COPY . . +CMD ["npm", "run", "dev"] +# Etapa de build (produção) +FROM base AS build +ENV NODE_ENV=production +COPY --from=deps /app-backend/node_modules ./node_modules +COPY . . RUN npm run build -CMD [ "npm", "run", "start" ] \ No newline at end of file +# Etapa final para produção +FROM node:20 AS prod +WORKDIR /app-backend +ENV NODE_ENV=production +COPY --from=build /app-backend/dist ./dist +COPY package*.json ./ +RUN npm install --omit=dev +CMD ["node", "dist/index.js"] diff --git a/app/backend/Dockerfile.dev b/app/backend/Dockerfile.dev deleted file mode 100644 index db2c895..0000000 --- a/app/backend/Dockerfile.dev +++ /dev/null @@ -1,11 +0,0 @@ -FROM node:18 - -WORKDIR /app-backend - -COPY package.json . - -RUN npm install - -COPY . . - -CMD [ "npm", "run", "dev" ] \ No newline at end of file diff --git a/app/backend/tsconfig.json b/app/backend/tsconfig.json index 8bdcfc6..cef3db5 100644 --- a/app/backend/tsconfig.json +++ b/app/backend/tsconfig.json @@ -70,7 +70,7 @@ // "newLine": "crlf", /* Set the newline character for emitting files. */ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + "noEmitOnError": false, /* Disable emitting files if any type checking errors are reported. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ @@ -85,7 +85,7 @@ /* Type Checking */ "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ @@ -107,5 +107,14 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*.ts"], + "exclude": [ + "node_modules", + "**/*.spec.ts", + "**/*.test.ts", + "**/*.e2e-spec.ts", + "**/*.d.ts", + "**/dist", + ], } diff --git a/app/frontend/Dockerfile b/app/frontend/Dockerfile index d50cddb..19b6832 100644 --- a/app/frontend/Dockerfile +++ b/app/frontend/Dockerfile @@ -1,13 +1,31 @@ -FROM node:18-alpine - +# Etapa base +FROM node:20-alpine AS base WORKDIR /app-frontend +COPY package*.json ./ -COPY package.json . - +# Etapa de dependências +FROM base AS deps RUN npm install +# Etapa de desenvolvimento +FROM base AS dev +ENV NODE_ENV=development +COPY --from=deps /app-frontend/node_modules ./node_modules COPY . . +CMD ["npm", "run", "dev"] +# Etapa de build (produção) +FROM base AS build +ENV NODE_ENV=production +COPY --from=deps /app-frontend/node_modules ./node_modules +COPY . . RUN npm run build -CMD [ "npm", "run", "start" ] \ No newline at end of file +# Etapa final para produção +FROM node:20-alpine AS prod +WORKDIR /app-frontend +ENV NODE_ENV=production +COPY --from=build /app-frontend/dist ./dist +COPY package*.json ./ +RUN npm install --omit=dev +CMD ["node", "dist/index.js"] diff --git a/app/whatsapp-api/Dockerfile b/app/whatsapp-api/Dockerfile index 72618c0..dc4e231 100644 --- a/app/whatsapp-api/Dockerfile +++ b/app/whatsapp-api/Dockerfile @@ -1,13 +1,31 @@ -FROM node:18 - +# Etapa base +FROM node:20-alpine AS base WORKDIR /app-whatsapp-api +COPY package*.json ./ -COPY package.json . - +# Etapa de dependências +FROM base AS deps RUN npm install +# Etapa de desenvolvimento +FROM base AS dev +ENV NODE_ENV=development +COPY --from=deps /app-whatsapp-api/node_modules ./node_modules COPY . . +CMD ["npm", "run", "dev"] +# Etapa de build (produção) +FROM base AS build +ENV NODE_ENV=production +COPY --from=deps /app-whatsapp-api/node_modules ./node_modules +COPY . . RUN npm run build -CMD [ "npm", "run", "start" ] \ No newline at end of file +# Etapa final para produção +FROM node:20-alpine AS prod +WORKDIR /app-whatsapp-api +ENV NODE_ENV=production +COPY --from=build /app-whatsapp-api/dist ./dist +COPY package*.json ./ +RUN npm install --omit=dev +CMD ["node", "dist/index.js"] diff --git a/app/whatsapp-api/Dockerfile.dev b/app/whatsapp-api/Dockerfile.dev deleted file mode 100644 index ebe059e..0000000 --- a/app/whatsapp-api/Dockerfile.dev +++ /dev/null @@ -1,11 +0,0 @@ -FROM node:18 - -WORKDIR /app-whatsapp-api - -COPY package.json . - -RUN npm install - -COPY . . - -CMD [ "npm", "run", "dev" ] \ No newline at end of file diff --git a/app/whatsapp-api/tsconfig.json b/app/whatsapp-api/tsconfig.json index 6ee2835..b761363 100644 --- a/app/whatsapp-api/tsconfig.json +++ b/app/whatsapp-api/tsconfig.json @@ -68,7 +68,7 @@ // "newLine": "crlf", /* Set the newline character for emitting files. */ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + "noEmitOnError": false, /* Disable emitting files if any type checking errors are reported. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ @@ -105,5 +105,15 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "exclude": [ + "node_modules", + "**/*.spec.ts", + "**/*.test.ts", + "**/*.e2e-spec.ts", + "**/*.d.ts" + ], + "include": [ + "src/**/*.ts" + ], } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml deleted file mode 100644 index 03cba1a..0000000 --- a/docker-compose.dev.yml +++ /dev/null @@ -1,103 +0,0 @@ -version: '3.9' -services: - frontend: - container_name: frontend - build: - context: ./app/frontend - dockerfile: Dockerfile.dev - ports: - - 3000:3000 - volumes: - - ./app/frontend/src:/app-frontend/src - depends_on: - - backend - - whatsapp-api - environment: - - API_URL=http://backend:3001 - - NEXT_PUBLIC_WHATSAPP_API=http://whatsapp-api:3002 - # Os `healthcheck` devem garantir que a aplicação - # está operacional, antes de liberar o container - healthcheck: - test: ["CMD", "lsof", "-t", "-i:3001"] # Caso utilize outra porta interna para o front, altere ela aqui também - timeout: 10s - retries: 5 - networks: - - app-network - - backend: - container_name: backend - build: - context: ./app/backend - dockerfile: Dockerfile.dev - volumes: - - ./app/backend/src:/app-backend/src - ports: - - 3001:3001 - command: sh -c "npm run db:generate && npm run db:migrate && npm run dev" - depends_on: - - db - env_file: - - ./app/backend/.env - healthcheck: - test: ["CMD", "lsof", "-t", "-i:3001"] # Caso utilize outra porta interna para o back, altere ela aqui também - timeout: 10s - retries: 5 - restart: always - networks: - - app-network - - whatsapp-api: - container_name: whatsapp-api - build: - context: ./app/whatsapp-api - dockerfile: Dockerfile.dev - ports: - - 3002:3002 - command: sh -c "npm run dev" - volumes: - - ./app/whatsapp-api/src:/app-whatsapp-api/src - environment: - - PORT=3002 - healthcheck: - test: ["CMD", "lsof", "-t", "-i:3002"] # Caso utilize outra porta interna para o back, altere ela aqui também - timeout: 10s - retries: 5 - networks: - - app-network - - db-studio: - container_name: db-studio - build: - context: ./app/backend - dockerfile: Dockerfile.dev - ports: - - 5555:5555 - working_dir: /app-backend - command: sh -c "npm run db:studio" - depends_on: - - backend - environment: - - DATABASE_URL=postgres://root:root@db:5432/queue-dev - healthcheck: - test: ["CMD", "lsof", "-t", "-i:5555"] # Caso utilize outra porta interna para o back, altere ela aqui também - timeout: 10s - retries: 5 - networks: - - app-network - - db: - image: postgres:latest - container_name: db - platform: linux/x86_64 - ports: - - 5432:5432/tcp - environment: - - POSTGRES_USER=root - - POSTGRES_PASSWORD=root - restart: always - networks: - - app-network - -networks: - app-network: - driver: bridge \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5e3ef29..668861d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,76 +1,95 @@ -version: '3.9' services: frontend: - container_name: app_frontend - build: ./app/frontend + container_name: frontend + build: + context: ./app/frontend + dockerfile: ./Dockerfile + target: ${TARGET:-dev} ports: - - 3000:3000 - command: sh -c "npm run start" - volumes: + - ${FRONT_PORT:-3000}:3000 + command: ${FRONT_COMMAND:-npm run dev} + volumes: - ./app/frontend/src:/app-frontend/src depends_on: - backend - whatsapp-api environment: - - API_URL=http://localhost:3001 - # Os `healthcheck` devem garantir que a aplicação - # está operacional, antes de liberar o container + - API_URL=${API_URL:-http://backend:3001} + - NEXT_PUBLIC_WHATSAPP_API=${WHATSAPP_API_URL:-http://localhost:3002} healthcheck: - test: ["CMD", "lsof", "-t", "-i:3000"] # Caso utilize outra porta interna para o front, altere ela aqui também + test: ["CMD", "lsof", "-t", "-i:3000"] timeout: 10s retries: 5 networks: - app-network backend: - container_name: app_backend - build: ./app/backend + container_name: backend + build: + context: ./app/backend + dockerfile: ./Dockerfile + target: ${TARGET:-dev} ports: - - 3001:3001 - command: sh -c "npm run build && npm run db:generate && npm run db:migrate && npm run start" - volumes: + - ${BACKEND_PORT:-3001}:3001 + command: ${BACK_COMMAND:-sh -c "npm run db:generate && npm run db:migrate && npm run dev"} + volumes: - ./app/backend/src:/app-backend/src depends_on: - db env_file: - ./app/backend/.env + environment: + - PORT=${BACKEND_PORT:-3001} + - DATABASE_URL=${DATABASE_URL:-postgres://root:root@db:5432/queue-dev} + - JWT_SECRET=${JWT_SECRET:-SENHACECRETA} + - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-1d} + - WHATSAPP_API_URL=${WHATSAPP_API_URL:-http://whatsapp-api:3002} + - THIS_URL=${THIS_URL:-https://seu-dominio.com.br} + - MP_ACCESS_TOKEN=${MP_ACCESS_TOKEN:-SUA_CHAVE_MERCADOPAGO} healthcheck: - test: ["CMD", "lsof", "-t", "-i:3001"] # Caso utilize outra porta interna para o back, altere ela aqui também + test: ["CMD", "lsof", "-t", "-i:3001"] timeout: 10s retries: 5 + restart: always networks: - app-network whatsapp-api: - container_name: app_whatsapp-api - build: ./app/whatsapp-api + container_name: whatsapp-api + build: + context: ./app/whatsapp-api + dockerfile: ./Dockerfile + target: ${TARGET:-dev} ports: - - 3002:3002 - command: sh -c "npm run build && npm run start" - volumes: + - ${WA_PORT:-3002}:3002 + command: ${WA_COMMAND:-npm run dev} + volumes: - ./app/whatsapp-api/src:/app-whatsapp-api/src environment: - - PORT=3002 + - PORT=${WA_PORT:-3002} healthcheck: - test: ["CMD", "lsof", "-t", "-i:3002"] # Caso utilize outra porta interna para o back, altere ela aqui também + test: ["CMD", "lsof", "-t", "-i:3002"] timeout: 10s retries: 5 networks: - app-network db-studio: - container_name: app_db-studio - build: ./app/backend + container_name: db-studio + build: + context: ./app/backend + dockerfile: ./Dockerfile + target: ${TARGET:-dev} ports: - - 5555:5555 + - ${STUDIO_PORT:-5555}:5555 working_dir: /app-backend command: sh -c "npm run db:studio" depends_on: - backend environment: - - DATABASE_URL=postgres://root:root@db:5432/queue + - DATABASE_URL=${DATABASE_URL:-postgres://root:root@db:5432/queue} healthcheck: - test: ["CMD", "lsof", "-t", "-i:5555"] # Caso utilize outra porta interna para o back, altere ela aqui também + test: ["CMD", "lsof", "-t", "-i:5555"] timeout: 10s retries: 5 networks: @@ -81,13 +100,13 @@ services: container_name: db platform: linux/x86_64 ports: - - 5432:5432/tcp + - ${DB_PORT:-5432}:5432/tcp environment: - - POSTGRES_USER=root - - POSTGRES_PASSWORD=root + - POSTGRES_USER=${POSTGRES_USER:-root} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-root} restart: always networks: - - app-network + - app-network networks: app-network: