From e64a931558cb3db9a05e6140a45a387f4e940ede Mon Sep 17 00:00:00 2001 From: Leonardo Dias Lissone Santomero Date: Fri, 4 Nov 2022 20:02:39 -0300 Subject: [PATCH 1/3] docs(readme): add whimsical link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c10e71..147bedf 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ This project is the Back-end (Api) of a company point control application. To il Project developed as an activity of my bachelor's degree in information systems, with the main objective of having a very descriptive and extensive documentation, for anyone to understand the features and learn from it. The api framework was built on clean architecture and documented with Swagger. -To facilitate the development of the project and better describe everything that was created, a flowchart of some of the project's features and relevant information at the time of its development was designed, using Whimsical. +To facilitate the development of the project and better describe everything that was created, a flowchart of some of the project's features and relevant information at the time of its development was designed, using Whimsical. To access the other projects integrated to this one, access: - Front-end to admin users From 95114bf7c782bf49ae263dcbc9a7d6902a2dec99 Mon Sep 17 00:00:00 2001 From: Leonardo Dias Lissone Santomero Date: Thu, 27 Apr 2023 18:16:43 -0300 Subject: [PATCH 2/3] build: first version of docker container --- .dockerignore | 22 ++++++++++++++++++ Dockerfile | 22 ++++++++++++++++++ README.md | 37 ++++++++++++++++++++----------- docker-compose.yml | 30 +++++++++++++++++++++++++ src/external/database/dbConfig.ts | 10 ++------- 5 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e5d92fb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# docker +.dockerignore +Dockerfile* +docker-compose* + +# git +.git +.gitignore + +# generated +node_modules +build +dist +coverage + +# other +*.log +.husky +.vscode +.env.example +CHANGELOG.md +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e333f09 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:18-alpine + +ENV TZ=America/Sao_Paulo +ENV NODE_OPTIONS=--max-old-space-size=4096 + +WORKDIR /app + +COPY package*.json ./ + +# --production=false para instalar tudo +RUN npm install --legacy-peer-deps --production=false + +COPY . . + +RUN npm run --silent build + +ARG PORT=5000 +ENV PORT $PORT +EXPOSE $PORT + +CMD npm run --silent start + diff --git a/README.md b/README.md index 147bedf..e671b9f 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,12 @@ Project developed as an activity of my bachelor's degree in information systems, To facilitate the development of the project and better describe everything that was created, a flowchart of some of the project's features and relevant information at the time of its development was designed, using Whimsical. To access the other projects integrated to this one, access: + - Front-end to admin users - Front-end to employees This project was done in partnership with: + - Moises Morais - Stenio Rapchan - Vinicius Almeida @@ -88,13 +90,6 @@ git clone https://github.com/Lissone/pointControl-api.git cd pointControl-api ``` -Install dependencies using: -```bash -yarn -#or -npm install -``` - ### Initial settings before running project Because we use external services, it is necessary to make some simple configurations before running the project. @@ -130,13 +125,13 @@ Default password: 123456 INSERT INTO [dbo].[user] (id, name, email, password, role, first_access, company_cnpj, created_at, updated_at) VALUES ( - '08e5ad8d-5fa3-41a2-a732-b997336b4cf5', + '08e5ad8d-5fa3-41a2-a732-b997336b4cf5', 'Global Admin', - 'admin@admin.com', - '$2a$05$MG6XoOEDPjtXVesTW8P2S.UkNzii1ai7VEAvBnToDHZq03sSij2vi', + 'admin@admin.com', + '$2a$05$MG6XoOEDPjtXVesTW8P2S.UkNzii1ai7VEAvBnToDHZq03sSij2vi', 'global.admin', 1, - NULL, + NULL, '2001-12-11T22:30:00Z', '2001-12-11T22:30:00Z' ) @@ -166,10 +161,27 @@ DB_NAME=dbPointControl DB_HOST=localhost # NODEMAILER -NODEMAILER_USER= # Email used for sending messages +NODEMAILER_USER= # Email used for sending messages NODEMAILER_PASS= # Your email password ``` +If you have Docker, and want to run the container, use the command: + +```bash +# Build the project container +docker-compose build +# Up container +docker-compose up +``` + +Install dependencies using: + +```bash +yarn +#or +npm install +``` + Run api: ```bash @@ -216,4 +228,3 @@ Thanks goes to these wonderful people, who were part of the project from start t Distributed under the MIT License. See `LICENSE` for more information.
- diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e357576 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' + +services: + sqlserver: + image: mcr.microsoft.com/mssql/server:2022-latest + ports: + - '1433:1433' + environment: + MSSQL_SA_PASSWORD: Dev1234! + ACCEPT_EULA: Y + MSSQL_PID: Developer + + redis: + image: 'redis:alpine' + ports: + - '6379:6379' + + api: + container_name: point-control-api + image: point-control-api:1.0 + build: + context: . + args: + APP_PORT: 5000 + restart: always + ports: + - 5000:5000 + depends_on: + - redis + - sqlserver diff --git a/src/external/database/dbConfig.ts b/src/external/database/dbConfig.ts index 89b6b35..b3776d5 100644 --- a/src/external/database/dbConfig.ts +++ b/src/external/database/dbConfig.ts @@ -1,12 +1,6 @@ +import path from 'path' import { createConnection } from 'typeorm' -import { AbsenceEntity } from './entities/AbsenceEntity' -import { AddressEntity } from './entities/AddressEntity' -import { CompanyEntity } from './entities/CompanyEntity' -import { EmployeeEntity } from './entities/EmployeeEntity' -import { PointEntity } from './entities/PointEntity' -import { UserEntity } from './entities/UserEntity' - const connection = createConnection({ type: 'mssql', host: process.env.DB_HOST, @@ -14,7 +8,7 @@ const connection = createConnection({ username: process.env.DB_USERNAME, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, - entities: [UserEntity, CompanyEntity, EmployeeEntity, AddressEntity, AbsenceEntity, PointEntity], + entities: [path.join(__dirname, 'entities/*{.ts,.js}')], synchronize: true, logging: false, options: { From 0d18b4d42279771f4c4ebadb4ac35c6363b96ecc Mon Sep 17 00:00:00 2001 From: Leonardo Dias Lissone Santomero Date: Fri, 28 Apr 2023 17:03:49 -0300 Subject: [PATCH 3/3] fix: changed enviroment variable PORT --- .env.example | 8 ++++++-- Dockerfile | 6 +++--- README.md | 9 +++++++-- docker-compose.yml | 8 ++++---- src/external/server.ts | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 22222dc..9a81d1a 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,9 @@ -# DEFAULT -PORT=5000 +# APP +APP_PORT=5000 +APP_NAME=point-control-api +APP_VERSION=0.0.0 + +# AUTH SECRET_KEY=super_scret # REDIS diff --git a/Dockerfile b/Dockerfile index e333f09..479d6ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,9 @@ COPY . . RUN npm run --silent build -ARG PORT=5000 -ENV PORT $PORT -EXPOSE $PORT +ARG APP_PORT=5000 +ENV APP_PORT $APP_PORT +EXPOSE $APP_PORT CMD npm run --silent start diff --git a/README.md b/README.md index e671b9f..5b0418f 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,13 @@ Need to add environment variables: # .\.env # DEFAULT -PORT=5000 -SECRET_KEY=super_secret # JWT secret key +# APP +APP_PORT=5000 +APP_NAME=point-control-api +APP_VERSION=0.0.0 + +# AUTH +SECRET_KEY=super_scret # JWT secret key # REDIS REDIS_HOST=localhost diff --git a/docker-compose.yml b/docker-compose.yml index e357576..ac8b3e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,15 +16,15 @@ services: - '6379:6379' api: - container_name: point-control-api - image: point-control-api:1.0 + container_name: ${APP_NAME} + image: ${APP_NAME}:${APP_VERSION} build: context: . args: - APP_PORT: 5000 + APP_PORT: ${APP_PORT} restart: always ports: - - 5000:5000 + - ${APP_PORT}:${APP_PORT} depends_on: - redis - sqlserver diff --git a/src/external/server.ts b/src/external/server.ts index bb4aee5..0d5dd71 100644 --- a/src/external/server.ts +++ b/src/external/server.ts @@ -6,7 +6,7 @@ import { connection } from '@external/database/dbConfig' import { app } from './app' -const port = process.env.PORT || 5000 +const port = process.env.APP_PORT || 5000 connection .then(() => {