Commit 523bf3dd authored by Laury Bueno's avatar Laury Bueno
Browse files

Initial version; largely based on the current 'Empurrando Juntos' install

parents
[run]
include = base_django_project/*
omit = *migrations*, *tests*
plugins =
django_coverage_plugin
.*
!.coveragerc
!.env
!.pylintrc
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{py,rst,ini}]
indent_style = space
indent_size = 4
[*.py]
line_length=120
known_first_party=base_django_project
multi_line_output=3
default_section=THIRDPARTY
[*.{html,css,scss,json,yml}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
[nginx.conf]
indent_style = space
indent_size = 2
* text=auto
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.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
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
staticfiles/
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
### Linux template
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### VisualStudioCode template
.vscode
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
### macOS template
# General
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### SublimeText template
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project
# SFTP configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Vim template
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
base_django_project/media/
# Added to maintain local compose files which are ignored by something above.
# See issue https://github.com/pydanny/cookiecutter-django/issues/1321
!/compose/local/
---
image: docker:18.01.0-ce-git
services:
- docker:18.01.0-ce-dind
stages:
- build
- deploy
variables:
DJANGO_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/django:$CI_BUILD_REF_NAME
NGINX_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/nginx:$CI_BUILD_REF_NAME
#############
## Production
#############
build to production:
stage: build
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -f compose/production/Dockerfile --target django -t $DJANGO_RELEASE_IMAGE .
- docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:latest"
- docker push $DJANGO_RELEASE_IMAGE
- docker push "$CI_REGISTRY_IMAGE/django:latest"
- docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
- docker tag $NGINX_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/nginx:latest"
- docker push $NGINX_RELEASE_IMAGE
- docker push "$CI_REGISTRY_IMAGE/nginx:latest"
only:
- tags
environment: production
tags:
- docker
deploy to production:
stage: deploy
image: cdrx/rancher-gitlab-deploy
script:
- upgrade --environment FPAbramo --stack empurrandojuntos-prod --service backend --no-finish-upgrade --debug
only:
- tags
environment: production
tags:
- docker
##########
## Homolog
##########
build to homolog:
stage: build
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -f compose/production/Dockerfile --target django -t $DJANGO_RELEASE_IMAGE .
- docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:master"
- docker push $DJANGO_RELEASE_IMAGE
- docker push "$CI_REGISTRY_IMAGE/django:master"
- docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
- docker tag $NGINX_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/nginx:master"
- docker push $NGINX_RELEASE_IMAGE
- docker push "$CI_REGISTRY_IMAGE/nginx:master"
only:
- /master/
environment: homolog
tags:
- docker
# test to homolog:
# stage: test
# script:
# - docker build -f compose/dev/django/Dockerfile -t $DJANGO_RELEASE_IMAGE .
# - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:test"
# - docker run -d --env-file=./compose/dev/test_env --name=postgres postgres:9.6
# - docker run --env-file=./compose/dev/test_env --link=postgres:postgres "$CI_REGISTRY_IMAGE/django:test" /test.sh
# only:
# - /master/
# environment: homolog
# tags:
# - docker
deploy to homolog:
stage: deploy
image: cdrx/rancher-gitlab-deploy
script:
- upgrade --environment FPAbramo --stack brasilqueopovoquer-empurrandojuntos-dev --service backend --no-finish-upgrade --debug
only:
- /master/
environment: homolog
tags:
- docker
##########
## Develop
##########
build to develop:
stage: build
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -f compose/dev/django/Dockerfile -t $DJANGO_RELEASE_IMAGE .
- docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:develop"
- docker push "$CI_REGISTRY_IMAGE/django:develop"
only:
- /develop/
environment: development
tags:
- docker
# test to develop:
# stage: test
# script:
# - docker run -d --env-file=./compose/dev/test_env --name=postgres postgres:9.6
# - docker run --env-file=./compose/dev/test_env --link=postgres:postgres "$CI_REGISTRY_IMAGE/django:develop" /test.sh
# only:
# - /develop/
# environment: development
# tags:
# - docker
[MASTER]
load-plugins=pylint_common, pylint_django
[FORMAT]
max-line-length=120
[MESSAGES CONTROL]
disable=missing-docstring,invalid-name
[DESIGN]
max-parents=13
[TYPECHECK]
generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete
hacklab/
\ No newline at end of file
This diff is collapsed.
Copyright (c) 2017, Bruno Martin, Laury Bueno, Luan Guimarães, Ricardo Poppi, Henrique Parra
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
# Empurrando Juntos
Projeto Django baseado no padrão [cookiecutter-django](http://cookiecutter-django.readthedocs.io/en/latest).
## Ambiente de desenvolvimento
Para clonar este repositório e seus [submódulos](https://git-scm.com/book/en/v2/Git-Tools-Submodules), execute:
`git clone git@gitlab.com:hacklab/base-django-project.git`
Levante o ambiente de desenvolvimento com `docker-compose -f local.yml up` e acesse [localhost:8000](http://localhost:8000).
## Testes
Existem duas maneiras de se executar os testes automatizados localmente:
- Você já executou o comando `docker-compose -f local.yml up` e o servidor está funcionando.
```
docker-compose -f local.yml exec django pytest
```
- Você deseja apenas executar os testes sem necessariamente levantar o servidor. Antes é necessário construir a imagem do backend e disponibilizar o banco de dados para então executar o pytest via `docker run`
```
docker build -f compose/dev/django/Dockerfile -t django_test .
docker run -d --env-file=./compose/dev/test_env --name=postgres_test postgres:9.6
docker run --env-file=./compose/dev/test_env --link=postgres_test:postgres \
django_test /test.sh
```
## Variáveis de ambiente
### Banco de dados
- POSTGRES_HOST - opcional; padrão 'postgres'
- POSTGRES_DB - obrigatório
- POSTGRES_USER - obrigatório
- POSTGRES_PASSWORD - obrigatório
### Email
- MAILGUN_SENDER_DOMAIN - obrigatório em produção
- DJANGO_DEFAULT_FROM_EMAIL - obrigatório em produção
- DJANGO_MAILGUN_API_KEY - obrigatório em produção
### Django
- DJANGO_ALLOWED_HOSTS - obrigatório em produção
- DJANGO_ADMIN_URL - opcional
- DJANGO_SETTINGS_MODULE - opcional; use `config.settings.production` em produção
- DJANGO_ACCOUNT_ALLOW_REGISTRATION - opcional; padrão True
- DJANGO_SECRET_KEY - obrigatório em produção
- USE_CACHE - opcional; padrão True
- USE_DOCKER - opcional; desnecessário em produção; em ambientes locais, escreva 'yes' se estiver usando Docker
### Redis
- REDIS_URL - obrigatório em produção; exemplo: `redis://127.0.0.1:6379`
### Sentry
- DJANGO_SENTRY_DSN - opcional; só válido em produção
## Depoly em produção
Um exemplo de deploy em produção pode ser encontrado no arquivo `production.yml`.
Para rodá-lo localmente, e assim ter o máximo de aderência com o ambiente final, cire um arquivo `.env` baseado em `env.example` com as configurações necessárias e execute:
```
docker-compose -f production.yml up
```
## Integrações de deploy
**Commits no branch `master`** fazem releases da versão em **desenvolvimento**.
**Tags** fazem releases em [**produção**](http://example.com/).
__version__ = '0.1.0'
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
"""
To understand why this file is here, please read:
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
"""
"""
To understand why this file is here, please read:
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
"""
import django.contrib.sites.models
from django.contrib.sites.models import _simple_domain_name_validator
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.CreateModel(
name='Site',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('domain', models.CharField(
max_length=100, verbose_name='domain name', validators=[_simple_domain_name_validator]
)),
('name', models.CharField(max_length=50, verbose_name='display name')),
],
options={
'ordering': ('domain',),
'db_table': 'django_site',
'verbose_name': 'site',
'verbose_name_plural': 'sites',
},
bases=(models.Model,),
managers=[
('objects', django.contrib.sites.models.SiteManager()),
],
),
]
import django.contrib.sites.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sites', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='site',
name='domain',
field=models.CharField(
max_length=100, unique=True, validators=[django.contrib.sites.models._simple_domain_name_validator],
verbose_name='domain name'
),
),