Skip to content

Commit

Permalink
Merge pull request #88 from filiperochalopes/develop
Browse files Browse the repository at this point in the history
Develop - Primeira versão utilizável 22/05/2023
  • Loading branch information
filiperochalopes authored May 28, 2023
2 parents 893e343 + 1a25e38 commit 9f742af
Show file tree
Hide file tree
Showing 304 changed files with 34,649 additions and 10,757 deletions.
7 changes: 5 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
POSTGRES_DB="service_status"
POSTGRES_NAME="hmlem"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="kd&njf%s7@nme$7"
POSTGRES_PASS="7xyed8uDyi0="
POSTGRES_PORT=55432
POSTGRES_TEST_PORT=55433
FLASKAPP_PORT=5006
APP_PORT=83
FRONTEND_PORT=3002
SECRET_KEY="40da743e52d28395796361da56614621fd4b59cd1338dd4587918fb6d8e18106"
MASTER_KEY="passw@rd"
14 changes: 12 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
POSTGRES_DB="service_status"
POSTGRES_NAME="hmlem"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="kd&njf%s7@nme$7"
# openssl rand -base64 8
POSTGRES_PASS="7xyed8uDyi0="
POSTGRES_PORT=55432
# Porta que executa o banco de dados de teste
POSTGRES_TEST_PORT=55433
FLASKAPP_PORT=5006
APP_PORT=83
FRONTEND_PORT=3002

# Gerar hash aleatório para criptografia
# python -c 'import secrets; print(secrets.token_hex())'
SECRET_KEY=

# Gerar senha aleatória
MASTER_KEY=
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
__pycache__
.env
data
.idea
flaskapp/app/graphql/mutations/pdfs/tests/pdfs_created_files_test/*
instance/
*.db
flaskapp/app/tests/files/tmp/*.pdf
data
.DS_Store
.pytest_cache
users.json
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

cd ./reactapp
npx pretty-quick --staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
cd ./reactapp
npx prettier --write src/**/*.{js,jsx} && npx eslint src/**/*.{js,jsx} --fix
5 changes: 5 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
cd ./reactapp

exec < /dev/tty && yarn commit --edit --hook || true
46 changes: 32 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
build:
docker-compose build --no-cache
run:
docker-compose up --build
docker compose up --build
logs:
docker-compose logs -f
docker compose logs -f
seed:
docker exec -it evolucao_hospitalar_flaskapp bash -c "FLASK_APP=app/__init__.py && \
docker exec -it evolucao_hospitalar_app bash -c "FLASK_APP=app/__init__.py && \
flask seed"
users:
docker exec -it evolucao_hospitalar_app bash -c "FLASK_APP=app/__init__.py && \
flask create_users"
terminal:
docker exec -it evolucao_hospitalar_flaskapp bash
docker exec -it evolucao_hospitalar_app bash
shell:
docker exec -it evolucao_hospitalar_flaskapp bash -c "flask shell"
docker exec -it evolucao_hospitalar_app bash -c "flask shell"
migrate:
docker exec -it evolucao_hospitalar_flaskapp bash -c "flask db upgrade"
docker exec -it evolucao_hospitalar_app bash -c ' \
chmod -R 777 /app/migrations && \
flask db upgrade'
makemigrations:
docker exec -it evolucao_hospitalar_flaskapp bash -c 'flask db migrate -m "$(m)"'
reset_db:
docker exec -it evolucao_hospitalar_flaskapp bash -c ' \
rm -rf migrations && \
rm -rf instance && \
flask db init && \
flask db migrate -m "Initial migration" && \
flask db upgrade'
docker exec -it evolucao_hospitalar_app bash -c ' \
chmod -R 777 /app/migrations && \
flask db migrate -m "$(m)"'
test_all:
docker exec -it evolucao_hospitalar_app bash -c 'pytest -s'
clean_db:
docker compose rm -s -v -f db
sudo rm -rf data
docker compose up -d db
sleep 10
docker exec -it evolucao_hospitalar_app bash -c ' \
flask db upgrade'
test_flow:
# Clean all database
docker exec -it evolucao_hospitalar_db bash -c 'psql -U postgres -c "\set AUTOCOMMIT on" -c "DROP DATABASE hmlem WITH (FORCE)" -c "CREATE DATABASE hmlem"'
docker exec -it evolucao_hospitalar_app bash -c 'flask db upgrade && flask seed'
docker exec -it evolucao_hospitalar_app bash -c 'pytest -s -k TestInternmentFlow'
docker exec -it evolucao_hospitalar_app bash -c 'pytest -s -k TestPrintPdfs'
fix-folder-permission:
docker exec -it evolucao_hospitalar_app bash -c ' \
chmod -R 777 /app/migrations'
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Inicialmente criado com a ideia de ser um registro para acompanhamento de pacientes por médicos de um pronto atendimento, o conceito foi migrado ao notar a debilidade de um Hospital de Pequeno Porte em registrar as condutas de seus pacientes. Esse novo escopo visa ser responsável pela melhoria da comunicação e atenção da equipe.

## Deploy em ambiente de homologação/produção

1. (Opcional) Crie dentro da pasta app uma lista de usuários para cadastro/seed inicial
2. Execute:

```sh
docker-compose down --volumes --remove-orphans
rm -rf data
docker-compose up -d
make migrate
make seed
make users
```

## Ambiente de desenvolvimento

Para desenvolvimento foi criado um ambiente docker que supre as necessidades da construção, entretando para produção será instalado em um computador Windows de baixo custo da unidade que funcionará como servidor.
Expand Down Expand Up @@ -55,7 +69,7 @@ npm install --global yarn
### Realizando a build React

```sh
cd flaskapp/app/templates/reactapp
cd reactapp
yarn
yarn build
```
Expand Down Expand Up @@ -87,17 +101,6 @@ FLASK_DEBUG=false
gunicorn --bind 0.0.0.0:5000 wsgi:app --daemon
```

# Como rodar os testes
### Entre no diretorio /app/app
```cd /app/app```
### Agora rode os teste utilizando esse comando
```pytest /app/app/graphql/mutations/pdfs/tests/```
### Testes

### O resultado é pra ser parecido isso:
```
root@d956c3253006:/app/app# pytest /app/app/graphql/mutations/pdfs/tests/
========================================================================================== test session starts ==========================================================================================platform linux -- Python 3.8.15, pytest-7.1.3, pluggy-1.0.0
rootdir: /app/app
plugins: anyio-3.6.1
collected 819 items
```
Para facilitar o teste estou mantendo no README algumas requisições para preencher o banco de dados com informações iniciais e úteis para o teste estão disponíveis na lista de comando do `Makefile`
44 changes: 44 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3"
services:
db:
container_name: evolucao_hospitalar_db
restart: always
image: postgres:13.9-alpine
volumes:
- ./data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASS}
ports:
- "${POSTGRES_PORT}:5432"
app:
container_name: evolucao_hospitalar_app
restart: always
build:
context: ./flaskapp
dockerfile: Dockerfile
volumes:
- ./flaskapp:/app
environment:
- SECRET_KEY=${SECRET_KEY}
- MASTER_KEY=${MASTER_KEY}
- POSTGRES_NAME=${POSTGRES_NAME:?nome do BD ausente}
- POSTGRES_USER=${POSTGRES_USER:?usuario do BD ausente}
- POSTGRES_PASS=${POSTGRES_PASS:?senha do BD ausente}
ports:
- "${FLASKAPP_PORT}:5000"
depends_on:
- db
nginx:
container_name: evolucao_hospitalar_nginx
restart: always
build:
context: .
dockerfile: Dockerfile.nginx
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "${APP_PORT}:80"
depends_on:
- app
43 changes: 39 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
version: "3"
services:
flaskapp:
container_name: evolucao_hospitalar_flaskapp
db:
container_name: evolucao_hospitalar_db
restart: always
image: postgres:13.9-alpine
volumes:
- ./data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASS}
ports:
- "${POSTGRES_PORT}:5432"
app:
container_name: evolucao_hospitalar_app
restart: always
build:
context: ./flaskapp
Expand All @@ -11,17 +23,40 @@ services:
environment:
- SECRET_KEY=${SECRET_KEY}
- MASTER_KEY=${MASTER_KEY}
- POSTGRES_NAME=${POSTGRES_NAME:?nome do BD ausente}
- POSTGRES_USER=${POSTGRES_USER:?usuario do BD ausente}
- POSTGRES_PASS=${POSTGRES_PASS:?senha do BD ausente}
ports:
- "${FLASKAPP_PORT}:5000"
depends_on:
- db
frontend:
container_name: evolucao_hospitalar_frontend
restart: always
build:
context: reactapp
dockerfile: Dockerfile.dev
volumes:
- ./reactapp:/home/node/app:delegated
- ./reactapp/node_modules:/home/node/app/node_modules
environment:
- REACT_APP_API_URL=/api/v1
- CHOKIDAR_USEPOLLING=true
ports:
- "${FRONTEND_PORT}:3000"
stdin_open: true
depends_on:
- app
nginx:
container_name: evolucao_hospitalar_nginx
restart: always
build:
context: .
dockerfile: Dockerfile.nginx
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/development.conf:/etc/nginx/conf.d/default.conf
ports:
- "${APP_PORT}:80"
depends_on:
- flaskapp
- app
- frontend
Loading

0 comments on commit 9f742af

Please sign in to comment.