Skip to content

Commit

Permalink
Merge pull request #3 from Lissone/feature/docker
Browse files Browse the repository at this point in the history
Feature - Added Docker
  • Loading branch information
Lissone authored Apr 28, 2023
2 parents 8574b2d + 0d18b4d commit 96beef8
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 APP_PORT=5000
ENV APP_PORT $APP_PORT
EXPOSE $APP_PORT

CMD npm run --silent start

46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://whimsical.com/pointcontrol-5dryUV3teiRwy1rPzH3ekK" target="_blank">Whimsical</a>.

To access the other projects integrated to this one, access:

- <a href="https://github.com/Lissone/point-control-admin-web" target="_blank">Front-end to admin users</a>
- <a href="https://github.com/almeidavini/point-control" target="_blank">Front-end to employees</a>

This project was done in partnership with:

- <a href="https://github.com/MikaMorais" target="_blank">Moises Morais</a>
- <a href="https://github.com/steniodr" target="_blank">Stenio Rapchan</a>
- <a href="https://github.com/almeidavini" target="_blank">Vinicius Almeida</a>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'
)
Expand All @@ -152,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
Expand All @@ -166,10 +166,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 <b>Docker</b>, 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
Expand Down Expand Up @@ -216,4 +233,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.

<hr />

30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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: ${APP_NAME}
image: ${APP_NAME}:${APP_VERSION}
build:
context: .
args:
APP_PORT: ${APP_PORT}
restart: always
ports:
- ${APP_PORT}:${APP_PORT}
depends_on:
- redis
- sqlserver
10 changes: 2 additions & 8 deletions src/external/database/dbConfig.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
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,
port: 1433,
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: {
Expand Down
2 changes: 1 addition & 1 deletion src/external/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 96beef8

Please sign in to comment.