-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 841ac63
Showing
68 changed files
with
3,025 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
source=oildjango_pro | ||
omit = */tests/*, */migrations/*, */config.py, */baker_recipes.py, *_multischema.py, *conftest.py |
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,13 @@ | ||
**/.git | ||
**/.gitignore | ||
**/.vscode | ||
**/coverage | ||
**/.env | ||
**/.aws | ||
**/.ssh | ||
Dockerfile | ||
README.md | ||
docker-compose.yml | ||
**/.DS_Store | ||
**/venv | ||
**/env |
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,72 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: build | ||
|
||
on: push | ||
|
||
jobs: | ||
CI: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.10'] | ||
|
||
services: | ||
# Label used to access the service container | ||
db: | ||
# Docker Hub image | ||
image: postgres:latest | ||
# Provide the password for postgres | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: postgres | ||
# Set health checks to wait until postgres has started | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
ports: | ||
# Maps tcp port 5432 on service container to the host | ||
- 5432:5432 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Cache pip | ||
uses: actions/cache@v2 | ||
with: | ||
# This path is specific to Ubuntu | ||
path: ~/.cache/pip | ||
# Look to see if there is a cache hit for the corresponding requirements file | ||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/local.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
${{ runner.os }}- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 | ||
pip install -r requirements/local.txt | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test coverage with pytest | ||
env: | ||
DJANGO_SETTINGS_MODULE: conf.settings.test | ||
DJANGO_SECRET_KEY: testsecret | ||
DJANGO_DEBUG: False | ||
DOMAIN_ALIASES: localhost,127.0.0.1 | ||
SECURE_SSL_REDIRECT: False | ||
STAGE: test | ||
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres | ||
DEFAULT_STORAGE_DSN: file:///tmp/media/?url=%2Fmedia%2F | ||
CACHE_URL: locmem://unique-snowflake | ||
run: | | ||
python manage.py makemigrations --noinput | ||
pytest -n 4 --cov=apps | ||
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,106 @@ | ||
# Created by https://www.gitignore.io | ||
|
||
### OSX ### | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear on external disk | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Temporary files | ||
tmp/ | ||
|
||
### Django ### | ||
*.log | ||
*.pot | ||
*.pyc | ||
__pycache__/ | ||
local_settings.py | ||
|
||
.env | ||
db.sqlite3 | ||
|
||
### IDEs ### | ||
.vscode | ||
|
||
### Platforms ### | ||
# Divio | ||
.divio | ||
/data.tar.gz | ||
/data |
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,26 @@ | ||
FROM python:3.10 | ||
|
||
LABEL maintainer="pedro@monumentosoftware.com.br" | ||
|
||
ARG requirements_file="requirements/production.txt" | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# We copy just the requirements.txt first to leverage Docker cache | ||
COPY ./requirements /app/requirements | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install --upgrade pip && pip install -r $requirements_file | ||
|
||
COPY . /app | ||
|
||
# Build operations | ||
RUN STAGE=build ENVKEY_DISABLE_AUTOLOAD=1 python manage.py collectstatic --noinput | ||
|
||
# Determines whether the process running is active, running and healthy. | ||
HEALTHCHECK CMD ["curl", "--fail", "http://localhost:8000", "||", "exit 1"] | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["uwsgi", "--http=0.0.0.0:80", "--module=conf.wsgi"] |
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,69 @@ | ||
ARG := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS)) | ||
$(eval $(ARG):;@true) | ||
|
||
perms: | ||
sudo chown -hR ${USER}:${USER} . | ||
|
||
build: | ||
docker-compose build | ||
|
||
up: | ||
docker-compose up | ||
|
||
enter: | ||
docker-compose exec $(ARG) bash | ||
|
||
setup_install: | ||
bash scripts/setup-install.sh | ||
|
||
setup_venv: | ||
bash scripts/setup-venv.sh | ||
|
||
startapp: | ||
bash scripts/start-app.sh $(ARG) | ||
|
||
run: | ||
bash scripts/docker-run.sh $(ARG) | ||
|
||
migrations: | ||
bash scripts/docker-run.sh python manage.py makemigrations $(ARG) | ||
|
||
migrate: | ||
bash scripts/docker-run.sh python manage.py migrate | ||
|
||
seed: | ||
bash scripts/docker-run.sh python manage.py runscript seed | ||
|
||
reset_schema: | ||
bash scripts/docker-run.sh python manage.py reset_schema | ||
|
||
shell: | ||
bash scripts/docker-run.sh python manage.py shell_plus | ||
|
||
collectstatic: | ||
bash scripts/docker-run.sh python manage.py collectstatic | ||
|
||
messages: | ||
bash scripts/docker-run.sh django-admin makemessages -l pt_BR --ignore venv | ||
|
||
compilemessages: | ||
bash scripts/docker-run.sh django-admin compilemessages -l pt_BR | ||
|
||
generate_schema: | ||
mkdir -p tmp/docs | ||
bash scripts/docker-run.sh python manage.py generateschema --format openapi-json > docs/openapi.json | ||
|
||
test: | ||
bash scripts/docker-run.sh pytest -n 4 | ||
|
||
test_create_db: | ||
bash scripts/docker-run.sh pytest -n 4 --create-db | ||
|
||
coverage: | ||
bash scripts/docker-run.sh pytest -n 4 --cov=apps | ||
|
||
coverage_html: | ||
bash scripts/docker-run.sh pytest -n 4 --cov=apps --cov-report html | ||
google-chrome htmlcov/index.html | ||
|
||
total_reset: reset_schema migrate seed |
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,102 @@ | ||
# OilDjango-Pro [![build](https://github.com/MonumentoSoftware/django-base/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/MonumentoSoftware/django-base/actions/workflows/main.yml) | ||
|
||
For professional managament of energy industries assets | ||
|
||
## Como rodar | ||
|
||
Se for a primeira vez: | ||
```bash | ||
make setup_install | ||
``` | ||
|
||
Depois, apenas: | ||
```bash | ||
make up | ||
``` | ||
|
||
### Opcional | ||
|
||
Criar ambiente virtual: | ||
```bash | ||
make setup_venv | ||
``` | ||
|
||
Rodar seed do banco: | ||
```bash | ||
make seed | ||
``` | ||
|
||
## Documentação da API | ||
|
||
### Interface gráfica | ||
|
||
Usamos a Swagger UI, para exibir a documentação, em formato OpenAPI, numa interface gráfica no navegador. Para rodar localmente apenas o container da documentação, seguir os passos: | ||
|
||
1. Rodar `docker-compose up swagger-ui` | ||
2. Acessar *localhost:8080* | ||
|
||
### Incrementando a documentação | ||
|
||
O arquivo *docs/openapi.json* descreve a API utilizando a especificação OpenAPI. Ele deve ser editado manualmente ao longo do tempo de vida do projeto para deixar a documentação em conformidade com a API. Uma ferramenta que pode acelerar este processo é o comando *genarateschema* do Django REST Framework. Ele pode ser usado para gerar a documentação automática do projeto baseada nas views existentes. No entanto, deve-se ter cuidado pra não sobrescrever o arquivo original *openapi.json*. Para utilizar a ferramenta, seguir o tutorial: | ||
|
||
1. Rodar o comando `make generate_schema` para criar o arquivo **docs/temp-schema.json**. | ||
2. Identificar no arquivo gerado a parte desejada (exemplo: alguma *view* nova) e mover para **docs/openapi.json**. | ||
3. Excluir o arquivo **docs/temp-schema.json**. | ||
|
||
## Testes unitários | ||
|
||
Utilizamos a biblioteca **pytest** para rodar testes unitários. Seu arquivo de configuração é *pytest.ini*. | ||
|
||
- Para rodas os testes, usar o comando `make test`. | ||
|
||
Como por padrão os testes reutilizam o banco de dados gerado, caso tenha novas migrações é necessário re-criar o banco. | ||
|
||
- Para re-criar o banco, utilizar o comando `pytest --create-db`. | ||
|
||
### Cobertura de teste | ||
|
||
- `make coverage` | ||
|
||
ou | ||
|
||
- `make coverage_html`, para um relatório HTML. | ||
|
||
## Arquitetura | ||
|
||
- `apps`: aqui devem estar todas as django apps locais que devem ser criadas ao longo do desenvolvimento do projeto. No projeto base esta pasta conterá apenas a app `user` (e a `tenant`, se for um projeto tenant-based). Para criar uma nova app, deve-se usar o comando *make startapp* na raiz do projeto para criá-la no lugar correto e seguindo o template do projeto base. | ||
- `conf`: módulo que contém arquivos de configuração do projeto. | ||
- `app_template`: template usado para criação de novas apps. Geralmente, não deve ser alterado. | ||
- `settings`: pasta com os arquivos settings do django. É modularizado de forma a possuir um arquivo de settings para cada ambiente: local, production, etc. | ||
- `urls.py`: arquivo de urls do projeto. É preferível deixar apenas incluir as urls das outras apps, deixando a configuração específica de cada módulo em seu próprio arquivo urls.py. | ||
- `wsgi.py`: arquivo wsgi padrão do Django para deploy. | ||
- `docs`: módulo que contém arquivos relacionados à documentação do projeto. | ||
- `openapi.json`: arquivo contendo schema da API REST. É usado no container *swagger-ui*. | ||
- `lib`: módulo que contém as classes que devem ser compartilhada por todo o projeto, como por exemplo um model base, uma view genérica, etc. | ||
- `models.py`: contém models base para o projeto que automaticamente incluem campos de timestamp (created_at ou updated_at) ou safe delete feature. | ||
- `requirements`: contém as dependências do projeto, separadas por ambiente (local, production, etc.). | ||
- `scripts`: contém shell scripts úteis para o projeto. | ||
- `env.example`: arquivo env de exemplo para iniciar o projeto. Deve ser copiado para um arquivo `.env` (não versionado). | ||
- `docker-compose.yml` e `Dockerfile`: arquivos de configuração Docker. | ||
- `Makefile`: contém comandos úteis, como por exemplo entrar num container ou criar uma app. | ||
|
||
## Comandos úteis | ||
|
||
### Criar uma app | ||
|
||
`make startapp [app_name]` | ||
|
||
### Entrar em um container | ||
|
||
`make enter [service_name]` | ||
|
||
### Abrir o django shell | ||
|
||
`make shell` | ||
|
||
### Resetar o banco de dados | ||
|
||
`make reset_db` | ||
|
||
### Atualizar traduções do inglês | ||
|
||
`make compilemessages` |
Empty file.
Oops, something went wrong.