generated from HenriqueAmorim20/GEROcuidadoAPITemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fga-eps-mds/develop
Develop
- Loading branch information
Showing
52 changed files
with
1,829 additions
and
9,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
#!/bin/bash | ||
# TODO | ||
npm install | ||
npm run start:dev | ||
#!/bin/sh | ||
|
||
echo "---------------Run migrations---------------" | ||
|
||
node /app/migrations.js | ||
|
||
echo "---------------Run migrations - END---------" | ||
|
||
node /app/main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
#!/bin/bash | ||
|
||
cd /home/node/app | ||
source .env.development | ||
|
||
npm install --legacy-peer-deps | ||
|
||
rm -rf dist | ||
|
||
echo "---------------Run migrations---------------" | ||
|
||
npm run typeorm:run | ||
|
||
echo "---------------Run migrations - END---------" | ||
npm run start:dev | ||
|
||
npm run start:debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ ENV LANG pt_BR.utf8 | |
ENV LC_ALL pt_BR.utf8 | ||
ENV LANGUAGE pt_BR.utf8 | ||
|
||
EXPOSE 5432 | ||
EXPOSE 5001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
jobs: | ||
sonarqube: | ||
name: sonarqube | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install dependencies | ||
run: yarn | ||
- name: Test and coverage | ||
run: yarn jest --coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
tags: ['v*.*.*'] | ||
|
||
env: | ||
TARGET_DIR: '~/${{ github.event.repository.name }}' | ||
|
||
jobs: | ||
docker-hub: | ||
name: Docker Hub Image Push | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Sending Image to Docker Hub | ||
uses: mr-smithers-excellent/docker-build-push@v5 | ||
with: | ||
image: gerocuidadodev/gerocuidado-usuario-api | ||
registry: docker.io | ||
directory: ./ | ||
dockerfile: ./Dockerfile.prod | ||
tags: latest | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
deploy-ec2: | ||
name: Deploy EC2 | ||
needs: docker-hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the files | ||
uses: actions/checkout@v2 | ||
|
||
- name: Executing remote ssh commands using ssh key | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST_DNS }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
cd ${{env.TARGET_DIR}} | ||
sudo git pull | ||
sudo docker compose -f docker-compose.prod.yml up --force-recreate --build --pull --remove-orphans -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,81 @@ | ||
# GEROcuidado-APIUsuario | ||
# gerocuidado-usuario-api | ||
|
||
## CONFIGURAÇÃO | ||
## Configuração | ||
|
||
Definir valores iguais para os arquivos .env e docker-compose. | ||
Definir valores iguais para os arquivos .env e docker-compose | ||
|
||
Arquivo .env: | ||
Arquivo .env.development e .env.test: | ||
|
||
#POSTGRES | ||
DB_TYPE='postgres' | ||
DB_HOST='localhost' | ||
DB_USERNAME='postgres' | ||
DB_PASS='postgres' | ||
DB_DATABASE='gerocuidado-usuario-db' | ||
DB_PORT=5001 | ||
DB_TYPE= | ||
DB_HOST= | ||
DB_USERNAME= | ||
DB_PASS= | ||
DB_DATABASE= | ||
DB_PORT= | ||
JWT_TOKEN_SECRET= | ||
JWT_TOKEN_EXPIRES_IN= | ||
HASH_SALT= | ||
|
||
Arquivo .docker-compose, na seção **_environment_**: | ||
|
||
... | ||
environment: | ||
- POSTGRES_DB=gerocuidado-usuario-db | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_DB= | ||
- POSTGRES_USER= | ||
- POSTGRES_PASSWORD= | ||
... | ||
|
||
Da mesma forma, alterar os valores das portas terminadas em **_xx_** (i.e 30xx para 3001) para a porta desejada nos arquivos de compose, bem como no arquivo launch.json da pasta .vscode. | ||
Da mesma forma, alterar os valores das portas terminadas em **_x_** (i.e 300x para 3001) para a porta desejada nos arquivos de compose, bem como no arquivo launch.json da pasta .vscode. | ||
|
||
## AMBIENTES | ||
## Execução | ||
|
||
### DEV | ||
Para subir a aplicação, basta rodar o comando: | ||
|
||
```bash | ||
docker-compose up | ||
``` | ||
|
||
#### INSTALAR DEPENDÊNCIAS E CRIAR NOVAS FUNCIONALIDADES | ||
|
||
```bash | ||
docker-compose exec gerocuidado-usuario-api bash | ||
nest g resource users | ||
``` | ||
```bash | ||
docker compose up | ||
``` | ||
|
||
### TEST | ||
## Testes | ||
|
||
- GERAL | ||
Para testar a aplicação, suba o container de testes: | ||
|
||
```bash | ||
docker-compose -f docker-compose.test.yml up | ||
TEST=dev docker compose -f docker-compose.test.yml up | ||
``` | ||
|
||
após em um novo terminal | ||
|
||
E rode os comandos para os testes unitários e E2E respectivamente (:cov gera o arquivo de coverage na raiz do projeto): | ||
```bash | ||
docker-compose -f docker-compose.test.yml exec gerocuidado-usuario-api-test bash | ||
cd /home/node/app | ||
npm run test | ||
npm run test:cov | ||
npm run test:e2e | ||
npm run test:e2e:cov | ||
npm run test:cov | ||
npm run test:e2e:cov | ||
``` | ||
|
||
- UNIT | ||
## Migrations | ||
|
||
Para apenas rodar os testes unitários e sair do container rode o comando abaixo: | ||
Sempre que houver qualquer alteração em alguma entidade na aplicação (adicionar uma entidade, remover ou edita-la), deve ser gerada uma migration para sincronizar o banco de dados. | ||
|
||
```bash | ||
TEST=unit docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from gerocuidado-usuario-api-test | ||
``` | ||
1. Entrar no container da api: | ||
|
||
- E2E | ||
Para apenas rodar os testes unitários e sair do container rode o comando abaixo: | ||
```bash | ||
docker exec -it gerocuidado-usuario-api bash | ||
``` | ||
|
||
```bash | ||
TEST=e2e docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from gerocuidado-usuario-api-test | ||
``` | ||
2. Rodar o comando de criar uma migration (tente dar um nome descritivo, ex.: CreateTableUsuario) | ||
|
||
# ENVIRONMENTS VARIABLES | ||
```bash | ||
npm run typeorm:migrate src/migration/NOME_DA_MIGRATION | ||
``` | ||
|
||
| ENV | Descrição | Valor Padrão | | ||
| ----------- | ---------------------- | ---------------------- | | ||
| DB_TYPE | tipo do banco | postgres | | ||
| DB_HOST | host do PostgreSQL | localhost | | ||
| DB_USERNAME | usuário do PostgreSQL | postgres | | ||
| DB_PASS | senha do PostgreSQL | postgres | | ||
| DB_DATABASE | database do PostgreSQL | gerocuidado-usuario-db | | ||
| DB_PORT | porta do PostgreSQL | 5001 | | ||
# Dicionário variáveis de ambiente | ||
|
||
| ENV | Descrição | Valor Padrão | | ||
| -------------------- | ------------------------- | ---------------------- | | ||
| DB_TYPE | tipo do banco | postgres | | ||
| DB_HOST | host do PostgreSQL | localhost | | ||
| DB_USERNAME | usuário do PostgreSQL | postgres | | ||
| DB_PASS | senha do PostgreSQL | postgres | | ||
| DB_DATABASE | database do PostgreSQL | gerocuidado-usuario-db | | ||
| DB_PORT | porta do PostgreSQL | 5001 | | ||
| JWT_TOKEN_SECRET | secret do JWT | | | ||
| JWT_TOKEN_EXPIRES_IN | tempo de expiração do JWT | 12h | | ||
| HASH_SALT | saltRounds da senha | 10 | |
Oops, something went wrong.