├── .gitignore ├── LICENSE ├── README.md ├── cookiecutter.json ├── hooks └── post_gen_project.py └── {{cookiecutter.project_name}} ├── .env.dev ├── .env.dev-sample ├── .env.dev.db ├── .env.dev.db-sample ├── .env.prod ├── .env.prod-sample ├── .env.prod.db ├── .env.prod.db-sample ├── .env.prod.grafana ├── .env.prod.grafana-sample ├── .env.prod.proxy-companion ├── .env.prod.proxy-companion-sample ├── .github └── workflows │ └── deploy.prod.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── Dockerfile ├── Dockerfile.prod ├── entrypoint.prod.sh ├── entrypoint.sh ├── manage.py ├── requirements.txt └── {{cookiecutter.project_name}} │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── docker-compose.prod.yml ├── docker-compose.yml ├── grafana ├── Dockerfile └── provisioning │ ├── dashboards │ ├── dashboard.yml │ └── django.json │ └── datasources │ └── prometheus.yml ├── nginx ├── Dockerfile ├── custom.conf └── vhost.d │ └── default ├── prometheus ├── Dockerfile ├── django.rules └── prometheus.yml └── pyproject.toml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Adrian Castellanos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The ultimate Django template to build a startup 2 | 3 | Lets be clear. If you can do a task in less than 5 minutes why would you even bother in do all this hard work by yourself? This cookie cutter provides you with: 4 | 1. **Django base project:** The wizzard will create a default Django project structure 5 | 2. **CI/CD integration with Github actions:** Github actions will be already configured in your project. It will deploy to your production server everytime a new commit is pushed to the master branch. 6 | 3. **Docker:** you will get Docker support out of the box. You will get a production ready Docker environment and also a local development environment to add new features to your project. 7 | 4. **Docker environment files:** The template will automatically the environment files that contains all the sensetive data. This files will not be reposited in your project to prevent password leaks. 8 | 5. **HTTPS out of the box:** When using the template wizard, you must use the real production domain for your project. This will be used to create the certificates of your production domain. The certificates will be automatically renewed. 9 | 6. **Monitoring:** If selected in the wizard, Sentry configuration will be added to your project. Remember to edit the Sentry DSN once you created your project in order to connect your project with your Sentry account. 10 | 7. **Metrics:** If selected in the wizard, Grafana and Prometheus will be added to your project. This template will configure the datasource automatically and will add a dashboard to your Grafana displaying basic metrics of your Django application. 11 | 12 | # Languages and Technologies 👨🏻‍💻 13 | 14 | ![Django](https://img.shields.io/badge/django-%23092E20.svg?style=for-the-badge&logo=django&logoColor=white) 15 | ![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white) 16 | ![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) 17 | ![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?style=for-the-badge&logo=html5&logoColor=white) 18 | ![Nginx](https://img.shields.io/badge/nginx-%23009639.svg?style=for-the-badge&logo=nginx&logoColor=white) 19 | ![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white) 20 | ![Postgres](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white) 21 | ![DigitalOcean](https://img.shields.io/badge/DigitalOcean-%230167ff.svg?style=for-the-badge&logo=digitalOcean&logoColor=white) 22 | ![Prometheus](https://img.shields.io/badge/Prometheus-E6522C?style=for-the-badge&logo=Prometheus&logoColor=white) 23 | ![Grafana](https://img.shields.io/badge/grafana-%23F46800.svg?style=for-the-badge&logo=grafana&logoColor=white) 24 | 25 | # Architecture Diagram 26 | 27 | ![Arhitecture Diagram](https://user-images.githubusercontent.com/23509868/137785149-5aa83029-6579-4b1c-a4e6-c2de2e27722e.jpg) 28 | 29 | # Things to take in consideration 30 | 31 | - The .envs generated by the template will be in the .gitignore. Those files will be generated but will not be reposited. When you install the app in the server, make sure that you copy the .env files. 32 | 33 | - In order to make Letsencrypt generate the certificates it will use a HTTP-01 challenge. In order to configure the pro environment, make sure that the domain configured in the cookicuter is properly configured in the DNS side. You must add A and AAA records in order to make letsencrypt work. If you want to learn more of the challenges that Letsencrypt does, follow this [guide](https://letsencrypt.org/docs/challenge-types/). 34 | 35 | 36 | # Usage of the django-template 37 | 38 | To execute the cookiecutter template wizard run: 39 | ``` 40 | $ pip install cookiecutter 41 | $ cookiecutter gh:adriancast/django-template 42 | ``` 43 | If you need more information about cookiecutter visit this [oficial guide](https://cookiecutter.readthedocs.io/en/latest/installation.html). 44 | 45 | ![Screenshot from 2021-07-11 13-09-40](https://user-images.githubusercontent.com/17761956/125192676-63377180-e249-11eb-8014-1fbecc749ecc.png) 46 | 47 | -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_name": "projectname", 3 | "license": ["MIT License", "GNU General Public License v3", "Unlicense"], 4 | "secret_key": "Plea$eUse$trong$ecretKey", 5 | "postgresql_database": "DatabaseNamePostgreSQL", 6 | "postgresql_user": "DatabaseUserPostgreSQL", 7 | "postgresql_password_dev": "DevelopmentPostgresqlPa$$w0d", 8 | "postgresql_password_prod": "ProductionPostgresqlPa$$w0d", 9 | "add_sentry": ["yes", "no"], 10 | "add_prometheus_and_grafana": ["yes", "no"], 11 | "production_domain_url": "projectname.com", 12 | "letsencrypt_email": "hello@projectname.com", 13 | "dockerhub_account": "YourDockerhubUsername" 14 | } 15 | -------------------------------------------------------------------------------- /hooks/post_gen_project.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | 5 | def remove(filepath): 6 | if os.path.isfile(filepath): 7 | os.remove(filepath) 8 | elif os.path.isdir(filepath): 9 | shutil.rmtree(filepath) 10 | 11 | 12 | add_prometheus_and_grafana = '{{cookiecutter.add_prometheus_and_grafana}}' == 'yes' 13 | add_sentry = '{{cookiecutter.add_sentry}}' == 'yes' 14 | production_domain_url = '{{cookiecutter.production_domain_url}}' 15 | project_path = os.getcwd() 16 | 17 | icon_check = '✅' 18 | icon_cross = '❌' 19 | icon_warning = '⚠️' 20 | summary_text = """ 21 | 22 | ███████╗██╗ ██╗███╗ ███╗███╗ ███╗ █████╗ ██████╗ ██╗ ██╗ 23 | ██╔════╝██║ ██║████╗ ████║████╗ ████║██╔══██╗██╔══██╗╚██╗ ██╔╝ 24 | ███████╗██║ ██║██╔████╔██║██╔████╔██║███████║██████╔╝ ╚████╔╝ 25 | ╚════██║██║ ██║██║╚██╔╝██║██║╚██╔╝██║██╔══██║██╔══██╗ ╚██╔╝ 26 | ███████║╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║██║ ██║██║ ██║ ██║ 27 | ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ 28 | 29 | """ 30 | if not add_prometheus_and_grafana: 31 | remove(os.path.join(project_path, 'prometheus')) 32 | 33 | print(summary_text) 34 | print('{icon} Project generated in: {project_path}'.format( 35 | project_path=project_path, 36 | icon=icon_check) 37 | ) 38 | print('{icon} Grafana and Prometheus added to the project'.format( 39 | project_path=project_path, 40 | icon=(icon_check if add_prometheus_and_grafana else icon_cross)) 41 | ) 42 | print('{icon} Sentry and Prometheus added to the project'.format( 43 | project_path=project_path, 44 | icon=(icon_check if add_sentry else icon_cross)) 45 | ) 46 | print('{icon} HTTPS certificates will be generated for the following domains:'.format(icon=icon_check)) 47 | print(' - {production_domain_url} '.format( 48 | production_domain_url=production_domain_url) 49 | ) 50 | print(' - www.{production_domain_url}'.format( 51 | production_domain_url=production_domain_url) 52 | ) 53 | if add_sentry: 54 | print('{icon} Sentry - manual configuration required:' 55 | ' Update "dsn" Sentry configuration in the bottom of the Django settings.py file'.format(icon=icon_warning)) 56 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.dev: -------------------------------------------------------------------------------- 1 | DEBUG=1 2 | SECRET_KEY={{cookiecutter.secret_key}} 3 | DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 [::1] 4 | SQL_ENGINE=django.db.backends.postgresql 5 | SQL_DATABASE={{cookiecutter.postgresql_database}}_dev 6 | SQL_USER={{cookiecutter.postgresql_user}} 7 | SQL_PASSWORD={{cookiecutter.postgresql_password_dev}} 8 | SQL_HOST=db 9 | SQL_PORT=5432 10 | DATABASE=postgres 11 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.dev-sample: -------------------------------------------------------------------------------- 1 | DEBUG=1 2 | SECRET_KEY= 3 | DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] 4 | SQL_ENGINE=django.db.backends.postgresql 5 | SQL_DATABASE= 6 | SQL_USER= 7 | SQL_PASSWORD= 8 | SQL_HOST=db 9 | SQL_PORT=5432 10 | DATABASE=postgres 11 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.dev.db: -------------------------------------------------------------------------------- 1 | POSTGRES_USER={{cookiecutter.postgresql_user}} 2 | POSTGRES_PASSWORD={{cookiecutter.postgresql_password_dev}} 3 | POSTGRES_DB={{cookiecutter.postgresql_database}}_dev 4 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.dev.db-sample: -------------------------------------------------------------------------------- 1 | POSTGRES_USER= 2 | POSTGRES_PASSWORD= -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod: -------------------------------------------------------------------------------- 1 | DEBUG=0 2 | SECRET_KEY={{cookiecutter.secret_key}} 3 | DJANGO_ALLOWED_HOSTS={{cookiecutter.production_domain_url}},www.{{cookiecutter.production_domain_url}} 4 | SQL_ENGINE=django.db.backends.postgresql 5 | SQL_DATABASE={{cookiecutter.postgresql_database}} 6 | SQL_USER={{cookiecutter.postgresql_user}} 7 | SQL_PASSWORD={{cookiecutter.postgresql_password_prod}} 8 | SQL_HOST=db 9 | SQL_PORT=5432 10 | DATABASE=postgres 11 | VIRTUAL_HOST={{cookiecutter.production_domain_url}},www.{{cookiecutter.production_domain_url}} 12 | VIRTUAL_PORT=8000 13 | LETSENCRYPT_HOST={{cookiecutter.production_domain_url}},www.{{cookiecutter.production_domain_url}} 14 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod-sample: -------------------------------------------------------------------------------- 1 | DEBUG=0 2 | SECRET_KEY= 3 | DJANGO_ALLOWED_HOSTS= 4 | SQL_ENGINE=django.db.backends.postgresql 5 | SQL_DATABASE= 6 | SQL_USER= 7 | SQL_PASSWORD= 8 | SQL_HOST=db 9 | SQL_PORT=5432 10 | DATABASE=postgres 11 | VIRTUAL_HOST=,www. 12 | VIRTUAL_PORT=8000 13 | LETSENCRYPT_HOST= 14 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.db: -------------------------------------------------------------------------------- 1 | POSTGRES_USER={{cookiecutter.postgresql_user}} 2 | POSTGRES_PASSWORD={{cookiecutter.postgresql_password_prod}} 3 | POSTGRES_DB={{cookiecutter.postgresql_database}} 4 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.db-sample: -------------------------------------------------------------------------------- 1 | POSTGRES_USER= 2 | POSTGRES_PASSWORD= 4 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.grafana: -------------------------------------------------------------------------------- 1 | GF_SECURITY_ADMIN_USER=admin 2 | GF_SECURITY_ADMIN_PASSWORD=admin -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.grafana-sample: -------------------------------------------------------------------------------- 1 | GF_SECURITY_ADMIN_USER=admin 2 | GF_SECURITY_ADMIN_PASSWORD=admin -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.proxy-companion: -------------------------------------------------------------------------------- 1 | DEFAULT_EMAIL={{cookiecutter.letsencrypt_email}} 2 | NGINX_PROXY_CONTAINER=nginx-proxy 3 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.env.prod.proxy-companion-sample: -------------------------------------------------------------------------------- 1 | DEFAULT_EMAIL= 2 | NGINX_PROXY_CONTAINER=nginx-proxy 3 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.github/workflows/deploy.prod.yml: -------------------------------------------------------------------------------- 1 | {% raw %} 2 | name: deploy-production 3 | 4 | on: 5 | push: 6 | branches: 7 | - 'master' 8 | 9 | jobs: 10 | docker-build-and-publish-web: 11 | name: docker-build-and-publish-web 12 | runs-on: ubuntu-latest 13 | steps: 14 | - 15 | uses: actions/checkout@v2 16 | - 17 | name: Set up QEMU 18 | uses: docker/setup-qemu-action@v1 19 | - 20 | name: Set up Docker Buildx 21 | uses: docker/setup-buildx-action@v1 22 | - 23 | name: Login to DockerHub 24 | uses: docker/login-action@v1 25 | with: 26 | username: ${{ secrets.DOCKERHUB_USERNAME }} 27 | password: ${{ secrets.DOCKERHUB_TOKEN }} 28 | - 29 | name: Build and push website 30 | id: docker_build_web 31 | uses: docker/build-push-action@v2 32 | with: 33 | context: ./app 34 | file: ./app/Dockerfile.prod 35 | pull: true 36 | push: true 37 | build-args: | 38 | arg1=value1 39 | arg2=value2 40 | cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest 41 | cache-to: type=inline 42 | tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }} 43 | 44 | docker-build-and-publish-prometheus: 45 | name: docker-build-and-publish-prometheus 46 | runs-on: ubuntu-latest 47 | steps: 48 | - 49 | uses: actions/checkout@v2 50 | - 51 | name: Set up QEMU 52 | uses: docker/setup-qemu-action@v1 53 | - 54 | name: Set up Docker Buildx 55 | uses: docker/setup-buildx-action@v1 56 | - 57 | name: Login to DockerHub 58 | uses: docker/login-action@v1 59 | with: 60 | username: ${{ secrets.DOCKERHUB_USERNAME }} 61 | password: ${{ secrets.DOCKERHUB_TOKEN }} 62 | - 63 | name: Build and push prometheus 64 | id: docker_build_prometheus 65 | uses: docker/build-push-action@v2 66 | with: 67 | context: ./prometheus 68 | pull: true 69 | push: true 70 | build-args: | 71 | arg1=value1 72 | arg2=value2 73 | cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-prometheus:latest 74 | cache-to: type=inline 75 | tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-prometheus:latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-prometheus:${{ github.sha }} 76 | 77 | docker-build-and-publish-grafana: 78 | name: docker-build-and-publish-grafana 79 | runs-on: ubuntu-latest 80 | steps: 81 | - 82 | uses: actions/checkout@v2 83 | - 84 | name: Set up QEMU 85 | uses: docker/setup-qemu-action@v1 86 | - 87 | name: Set up Docker Buildx 88 | uses: docker/setup-buildx-action@v1 89 | - 90 | name: Login to DockerHub 91 | uses: docker/login-action@v1 92 | with: 93 | username: ${{ secrets.DOCKERHUB_USERNAME }} 94 | password: ${{ secrets.DOCKERHUB_TOKEN }} 95 | - 96 | name: Build and push grafana 97 | id: docker_build_grafana 98 | uses: docker/build-push-action@v2 99 | with: 100 | context: ./grafana 101 | pull: true 102 | push: true 103 | build-args: | 104 | arg1=value1 105 | arg2=value2 106 | cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-grafana:latest 107 | cache-to: type=inline 108 | tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-grafana:latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-grafana:${{ github.sha }} 109 | 110 | docker-build-and-publish-nginx: 111 | name: docker-build-and-publish-nginx 112 | runs-on: ubuntu-latest 113 | steps: 114 | - 115 | uses: actions/checkout@v2 116 | - 117 | name: Set up QEMU 118 | uses: docker/setup-qemu-action@v1 119 | - 120 | name: Set up Docker Buildx 121 | uses: docker/setup-buildx-action@v1 122 | - 123 | name: Login to DockerHub 124 | uses: docker/login-action@v1 125 | with: 126 | username: ${{ secrets.DOCKERHUB_USERNAME }} 127 | password: ${{ secrets.DOCKERHUB_TOKEN }} 128 | - 129 | name: Build and push nginx 130 | id: docker_build_nginx 131 | uses: docker/build-push-action@v2 132 | with: 133 | context: ./nginx 134 | pull: true 135 | push: true 136 | build-args: | 137 | arg1=value1 138 | arg2=value2 139 | cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-grafana:latest 140 | cache-to: type=inline 141 | tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-nginx:latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-nginx:${{ github.sha }} 142 | 143 | deploy: 144 | name: deploy-to-production 145 | runs-on: ubuntu-latest 146 | needs: [docker-build-and-publish-web, docker-build-and-publish-prometheus, docker-build-and-publish-nginx, docker-build-and-publish-grafana] 147 | steps: 148 | - 149 | uses: actions/checkout@v2 150 | - 151 | name: Login to DockerHub 152 | uses: docker/login-action@v1 153 | with: 154 | username: ${{ secrets.DOCKERHUB_USERNAME }} 155 | password: ${{ secrets.DOCKERHUB_TOKEN }} 156 | - 157 | name: Deploy to server 158 | uses: wshihadeh/docker-deployment-action@v1 159 | with: 160 | remote_docker_host: ${{ secrets.PRODUCTION_SERVER_USER }}@${{ secrets.PRODUCTION_SERVER_IP }} 161 | ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} 162 | ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }} 163 | deployment_mode: docker-compose 164 | copy_stack_file: true 165 | pull_images_first: true 166 | {% endraw %} 167 | deploy_path: /opt/{{cookiecutter.project_name}} 168 | stack_file_name: docker-compose.prod.yml 169 | keep_files: 5 170 | args: up -d 171 | pre_deployment_command_args: | 172 | version 173 | docker volume create --name={{cookiecutter.project_name}}_postgres_data 174 | docker volume create --name=static_volume 175 | docker volume create --name=media_volume 176 | docker volume create --name=certs 177 | docker volume create --name=html 178 | docker volume create --name=vhost 179 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}docker volume create --name={{cookiecutter.project_name}}_grafana{% endif %} 180 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache 3 | .DS_Store 4 | .idea 5 | 6 | # Keep passwords outside the repository 7 | .env.dev 8 | .env.dev.db 9 | .env.prod 10 | .env.prod.db 11 | .env.prod.proxy-companion 12 | .env.prod.grafana 13 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/LICENSE: -------------------------------------------------------------------------------- 1 | {% if cookiecutter.license == "MIT License" %}MIT License 2 | 3 | Copyright (c) {% now 'utc', '%Y' %} {{cookiecutter.project_name}} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | {% elif cookiecutter.license == "GNU General Public License v3" %} GNU GENERAL PUBLIC LICENSE 23 | Version 3, 29 June 2007 24 | 25 | Copyright (C) 2007 Free Software Foundation, Inc. 26 | Everyone is permitted to copy and distribute verbatim copies 27 | of this license document, but changing it is not allowed. 28 | 29 | Preamble 30 | 31 | The GNU General Public License is a free, copyleft license for 32 | software and other kinds of works. 33 | 34 | The licenses for most software and other practical works are designed 35 | to take away your freedom to share and change the works. By contrast, 36 | the GNU General Public License is intended to guarantee your freedom to 37 | share and change all versions of a program--to make sure it remains free 38 | software for all its users. We, the Free Software Foundation, use the 39 | GNU General Public License for most of our software; it applies also to 40 | any other work released this way by its authors. You can apply it to 41 | your programs, too. 42 | 43 | When we speak of free software, we are referring to freedom, not 44 | price. Our General Public Licenses are designed to make sure that you 45 | have the freedom to distribute copies of free software (and charge for 46 | them if you wish), that you receive source code or can get it if you 47 | want it, that you can change the software or use pieces of it in new 48 | free programs, and that you know you can do these things. 49 | 50 | To protect your rights, we need to prevent others from denying you 51 | these rights or asking you to surrender the rights. Therefore, you have 52 | certain responsibilities if you distribute copies of the software, or if 53 | you modify it: responsibilities to respect the freedom of others. 54 | 55 | For example, if you distribute copies of such a program, whether 56 | gratis or for a fee, you must pass on to the recipients the same 57 | freedoms that you received. You must make sure that they, too, receive 58 | or can get the source code. And you must show them these terms so they 59 | know their rights. 60 | 61 | Developers that use the GNU GPL protect your rights with two steps: 62 | (1) assert copyright on the software, and (2) offer you this License 63 | giving you legal permission to copy, distribute and/or modify it. 64 | 65 | For the developers' and authors' protection, the GPL clearly explains 66 | that there is no warranty for this free software. For both users' and 67 | authors' sake, the GPL requires that modified versions be marked as 68 | changed, so that their problems will not be attributed erroneously to 69 | authors of previous versions. 70 | 71 | Some devices are designed to deny users access to install or run 72 | modified versions of the software inside them, although the manufacturer 73 | can do so. This is fundamentally incompatible with the aim of 74 | protecting users' freedom to change the software. The systematic 75 | pattern of such abuse occurs in the area of products for individuals to 76 | use, which is precisely where it is most unacceptable. Therefore, we 77 | have designed this version of the GPL to prohibit the practice for those 78 | products. If such problems arise substantially in other domains, we 79 | stand ready to extend this provision to those domains in future versions 80 | of the GPL, as needed to protect the freedom of users. 81 | 82 | Finally, every program is threatened constantly by software patents. 83 | States should not allow patents to restrict development and use of 84 | software on general-purpose computers, but in those that do, we wish to 85 | avoid the special danger that patents applied to a free program could 86 | make it effectively proprietary. To prevent this, the GPL assures that 87 | patents cannot be used to render the program non-free. 88 | 89 | The precise terms and conditions for copying, distribution and 90 | modification follow. 91 | 92 | TERMS AND CONDITIONS 93 | 94 | 0. Definitions. 95 | 96 | "This License" refers to version 3 of the GNU General Public License. 97 | 98 | "Copyright" also means copyright-like laws that apply to other kinds of 99 | works, such as semiconductor masks. 100 | 101 | "The Program" refers to any copyrightable work licensed under this 102 | License. Each licensee is addressed as "you". "Licensees" and 103 | "recipients" may be individuals or organizations. 104 | 105 | To "modify" a work means to copy from or adapt all or part of the work 106 | in a fashion requiring copyright permission, other than the making of an 107 | exact copy. The resulting work is called a "modified version" of the 108 | earlier work or a work "based on" the earlier work. 109 | 110 | A "covered work" means either the unmodified Program or a work based 111 | on the Program. 112 | 113 | To "propagate" a work means to do anything with it that, without 114 | permission, would make you directly or secondarily liable for 115 | infringement under applicable copyright law, except executing it on a 116 | computer or modifying a private copy. Propagation includes copying, 117 | distribution (with or without modification), making available to the 118 | public, and in some countries other activities as well. 119 | 120 | To "convey" a work means any kind of propagation that enables other 121 | parties to make or receive copies. Mere interaction with a user through 122 | a computer network, with no transfer of a copy, is not conveying. 123 | 124 | An interactive user interface displays "Appropriate Legal Notices" 125 | to the extent that it includes a convenient and prominently visible 126 | feature that (1) displays an appropriate copyright notice, and (2) 127 | tells the user that there is no warranty for the work (except to the 128 | extent that warranties are provided), that licensees may convey the 129 | work under this License, and how to view a copy of this License. If 130 | the interface presents a list of user commands or options, such as a 131 | menu, a prominent item in the list meets this criterion. 132 | 133 | 1. Source Code. 134 | 135 | The "source code" for a work means the preferred form of the work 136 | for making modifications to it. "Object code" means any non-source 137 | form of a work. 138 | 139 | A "Standard Interface" means an interface that either is an official 140 | standard defined by a recognized standards body, or, in the case of 141 | interfaces specified for a particular programming language, one that 142 | is widely used among developers working in that language. 143 | 144 | The "System Libraries" of an executable work include anything, other 145 | than the work as a whole, that (a) is included in the normal form of 146 | packaging a Major Component, but which is not part of that Major 147 | Component, and (b) serves only to enable use of the work with that 148 | Major Component, or to implement a Standard Interface for which an 149 | implementation is available to the public in source code form. A 150 | "Major Component", in this context, means a major essential component 151 | (kernel, window system, and so on) of the specific operating system 152 | (if any) on which the executable work runs, or a compiler used to 153 | produce the work, or an object code interpreter used to run it. 154 | 155 | The "Corresponding Source" for a work in object code form means all 156 | the source code needed to generate, install, and (for an executable 157 | work) run the object code and to modify the work, including scripts to 158 | control those activities. However, it does not include the work's 159 | System Libraries, or general-purpose tools or generally available free 160 | programs which are used unmodified in performing those activities but 161 | which are not part of the work. For example, Corresponding Source 162 | includes interface definition files associated with source files for 163 | the work, and the source code for shared libraries and dynamically 164 | linked subprograms that the work is specifically designed to require, 165 | such as by intimate data communication or control flow between those 166 | subprograms and other parts of the work. 167 | 168 | The Corresponding Source need not include anything that users 169 | can regenerate automatically from other parts of the Corresponding 170 | Source. 171 | 172 | The Corresponding Source for a work in source code form is that 173 | same work. 174 | 175 | 2. Basic Permissions. 176 | 177 | All rights granted under this License are granted for the term of 178 | copyright on the Program, and are irrevocable provided the stated 179 | conditions are met. This License explicitly affirms your unlimited 180 | permission to run the unmodified Program. The output from running a 181 | covered work is covered by this License only if the output, given its 182 | content, constitutes a covered work. This License acknowledges your 183 | rights of fair use or other equivalent, as provided by copyright law. 184 | 185 | You may make, run and propagate covered works that you do not 186 | convey, without conditions so long as your license otherwise remains 187 | in force. You may convey covered works to others for the sole purpose 188 | of having them make modifications exclusively for you, or provide you 189 | with facilities for running those works, provided that you comply with 190 | the terms of this License in conveying all material for which you do 191 | not control copyright. Those thus making or running the covered works 192 | for you must do so exclusively on your behalf, under your direction 193 | and control, on terms that prohibit them from making any copies of 194 | your copyrighted material outside their relationship with you. 195 | 196 | Conveying under any other circumstances is permitted solely under 197 | the conditions stated below. Sublicensing is not allowed; section 10 198 | makes it unnecessary. 199 | 200 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 201 | 202 | No covered work shall be deemed part of an effective technological 203 | measure under any applicable law fulfilling obligations under article 204 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 205 | similar laws prohibiting or restricting circumvention of such 206 | measures. 207 | 208 | When you convey a covered work, you waive any legal power to forbid 209 | circumvention of technological measures to the extent such circumvention 210 | is effected by exercising rights under this License with respect to 211 | the covered work, and you disclaim any intention to limit operation or 212 | modification of the work as a means of enforcing, against the work's 213 | users, your or third parties' legal rights to forbid circumvention of 214 | technological measures. 215 | 216 | 4. Conveying Verbatim Copies. 217 | 218 | You may convey verbatim copies of the Program's source code as you 219 | receive it, in any medium, provided that you conspicuously and 220 | appropriately publish on each copy an appropriate copyright notice; 221 | keep intact all notices stating that this License and any 222 | non-permissive terms added in accord with section 7 apply to the code; 223 | keep intact all notices of the absence of any warranty; and give all 224 | recipients a copy of this License along with the Program. 225 | 226 | You may charge any price or no price for each copy that you convey, 227 | and you may offer support or warranty protection for a fee. 228 | 229 | 5. Conveying Modified Source Versions. 230 | 231 | You may convey a work based on the Program, or the modifications to 232 | produce it from the Program, in the form of source code under the 233 | terms of section 4, provided that you also meet all of these conditions: 234 | 235 | a) The work must carry prominent notices stating that you modified 236 | it, and giving a relevant date. 237 | 238 | b) The work must carry prominent notices stating that it is 239 | released under this License and any conditions added under section 240 | 7. This requirement modifies the requirement in section 4 to 241 | "keep intact all notices". 242 | 243 | c) You must license the entire work, as a whole, under this 244 | License to anyone who comes into possession of a copy. This 245 | License will therefore apply, along with any applicable section 7 246 | additional terms, to the whole of the work, and all its parts, 247 | regardless of how they are packaged. This License gives no 248 | permission to license the work in any other way, but it does not 249 | invalidate such permission if you have separately received it. 250 | 251 | d) If the work has interactive user interfaces, each must display 252 | Appropriate Legal Notices; however, if the Program has interactive 253 | interfaces that do not display Appropriate Legal Notices, your 254 | work need not make them do so. 255 | 256 | A compilation of a covered work with other separate and independent 257 | works, which are not by their nature extensions of the covered work, 258 | and which are not combined with it such as to form a larger program, 259 | in or on a volume of a storage or distribution medium, is called an 260 | "aggregate" if the compilation and its resulting copyright are not 261 | used to limit the access or legal rights of the compilation's users 262 | beyond what the individual works permit. Inclusion of a covered work 263 | in an aggregate does not cause this License to apply to the other 264 | parts of the aggregate. 265 | 266 | 6. Conveying Non-Source Forms. 267 | 268 | You may convey a covered work in object code form under the terms 269 | of sections 4 and 5, provided that you also convey the 270 | machine-readable Corresponding Source under the terms of this License, 271 | in one of these ways: 272 | 273 | a) Convey the object code in, or embodied in, a physical product 274 | (including a physical distribution medium), accompanied by the 275 | Corresponding Source fixed on a durable physical medium 276 | customarily used for software interchange. 277 | 278 | b) Convey the object code in, or embodied in, a physical product 279 | (including a physical distribution medium), accompanied by a 280 | written offer, valid for at least three years and valid for as 281 | long as you offer spare parts or customer support for that product 282 | model, to give anyone who possesses the object code either (1) a 283 | copy of the Corresponding Source for all the software in the 284 | product that is covered by this License, on a durable physical 285 | medium customarily used for software interchange, for a price no 286 | more than your reasonable cost of physically performing this 287 | conveying of source, or (2) access to copy the 288 | Corresponding Source from a network server at no charge. 289 | 290 | c) Convey individual copies of the object code with a copy of the 291 | written offer to provide the Corresponding Source. This 292 | alternative is allowed only occasionally and noncommercially, and 293 | only if you received the object code with such an offer, in accord 294 | with subsection 6b. 295 | 296 | d) Convey the object code by offering access from a designated 297 | place (gratis or for a charge), and offer equivalent access to the 298 | Corresponding Source in the same way through the same place at no 299 | further charge. You need not require recipients to copy the 300 | Corresponding Source along with the object code. If the place to 301 | copy the object code is a network server, the Corresponding Source 302 | may be on a different server (operated by you or a third party) 303 | that supports equivalent copying facilities, provided you maintain 304 | clear directions next to the object code saying where to find the 305 | Corresponding Source. Regardless of what server hosts the 306 | Corresponding Source, you remain obligated to ensure that it is 307 | available for as long as needed to satisfy these requirements. 308 | 309 | e) Convey the object code using peer-to-peer transmission, provided 310 | you inform other peers where the object code and Corresponding 311 | Source of the work are being offered to the general public at no 312 | charge under subsection 6d. 313 | 314 | A separable portion of the object code, whose source code is excluded 315 | from the Corresponding Source as a System Library, need not be 316 | included in conveying the object code work. 317 | 318 | A "User Product" is either (1) a "consumer product", which means any 319 | tangible personal property which is normally used for personal, family, 320 | or household purposes, or (2) anything designed or sold for incorporation 321 | into a dwelling. In determining whether a product is a consumer product, 322 | doubtful cases shall be resolved in favor of coverage. For a particular 323 | product received by a particular user, "normally used" refers to a 324 | typical or common use of that class of product, regardless of the status 325 | of the particular user or of the way in which the particular user 326 | actually uses, or expects or is expected to use, the product. A product 327 | is a consumer product regardless of whether the product has substantial 328 | commercial, industrial or non-consumer uses, unless such uses represent 329 | the only significant mode of use of the product. 330 | 331 | "Installation Information" for a User Product means any methods, 332 | procedures, authorization keys, or other information required to install 333 | and execute modified versions of a covered work in that User Product from 334 | a modified version of its Corresponding Source. The information must 335 | suffice to ensure that the continued functioning of the modified object 336 | code is in no case prevented or interfered with solely because 337 | modification has been made. 338 | 339 | If you convey an object code work under this section in, or with, or 340 | specifically for use in, a User Product, and the conveying occurs as 341 | part of a transaction in which the right of possession and use of the 342 | User Product is transferred to the recipient in perpetuity or for a 343 | fixed term (regardless of how the transaction is characterized), the 344 | Corresponding Source conveyed under this section must be accompanied 345 | by the Installation Information. But this requirement does not apply 346 | if neither you nor any third party retains the ability to install 347 | modified object code on the User Product (for example, the work has 348 | been installed in ROM). 349 | 350 | The requirement to provide Installation Information does not include a 351 | requirement to continue to provide support service, warranty, or updates 352 | for a work that has been modified or installed by the recipient, or for 353 | the User Product in which it has been modified or installed. Access to a 354 | network may be denied when the modification itself materially and 355 | adversely affects the operation of the network or violates the rules and 356 | protocols for communication across the network. 357 | 358 | Corresponding Source conveyed, and Installation Information provided, 359 | in accord with this section must be in a format that is publicly 360 | documented (and with an implementation available to the public in 361 | source code form), and must require no special password or key for 362 | unpacking, reading or copying. 363 | 364 | 7. Additional Terms. 365 | 366 | "Additional permissions" are terms that supplement the terms of this 367 | License by making exceptions from one or more of its conditions. 368 | Additional permissions that are applicable to the entire Program shall 369 | be treated as though they were included in this License, to the extent 370 | that they are valid under applicable law. If additional permissions 371 | apply only to part of the Program, that part may be used separately 372 | under those permissions, but the entire Program remains governed by 373 | this License without regard to the additional permissions. 374 | 375 | When you convey a copy of a covered work, you may at your option 376 | remove any additional permissions from that copy, or from any part of 377 | it. (Additional permissions may be written to require their own 378 | removal in certain cases when you modify the work.) You may place 379 | additional permissions on material, added by you to a covered work, 380 | for which you have or can give appropriate copyright permission. 381 | 382 | Notwithstanding any other provision of this License, for material you 383 | add to a covered work, you may (if authorized by the copyright holders of 384 | that material) supplement the terms of this License with terms: 385 | 386 | a) Disclaiming warranty or limiting liability differently from the 387 | terms of sections 15 and 16 of this License; or 388 | 389 | b) Requiring preservation of specified reasonable legal notices or 390 | author attributions in that material or in the Appropriate Legal 391 | Notices displayed by works containing it; or 392 | 393 | c) Prohibiting misrepresentation of the origin of that material, or 394 | requiring that modified versions of such material be marked in 395 | reasonable ways as different from the original version; or 396 | 397 | d) Limiting the use for publicity purposes of names of licensors or 398 | authors of the material; or 399 | 400 | e) Declining to grant rights under trademark law for use of some 401 | trade names, trademarks, or service marks; or 402 | 403 | f) Requiring indemnification of licensors and authors of that 404 | material by anyone who conveys the material (or modified versions of 405 | it) with contractual assumptions of liability to the recipient, for 406 | any liability that these contractual assumptions directly impose on 407 | those licensors and authors. 408 | 409 | All other non-permissive additional terms are considered "further 410 | restrictions" within the meaning of section 10. If the Program as you 411 | received it, or any part of it, contains a notice stating that it is 412 | governed by this License along with a term that is a further 413 | restriction, you may remove that term. If a license document contains 414 | a further restriction but permits relicensing or conveying under this 415 | License, you may add to a covered work material governed by the terms 416 | of that license document, provided that the further restriction does 417 | not survive such relicensing or conveying. 418 | 419 | If you add terms to a covered work in accord with this section, you 420 | must place, in the relevant source files, a statement of the 421 | additional terms that apply to those files, or a notice indicating 422 | where to find the applicable terms. 423 | 424 | Additional terms, permissive or non-permissive, may be stated in the 425 | form of a separately written license, or stated as exceptions; 426 | the above requirements apply either way. 427 | 428 | 8. Termination. 429 | 430 | You may not propagate or modify a covered work except as expressly 431 | provided under this License. Any attempt otherwise to propagate or 432 | modify it is void, and will automatically terminate your rights under 433 | this License (including any patent licenses granted under the third 434 | paragraph of section 11). 435 | 436 | However, if you cease all violation of this License, then your 437 | license from a particular copyright holder is reinstated (a) 438 | provisionally, unless and until the copyright holder explicitly and 439 | finally terminates your license, and (b) permanently, if the copyright 440 | holder fails to notify you of the violation by some reasonable means 441 | prior to 60 days after the cessation. 442 | 443 | Moreover, your license from a particular copyright holder is 444 | reinstated permanently if the copyright holder notifies you of the 445 | violation by some reasonable means, this is the first time you have 446 | received notice of violation of this License (for any work) from that 447 | copyright holder, and you cure the violation prior to 30 days after 448 | your receipt of the notice. 449 | 450 | Termination of your rights under this section does not terminate the 451 | licenses of parties who have received copies or rights from you under 452 | this License. If your rights have been terminated and not permanently 453 | reinstated, you do not qualify to receive new licenses for the same 454 | material under section 10. 455 | 456 | 9. Acceptance Not Required for Having Copies. 457 | 458 | You are not required to accept this License in order to receive or 459 | run a copy of the Program. Ancillary propagation of a covered work 460 | occurring solely as a consequence of using peer-to-peer transmission 461 | to receive a copy likewise does not require acceptance. However, 462 | nothing other than this License grants you permission to propagate or 463 | modify any covered work. These actions infringe copyright if you do 464 | not accept this License. Therefore, by modifying or propagating a 465 | covered work, you indicate your acceptance of this License to do so. 466 | 467 | 10. Automatic Licensing of Downstream Recipients. 468 | 469 | Each time you convey a covered work, the recipient automatically 470 | receives a license from the original licensors, to run, modify and 471 | propagate that work, subject to this License. You are not responsible 472 | for enforcing compliance by third parties with this License. 473 | 474 | An "entity transaction" is a transaction transferring control of an 475 | organization, or substantially all assets of one, or subdividing an 476 | organization, or merging organizations. If propagation of a covered 477 | work results from an entity transaction, each party to that 478 | transaction who receives a copy of the work also receives whatever 479 | licenses to the work the party's predecessor in interest had or could 480 | give under the previous paragraph, plus a right to possession of the 481 | Corresponding Source of the work from the predecessor in interest, if 482 | the predecessor has it or can get it with reasonable efforts. 483 | 484 | You may not impose any further restrictions on the exercise of the 485 | rights granted or affirmed under this License. For example, you may 486 | not impose a license fee, royalty, or other charge for exercise of 487 | rights granted under this License, and you may not initiate litigation 488 | (including a cross-claim or counterclaim in a lawsuit) alleging that 489 | any patent claim is infringed by making, using, selling, offering for 490 | sale, or importing the Program or any portion of it. 491 | 492 | 11. Patents. 493 | 494 | A "contributor" is a copyright holder who authorizes use under this 495 | License of the Program or a work on which the Program is based. The 496 | work thus licensed is called the contributor's "contributor version". 497 | 498 | A contributor's "essential patent claims" are all patent claims 499 | owned or controlled by the contributor, whether already acquired or 500 | hereafter acquired, that would be infringed by some manner, permitted 501 | by this License, of making, using, or selling its contributor version, 502 | but do not include claims that would be infringed only as a 503 | consequence of further modification of the contributor version. For 504 | purposes of this definition, "control" includes the right to grant 505 | patent sublicenses in a manner consistent with the requirements of 506 | this License. 507 | 508 | Each contributor grants you a non-exclusive, worldwide, royalty-free 509 | patent license under the contributor's essential patent claims, to 510 | make, use, sell, offer for sale, import and otherwise run, modify and 511 | propagate the contents of its contributor version. 512 | 513 | In the following three paragraphs, a "patent license" is any express 514 | agreement or commitment, however denominated, not to enforce a patent 515 | (such as an express permission to practice a patent or covenant not to 516 | sue for patent infringement). To "grant" such a patent license to a 517 | party means to make such an agreement or commitment not to enforce a 518 | patent against the party. 519 | 520 | If you convey a covered work, knowingly relying on a patent license, 521 | and the Corresponding Source of the work is not available for anyone 522 | to copy, free of charge and under the terms of this License, through a 523 | publicly available network server or other readily accessible means, 524 | then you must either (1) cause the Corresponding Source to be so 525 | available, or (2) arrange to deprive yourself of the benefit of the 526 | patent license for this particular work, or (3) arrange, in a manner 527 | consistent with the requirements of this License, to extend the patent 528 | license to downstream recipients. "Knowingly relying" means you have 529 | actual knowledge that, but for the patent license, your conveying the 530 | covered work in a country, or your recipient's use of the covered work 531 | in a country, would infringe one or more identifiable patents in that 532 | country that you have reason to believe are valid. 533 | 534 | If, pursuant to or in connection with a single transaction or 535 | arrangement, you convey, or propagate by procuring conveyance of, a 536 | covered work, and grant a patent license to some of the parties 537 | receiving the covered work authorizing them to use, propagate, modify 538 | or convey a specific copy of the covered work, then the patent license 539 | you grant is automatically extended to all recipients of the covered 540 | work and works based on it. 541 | 542 | A patent license is "discriminatory" if it does not include within 543 | the scope of its coverage, prohibits the exercise of, or is 544 | conditioned on the non-exercise of one or more of the rights that are 545 | specifically granted under this License. You may not convey a covered 546 | work if you are a party to an arrangement with a third party that is 547 | in the business of distributing software, under which you make payment 548 | to the third party based on the extent of your activity of conveying 549 | the work, and under which the third party grants, to any of the 550 | parties who would receive the covered work from you, a discriminatory 551 | patent license (a) in connection with copies of the covered work 552 | conveyed by you (or copies made from those copies), or (b) primarily 553 | for and in connection with specific products or compilations that 554 | contain the covered work, unless you entered into that arrangement, 555 | or that patent license was granted, prior to 28 March 2007. 556 | 557 | Nothing in this License shall be construed as excluding or limiting 558 | any implied license or other defenses to infringement that may 559 | otherwise be available to you under applicable patent law. 560 | 561 | 12. No Surrender of Others' Freedom. 562 | 563 | If conditions are imposed on you (whether by court order, agreement or 564 | otherwise) that contradict the conditions of this License, they do not 565 | excuse you from the conditions of this License. If you cannot convey a 566 | covered work so as to satisfy simultaneously your obligations under this 567 | License and any other pertinent obligations, then as a consequence you may 568 | not convey it at all. For example, if you agree to terms that obligate you 569 | to collect a royalty for further conveying from those to whom you convey 570 | the Program, the only way you could satisfy both those terms and this 571 | License would be to refrain entirely from conveying the Program. 572 | 573 | 13. Use with the GNU Affero General Public License. 574 | 575 | Notwithstanding any other provision of this License, you have 576 | permission to link or combine any covered work with a work licensed 577 | under version 3 of the GNU Affero General Public License into a single 578 | combined work, and to convey the resulting work. The terms of this 579 | License will continue to apply to the part which is the covered work, 580 | but the special requirements of the GNU Affero General Public License, 581 | section 13, concerning interaction through a network will apply to the 582 | combination as such. 583 | 584 | 14. Revised Versions of this License. 585 | 586 | The Free Software Foundation may publish revised and/or new versions of 587 | the GNU General Public License from time to time. Such new versions will 588 | be similar in spirit to the present version, but may differ in detail to 589 | address new problems or concerns. 590 | 591 | Each version is given a distinguishing version number. If the 592 | Program specifies that a certain numbered version of the GNU General 593 | Public License "or any later version" applies to it, you have the 594 | option of following the terms and conditions either of that numbered 595 | version or of any later version published by the Free Software 596 | Foundation. If the Program does not specify a version number of the 597 | GNU General Public License, you may choose any version ever published 598 | by the Free Software Foundation. 599 | 600 | If the Program specifies that a proxy can decide which future 601 | versions of the GNU General Public License can be used, that proxy's 602 | public statement of acceptance of a version permanently authorizes you 603 | to choose that version for the Program. 604 | 605 | Later license versions may give you additional or different 606 | permissions. However, no additional obligations are imposed on any 607 | author or copyright holder as a result of your choosing to follow a 608 | later version. 609 | 610 | 15. Disclaimer of Warranty. 611 | 612 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 613 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 614 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 615 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 616 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 617 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 618 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 619 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 620 | 621 | 16. Limitation of Liability. 622 | 623 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 624 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 625 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 626 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 627 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 628 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 629 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 630 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 631 | SUCH DAMAGES. 632 | 633 | 17. Interpretation of Sections 15 and 16. 634 | 635 | If the disclaimer of warranty and limitation of liability provided 636 | above cannot be given local legal effect according to their terms, 637 | reviewing courts shall apply local law that most closely approximates 638 | an absolute waiver of all civil liability in connection with the 639 | Program, unless a warranty or assumption of liability accompanies a 640 | copy of the Program in return for a fee. 641 | 642 | END OF TERMS AND CONDITIONS 643 | 644 | How to Apply These Terms to Your New Programs 645 | 646 | If you develop a new program, and you want it to be of the greatest 647 | possible use to the public, the best way to achieve this is to make it 648 | free software which everyone can redistribute and change under these terms. 649 | 650 | To do so, attach the following notices to the program. It is safest 651 | to attach them to the start of each source file to most effectively 652 | state the exclusion of warranty; and each file should have at least 653 | the "copyright" line and a pointer to where the full notice is found. 654 | 655 | 656 | Copyright (C) {% now 'utc', '%Y' %} {{cookiecutter.project_name}} 657 | 658 | This program is free software: you can redistribute it and/or modify 659 | it under the terms of the GNU General Public License as published by 660 | the Free Software Foundation, either version 3 of the License, or 661 | (at your option) any later version. 662 | 663 | This program is distributed in the hope that it will be useful, 664 | but WITHOUT ANY WARRANTY; without even the implied warranty of 665 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 666 | GNU General Public License for more details. 667 | 668 | You should have received a copy of the GNU General Public License 669 | along with this program. If not, see . 670 | 671 | Also add information on how to contact you by electronic and paper mail. 672 | 673 | If the program does terminal interaction, make it output a short 674 | notice like this when it starts in an interactive mode: 675 | 676 | Copyright (C) {% now 'utc', '%Y' %} {{cookiecutter.project_name}} 677 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 678 | This is free software, and you are welcome to redistribute it 679 | under certain conditions; type `show c' for details. 680 | 681 | The hypothetical commands `show w' and `show c' should show the appropriate 682 | parts of the General Public License. Of course, your program's commands 683 | might be different; for a GUI interface, you would use an "about box". 684 | 685 | You should also get your employer (if you work as a programmer) or school, 686 | if any, to sign a "copyright disclaimer" for the program, if necessary. 687 | For more information on this, and how to apply and follow the GNU GPL, see 688 | . 689 | 690 | The GNU General Public License does not permit incorporating your program 691 | into proprietary programs. If your program is a subroutine library, you 692 | may consider it more useful to permit linking proprietary applications with 693 | the library. If this is what you want to do, use the GNU Lesser General 694 | Public License instead of this License. But first, please read 695 | . 696 | {% elif cookiecutter.license == "Unlicense" %}This is free and unencumbered software released into the public domain. 697 | 698 | Anyone is free to copy, modify, publish, use, compile, sell, or 699 | distribute this software, either in source code form or as a compiled 700 | binary, for any purpose, commercial or non-commercial, and by any 701 | means. 702 | 703 | In jurisdictions that recognize copyright laws, the author or authors 704 | of this software dedicate any and all copyright interest in the 705 | software to the public domain. We make this dedication for the benefit 706 | of the public at large and to the detriment of our heirs and 707 | successors. We intend this dedication to be an overt act of 708 | relinquishment in perpetuity of all present and future rights to this 709 | software under copyright law. 710 | 711 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 712 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 713 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 714 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 715 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 716 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 717 | OTHER DEALINGS IN THE SOFTWARE. 718 | 719 | For more information, please refer to 720 | {% endif %} -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/README.md: -------------------------------------------------------------------------------- 1 | # {{cookiecutter.project_name}} 2 | 3 | This repo contains all the code of the website from https://{{cookiecutter.production_domain_url}} 4 | 5 | ### Development 6 | 7 | Uses the default Django development server. 8 | 9 | 1. Check that you have your .env.dev and .env.dev.db. If for some reason these files are not generated, remember that you can find samples in the repository. 10 | ```sh 11 | $ cat .env.dev 12 | 13 | DEBUG=1 14 | SECRET_KEY={{cookiecutter.secret_key}} 15 | DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] 16 | SQL_ENGINE=django.db.backends.postgresql 17 | SQL_DATABASE={{cookiecutter.postgresql_database}}_dev 18 | SQL_USER={{cookiecutter.postgresql_user}} 19 | SQL_PASSWORD={{cookiecutter.postgresql_password_dev}} 20 | SQL_HOST=db 21 | SQL_PORT=5432 22 | DATABASE=postgres 23 | 24 | $ cat .env.dev.db 25 | 26 | POSTGRES_USER={{cookiecutter.postgresql_user}} 27 | POSTGRES_PASSWORD={{cookiecutter.postgresql_password_dev}} 28 | POSTGRES_DB={{cookiecutter.postgresql_database}}_dev 29 | ``` 30 | 31 | 2. Create docker volumes to save the data: 32 | ```sh 33 | $ docker volume create --name={{cookiecutter.project_name}}_postgres_data_dev 34 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}$ docker volume create --name={{cookiecutter.project_name}}_grafana{% endif %} 35 | ``` 36 | 37 | 3. Build the images and run the containers: 38 | 39 | ```sh 40 | $ docker-compose up -d --build 41 | ``` 42 | 43 | Test it out at [http://localhost:8000](http://localhost:8000). The "app" folder is mounted into the container and your code changes apply automatically. 44 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}Grafana dashboard will be accesible in [http://localhost:3000](http://localhost:3000).{% endif %} 45 | 46 | 47 | ### Deploying to production 48 | 49 | You will have to configure the the Dockerhub account, the Github actions for the CI/CD, DNS and the production server: 50 | 51 | * **Dockerhub:** You must create an [access token](https://docs.docker.com/docker-hub/access-tokens/) to download the Docker images from the production server. Then you must create the following repositories in your Docker Hub account: 52 | * {{cookiecutter.project_name}} 53 | * {{cookiecutter.project_name}}-nginx 54 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 55 | * {{cookiecutter.project_name}}-prometheus 56 | * {{cookiecutter.project_name}}-grafana 57 | {% endif %} 58 | 59 | * **Production server:** For this example we will be using [Digital Ocean](https://www.digitalocean.com/). Digital Ocean provides with droplets with Docker pre-installed. For an easy installation, I really recommend you to use those droplets. ![image](https://user-images.githubusercontent.com/17761956/140977706-ac9abf8f-931d-41e1-9908-218879b4b2b2.png) 60 | To deploy, you must create a deploy SSH key in your local machine that is going to be used to stablish connection between the CI/CD service and your production server. The following command will create a **private** ssh key at **~/.ssh/id_deploy_rsa** and a **public** ssh key at **~/.ssh/id_deploy_rsa.pub** 61 | ```sh 62 | $ ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/id_deploy_rsa -N '' 63 | ``` 64 | To let Github actions deploy to your production server, you must add the **id_deploy_rsa.pub** in the **~/.ssh/authorized_keys** file inside the production server. 65 | 66 | ```sh 67 | $ echo "ssh-rsa AAAACEzaC1yc2E...GvaQ your_email@example.com" >> ~/.ssh/authorized_keys 68 | ``` 69 | 70 | * **Environment files:** Once the server is created, you must copy the .env files in the production server inside **/opt/{{cookiecutter.project_name}}** path. 71 | ```sh 72 | $ cat .env.prod 73 | $ cat .env.prod.db 74 | $ cat .env.prod.proxy-companion 75 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}$ cat .env.prod.grafana{% endif %} 76 | ``` 77 | 78 | * **Github actions:** You must enable Github actions in your Github repository and add the required secrets inside Github 79 | * Push this repository to Github. 80 | * Enable actions inside Repository > Settings > Actions > Actions permissions > Allow all actions. 81 | * Create the following secrets inside Repository > Settings > Secrets. 82 | * DOCKERHUB_USERNAME: Username of your Docker Hub. 83 | * DOCKERHUB_TOKEN: Access token generated previously in Docker Hub. 84 | * PRODUCTION_SERVER_USER: User used to connect to the production server via SSH. 85 | * PRODUCTION_SERVER_IP: Public IP of the production server. 86 | * SSH_PRIVATE_KEY: Generated deploy RSA private key (id_deploy_rsa). 87 | * SSH_PUBLIC_KEY: Generated deploy RSA public key (id_deploy_rsa.pub). 88 | 89 | * DNS: It's important that the DNS records are setup properly before deploying the app to the production server. You will need to make sure that you have the following records: 90 | * A: record to set the IPv4 of your production server 91 | * AAAA: record to set the IPv6 of your production server 92 | * CNAME: record to configure the "wwww" subdomain. 93 | ![Screenshot from 2021-07-11 19-28-45](https://user-images.githubusercontent.com/17761956/125204570-40738000-e27e-11eb-81a4-7a495949af73.png) 94 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 95 | 96 | # Configuring Grafana in production 97 | It will automatically load the provisioning configurations and serve the dashboard in [http://{{cookiecutter.production_domain_url}}:3000](http://{{cookiecutter.production_domain_url}}:3000). 98 | {% endif %} 99 | 100 | # Hints to work with this project 101 | 102 | 1. To execute a command inside the Django container in **DEVELOPMENT** environment. 103 | ```sh 104 | $ docker-compose exec web python manage.py shell 105 | ``` 106 | 2. To execute a command inside the Django container in **PRODUCTION** environment. 107 | ```sh 108 | $ docker-compose -f docker-compose.prod.yml exec web python manage.py shell 109 | ``` 110 | 3. To create Django migrations. In case you want to execute this in production environment, remember to use the -f parameter. 111 | ```sh 112 | $ docker-compose exec web python manage.py makemigrations 113 | ``` 114 | 4. To execute Django migrations. In case you want to execute this in production environment, remember to use the -f parameter. 115 | ```sh 116 | $ docker-compose exec web python manage.py migrate 117 | ``` 118 | 119 | 5. To create Django admin superuser. In case you want to execute this in production environment, remember to use the -f parameter. 120 | ```sh 121 | $ docker-compose exec web python manage.py createsuperuser 122 | ``` 123 | 6. To configure the debugger in Pycharm you can use guide in the following [link](https://testdriven.io/blog/django-debugging-pycharm/#:~:text=To%20do%20so%2C%20open%20PyCharm,create%20a%20new%20Docker%20configuration.). Remember that you must have a professional license to use this feature. 124 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/.gitignore: -------------------------------------------------------------------------------- 1 | db.sqlite3 2 | .DS_Store 3 | .idea 4 | *.pyc 5 | 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | bin/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | 29 | # Installer logs 30 | pip-log.txt 31 | pip-delete-this-directory.txt 32 | 33 | # Unit test / coverage reports 34 | .tox/ 35 | .coverage 36 | .cache 37 | nosetests.xml 38 | coverage.xml 39 | 40 | # Translations 41 | *.mo 42 | 43 | # Mr Developer 44 | .mr.developer.cfg 45 | .project 46 | .pydevproject 47 | 48 | # Rope 49 | .ropeproject 50 | 51 | # Django stuff: 52 | *.log 53 | *.pot 54 | mediafiles/ 55 | 56 | # Sphinx documentation 57 | docs/_build/ 58 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/Dockerfile: -------------------------------------------------------------------------------- 1 | # pull official base image 2 | FROM python:3.8.3-alpine 3 | 4 | # set work directory 5 | WORKDIR /usr/src/app 6 | 7 | # set environment variables 8 | ENV PYTHONDONTWRITEBYTECODE 1 9 | ENV PYTHONUNBUFFERED 1 10 | 11 | # install psycopg2 dependencies 12 | RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev 13 | 14 | # install Pillow dependencies 15 | RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl 16 | RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev 17 | 18 | # install dependencies 19 | RUN pip install --upgrade pip 20 | COPY ./requirements.txt . 21 | RUN pip install -r requirements.txt 22 | 23 | # copy entrypoint.sh 24 | COPY ./entrypoint.sh . 25 | 26 | # copy project 27 | COPY . . 28 | 29 | # run entrypoint.sh 30 | ENTRYPOINT ["/usr/src/app/entrypoint.sh"] 31 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/Dockerfile.prod: -------------------------------------------------------------------------------- 1 | # pull official base image 2 | FROM python:3.8.3-alpine 3 | 4 | # set work directory 5 | WORKDIR /usr/src/app 6 | 7 | # set environment variables 8 | ENV PYTHONDONTWRITEBYTECODE 1 9 | ENV PYTHONUNBUFFERED 1 10 | 11 | # install psycopg2 dependencies 12 | RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev 13 | 14 | # install Pillow dependencies 15 | RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl 16 | RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev 17 | 18 | # install dependencies 19 | RUN pip install --upgrade pip 20 | COPY ./requirements.txt . 21 | RUN pip install -r requirements.txt 22 | 23 | # create directory for the app user 24 | RUN mkdir -p /home/app 25 | 26 | # create the app user 27 | RUN addgroup -S app && adduser -S app -G app 28 | 29 | # create the appropriate directories 30 | ENV HOME=/home/app 31 | ENV APP_HOME=/home/app/web 32 | RUN mkdir $APP_HOME 33 | RUN mkdir $APP_HOME/staticfiles 34 | RUN mkdir $APP_HOME/mediafiles 35 | WORKDIR $APP_HOME 36 | 37 | # copy entrypoint-prod.sh 38 | COPY ./entrypoint.prod.sh $APP_HOME 39 | 40 | # copy project 41 | COPY . $APP_HOME 42 | 43 | # chown all the files to the app user 44 | RUN chown -R app:app $APP_HOME 45 | 46 | # change to the app user 47 | USER app 48 | 49 | # run entrypoint.prod.sh 50 | ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"] 51 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/entrypoint.prod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$DATABASE" = "postgres" ] 4 | then 5 | echo "Waiting for postgres..." 6 | 7 | while ! nc -z $SQL_HOST $SQL_PORT; do 8 | sleep 0.1 9 | done 10 | 11 | echo "PostgreSQL started" 12 | fi 13 | 14 | python manage.py collectstatic --no-input 15 | python manage.py migrate 16 | 17 | exec "$@" 18 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$DATABASE" = "postgres" ] 4 | then 5 | echo "Waiting for postgres..." 6 | 7 | while ! nc -z $SQL_HOST $SQL_PORT; do 8 | sleep 0.1 9 | done 10 | 11 | echo "PostgreSQL started" 12 | fi 13 | 14 | python manage.py migrate 15 | 16 | exec "$@" 17 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{cookiecutter.project_name}}.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/requirements.txt: -------------------------------------------------------------------------------- 1 | Django==4.1.2 2 | pytz==2022.4 3 | tzdata==2022.4 4 | django-admin-interface==0.22.0 5 | gunicorn==20.1.0 6 | Pillow==9.2.0 7 | psycopg2-binary==2.9.4 8 | {% if cookiecutter.add_sentry == 'yes' %}sentry-sdk==1.9.10{% endif %} 9 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}django-prometheus==2.2.0{% endif %} 10 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adriancast/django-template/09dbdb00770417ec729740b9e7f5a553b54beb52/{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/__init__.py -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for app project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{cookiecutter.project_name}}.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for app project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | import os 15 | {% if cookiecutter.add_sentry == 'yes' %} 16 | import sentry_sdk 17 | from sentry_sdk.integrations.django import DjangoIntegration 18 | {% endif %} 19 | 20 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 21 | BASE_DIR = Path(__file__).resolve().parent.parent 22 | 23 | 24 | # Quick-start development settings - unsuitable for production 25 | # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ 26 | 27 | # SECURITY WARNING: keep the secret key used in production secret! 28 | SECRET_KEY = os.environ.get("SECRET_KEY") 29 | 30 | # SECURITY WARNING: don't run with debug turned on in production! 31 | DEBUG = int(os.environ.get("DEBUG", default=0)) 32 | 33 | # HTTPS redirect 34 | SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") 35 | 36 | ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(",") 37 | 38 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 39 | # Required in order to use Prometheus 40 | ALLOWED_HOSTS += ['web'] 41 | 42 | {% endif %} 43 | # Application definition 44 | 45 | INSTALLED_APPS = [ 46 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}'django_prometheus',{% endif %} 47 | 'django.contrib.admin', 48 | 'django.contrib.auth', 49 | 'django.contrib.contenttypes', 50 | 'django.contrib.sessions', 51 | 'django.contrib.messages', 52 | 'django.contrib.staticfiles', 53 | ] 54 | 55 | MIDDLEWARE = [ 56 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}'django_prometheus.middleware.PrometheusBeforeMiddleware',{% endif %} 57 | 'django.middleware.security.SecurityMiddleware', 58 | 'django.contrib.sessions.middleware.SessionMiddleware', 59 | 'django.middleware.common.CommonMiddleware', 60 | 'django.middleware.csrf.CsrfViewMiddleware', 61 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 62 | 'django.contrib.messages.middleware.MessageMiddleware', 63 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 64 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}'django_prometheus.middleware.PrometheusAfterMiddleware',{% endif %} 65 | ] 66 | 67 | ROOT_URLCONF = '{{cookiecutter.project_name}}.urls' 68 | 69 | TEMPLATES = [ 70 | { 71 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 72 | 'DIRS': [], 73 | 'APP_DIRS': True, 74 | 'OPTIONS': { 75 | 'context_processors': [ 76 | 'django.template.context_processors.debug', 77 | 'django.template.context_processors.request', 78 | 'django.contrib.auth.context_processors.auth', 79 | 'django.contrib.messages.context_processors.messages', 80 | ], 81 | }, 82 | }, 83 | ] 84 | 85 | WSGI_APPLICATION = '{{cookiecutter.project_name}}.wsgi.application' 86 | 87 | 88 | # Database 89 | # https://docs.djangoproject.com/en/4.1/ref/settings/#databases 90 | 91 | DATABASES = { 92 | "default": { 93 | "ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"), 94 | "NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db.sqlite3")), 95 | "USER": os.environ.get("SQL_USER", "user"), 96 | "PASSWORD": os.environ.get("SQL_PASSWORD", "password"), 97 | "HOST": os.environ.get("SQL_HOST", "localhost"), 98 | "PORT": os.environ.get("SQL_PORT", "5432"), 99 | } 100 | } 101 | 102 | 103 | # Password validation 104 | # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators 105 | 106 | AUTH_PASSWORD_VALIDATORS = [ 107 | { 108 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 109 | }, 110 | { 111 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 112 | }, 113 | { 114 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 115 | }, 116 | { 117 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 118 | }, 119 | ] 120 | 121 | 122 | # Internationalization 123 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ 124 | 125 | LANGUAGE_CODE = 'en-us' 126 | 127 | TIME_ZONE = 'UTC' 128 | 129 | USE_I18N = True 130 | 131 | USE_L10N = True 132 | 133 | USE_TZ = True 134 | 135 | 136 | # Static files (CSS, JavaScript, Images) 137 | # https://docs.djangoproject.com/en/4.1/howto/static-files/ 138 | 139 | STATIC_URL = "/staticfiles/" 140 | STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") 141 | 142 | MEDIA_URL = "/mediafiles/" 143 | MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles") 144 | 145 | # Default primary key field type 146 | # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 147 | 148 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 149 | 150 | # Django admin interface settings 151 | INSTALLED_APPS = ['admin_interface', 'colorfield'] + INSTALLED_APPS 152 | X_FRAME_OPTIONS = 'SAMEORIGIN' 153 | 154 | {% if cookiecutter.add_sentry == 'yes' %}sentry_sdk.init( 155 | dsn='https://examplePublicKey@o0.ingest.sentry.io/0', # Update with your project DSN 156 | integrations=[DjangoIntegration()], 157 | 158 | # Set traces_sample_rate to 1.0 to capture 100% 159 | # of transactions for performance monitoring. 160 | # We recommend adjusting this value in production. 161 | traces_sample_rate=1.0, 162 | 163 | # If you wish to associate users to errors (assuming you are using 164 | # django.contrib.auth) you may enable sending PII data. 165 | send_default_pii=True 166 | ) 167 | {% endif %} -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/urls.py: -------------------------------------------------------------------------------- 1 | """app URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}from django.urls import include{% endif %} 19 | from django.conf.urls.static import static 20 | from django.conf import settings 21 | 22 | urlpatterns = [ 23 | path('admin/', admin.site.urls), 24 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %}path('prometheus/', include('django_prometheus.urls')),{% endif %} 25 | ] 26 | 27 | if settings.DEBUG: 28 | # When you are using the dev docker-compose, you need to serve the media files somehow 29 | urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns 30 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/app/{{cookiecutter.project_name}}/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for app project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{cookiecutter.project_name}}.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/docker-compose.prod.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | web: 5 | image: {{cookiecutter.dockerhub_account}}/{{cookiecutter.project_name}}:latest 6 | command: gunicorn {{cookiecutter.project_name}}.wsgi:application --bind 0.0.0.0:8000 7 | volumes: 8 | - static_volume:/home/app/web/staticfiles 9 | - media_volume:/home/app/web/mediafiles 10 | expose: 11 | - 8000 12 | env_file: 13 | - .env.prod 14 | depends_on: 15 | - db 16 | db: 17 | image: postgres:12.0-alpine 18 | volumes: 19 | - {{cookiecutter.project_name}}_postgres_data:/var/lib/postgresql/data/ 20 | env_file: 21 | - .env.prod.db 22 | nginx-proxy: 23 | container_name: nginx-proxy 24 | image: {{cookiecutter.dockerhub_account}}/{{cookiecutter.project_name}}-nginx:latest 25 | restart: always 26 | ports: 27 | - 443:443 28 | - 80:80 29 | volumes: 30 | - static_volume:/home/app/web/staticfiles 31 | - media_volume:/home/app/web/mediafiles 32 | - certs:/etc/nginx/certs 33 | - html:/usr/share/nginx/html 34 | - vhost:/etc/nginx/vhost.d 35 | - /var/run/docker.sock:/tmp/docker.sock:ro 36 | depends_on: 37 | - web 38 | nginx-proxy-letsencrypt: 39 | image: jrcs/letsencrypt-nginx-proxy-companion 40 | env_file: 41 | - .env.prod.proxy-companion 42 | volumes: 43 | - /var/run/docker.sock:/var/run/docker.sock:ro 44 | - certs:/etc/nginx/certs 45 | - html:/usr/share/nginx/html 46 | - vhost:/etc/nginx/vhost.d 47 | depends_on: 48 | - nginx-proxy 49 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 50 | prometheus: 51 | image: {{cookiecutter.dockerhub_account}}/{{cookiecutter.project_name}}-prometheus:latest 52 | restart: always 53 | 54 | grafana: 55 | image: {{cookiecutter.dockerhub_account}}/{{cookiecutter.project_name}}-grafana:latest 56 | restart: always 57 | volumes: 58 | - {{cookiecutter.project_name}}_grafana:/var/lib/grafana 59 | ports: 60 | - 3000:3000 61 | depends_on: 62 | - prometheus 63 | env_file: 64 | - .env.prod.grafana 65 | {% endif %} 66 | volumes: 67 | {{cookiecutter.project_name}}_postgres_data: 68 | external: true 69 | static_volume: 70 | external: true 71 | media_volume: 72 | external: true 73 | certs: 74 | external: true 75 | html: 76 | external: true 77 | vhost: 78 | external: true 79 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 80 | {{cookiecutter.project_name}}_grafana: 81 | external: true 82 | {% endif %} 83 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | web: 5 | build: ./app 6 | command: python manage.py runserver 0.0.0.0:8000 7 | volumes: 8 | - ./app/:/usr/src/app/ 9 | ports: 10 | - 8000:8000 11 | env_file: 12 | - ./.env.dev 13 | depends_on: 14 | - db 15 | db: 16 | image: postgres:12.0-alpine 17 | volumes: 18 | - {{cookiecutter.project_name}}_postgres_data_dev:/var/lib/postgresql/data/ 19 | env_file: 20 | - ./.env.dev.db 21 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 22 | prometheus: 23 | image: prometheus:latest 24 | restart: always 25 | ports: 26 | - 9090:9090 27 | build: 28 | context: prometheus 29 | dockerfile: Dockerfile 30 | 31 | grafana: 32 | image: grafana/grafana:8.0.4 33 | restart: always 34 | volumes: 35 | - {{cookiecutter.project_name}}_grafana:/var/lib/grafana 36 | - ./grafana/provisioning/:/etc/grafana/provisioning/ 37 | ports: 38 | - 3000:3000 39 | depends_on: 40 | - prometheus 41 | environment: 42 | - GF_SECURITY_ADMIN_USER=admin 43 | - GF_SECURITY_ADMIN_PASSWORD=admin 44 | {% endif %} 45 | volumes: 46 | {{cookiecutter.project_name}}_postgres_data_dev: 47 | external: true 48 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 49 | {{cookiecutter.project_name}}_grafana: 50 | external: true 51 | {% endif %} -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/grafana/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM grafana/grafana:8.0.4 2 | 3 | ADD ./provisioning/ /etc/grafana/provisioning/ 4 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/grafana/provisioning/dashboards/dashboard.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: 'Prometheus' 5 | orgId: 1 6 | folder: '' 7 | type: file 8 | disableDeletion: false 9 | editable: true 10 | options: 11 | path: /etc/grafana/provisioning/dashboards -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/grafana/provisioning/dashboards/django.json: -------------------------------------------------------------------------------- 1 | {% raw %}{ 2 | "__inputs": [], 3 | "__requires": [ 4 | { 5 | "type": "grafana", 6 | "id": "grafana", 7 | "name": "Grafana", 8 | "version": "5.3.4" 9 | }, 10 | { 11 | "type": "panel", 12 | "id": "graph", 13 | "name": "Graph", 14 | "version": "5.0.0" 15 | }, 16 | { 17 | "type": "datasource", 18 | "id": "prometheus", 19 | "name": "Prometheus", 20 | "version": "5.0.0" 21 | }, 22 | { 23 | "type": "panel", 24 | "id": "singlestat", 25 | "name": "Singlestat", 26 | "version": "5.0.0" 27 | } 28 | ], 29 | "annotations": { 30 | "list": [ 31 | { 32 | "builtIn": 1, 33 | "datasource": "-- Grafana --", 34 | "enable": true, 35 | "hide": true, 36 | "iconColor": "rgba(0, 211, 255, 1)", 37 | "name": "Annotations & Alerts", 38 | "type": "dashboard" 39 | } 40 | ] 41 | }, 42 | "description": "Django metrics dashboard using korfuri/django-prometheus Prometheus metrics exporter", 43 | "editable": true, 44 | "gnetId": 9528, 45 | "graphTooltip": 0, 46 | "id": null, 47 | "iteration": 1544716165397, 48 | "links": [], 49 | "panels": [ 50 | { 51 | "cacheTimeout": null, 52 | "colorBackground": false, 53 | "colorValue": false, 54 | "colors": [ 55 | "#299c46", 56 | "rgba(237, 129, 40, 0.89)", 57 | "#d44a3a" 58 | ], 59 | "datasource": "$datasource", 60 | "description": "increase(v range-vector) calculates the increase in the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. The increase is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if a counter increases only by integer increments.", 61 | "format": "none", 62 | "gauge": { 63 | "maxValue": 100, 64 | "minValue": 0, 65 | "show": false, 66 | "thresholdLabels": false, 67 | "thresholdMarkers": true 68 | }, 69 | "gridPos": { 70 | "h": 2, 71 | "w": 12, 72 | "x": 0, 73 | "y": 0 74 | }, 75 | "id": 13, 76 | "interval": null, 77 | "links": [], 78 | "mappingType": 1, 79 | "mappingTypes": [ 80 | { 81 | "name": "value to text", 82 | "value": 1 83 | }, 84 | { 85 | "name": "range to text", 86 | "value": 2 87 | } 88 | ], 89 | "maxDataPoints": 100, 90 | "nullPointMode": "connected", 91 | "nullText": null, 92 | "postfix": "", 93 | "postfixFontSize": "50%", 94 | "prefix": "", 95 | "prefixFontSize": "50%", 96 | "rangeMaps": [ 97 | { 98 | "from": "null", 99 | "text": "N/A", 100 | "to": "null" 101 | } 102 | ], 103 | "sparkline": { 104 | "fillColor": "rgba(31, 118, 189, 0.18)", 105 | "full": false, 106 | "lineColor": "rgb(31, 120, 193)", 107 | "show": false 108 | }, 109 | "tableColumn": "", 110 | "targets": [ 111 | { 112 | "expr": "sum(irate(django_http_requests_total_by_transport_total{namespace=~\"$namespace\", app=~\"^$app$\"}[1m]))", 113 | "format": "time_series", 114 | "intervalFactor": 1, 115 | "refId": "A" 116 | } 117 | ], 118 | "thresholds": "", 119 | "title": "Total Requests", 120 | "type": "singlestat", 121 | "valueFontSize": "80%", 122 | "valueMaps": [ 123 | { 124 | "op": "=", 125 | "text": "N/A", 126 | "value": "null" 127 | } 128 | ], 129 | "valueName": "avg" 130 | }, 131 | { 132 | "cacheTimeout": null, 133 | "colorBackground": false, 134 | "colorValue": false, 135 | "colors": [ 136 | "#629e51", 137 | "rgba(237, 129, 40, 0.89)", 138 | "#d44a3a" 139 | ], 140 | "datasource": "$datasource", 141 | "format": "none", 142 | "gauge": { 143 | "maxValue": 100, 144 | "minValue": 0, 145 | "show": false, 146 | "thresholdLabels": false, 147 | "thresholdMarkers": true 148 | }, 149 | "gridPos": { 150 | "h": 2, 151 | "w": 4, 152 | "x": 12, 153 | "y": 0 154 | }, 155 | "id": 15, 156 | "interval": null, 157 | "links": [], 158 | "mappingType": 1, 159 | "mappingTypes": [ 160 | { 161 | "name": "value to text", 162 | "value": 1 163 | }, 164 | { 165 | "name": "range to text", 166 | "value": 2 167 | } 168 | ], 169 | "maxDataPoints": 100, 170 | "nullPointMode": "connected", 171 | "nullText": null, 172 | "postfix": "", 173 | "postfixFontSize": "50%", 174 | "prefix": "", 175 | "prefixFontSize": "50%", 176 | "rangeMaps": [ 177 | { 178 | "from": "null", 179 | "text": "N/A", 180 | "to": "null" 181 | } 182 | ], 183 | "sparkline": { 184 | "fillColor": "rgba(31, 118, 189, 0.18)", 185 | "full": false, 186 | "lineColor": "rgb(31, 120, 193)", 187 | "show": false 188 | }, 189 | "tableColumn": "", 190 | "targets": [ 191 | { 192 | "expr": "sum(irate(django_http_responses_total_by_status_total{status=~\"2.+\",namespace=~\"$namespace\", app=~\"^$app$\"}[1m]))", 193 | "format": "time_series", 194 | "intervalFactor": 1, 195 | "legendFormat": "", 196 | "refId": "A" 197 | } 198 | ], 199 | "thresholds": "", 200 | "title": "2XX Responses", 201 | "type": "singlestat", 202 | "valueFontSize": "80%", 203 | "valueMaps": [ 204 | { 205 | "op": "=", 206 | "text": "N/A", 207 | "value": "null" 208 | } 209 | ], 210 | "valueName": "avg" 211 | }, 212 | { 213 | "cacheTimeout": null, 214 | "colorBackground": false, 215 | "colorValue": false, 216 | "colors": [ 217 | "#299c46", 218 | "rgba(237, 129, 40, 0.89)", 219 | "#d44a3a" 220 | ], 221 | "datasource": "$datasource", 222 | "format": "none", 223 | "gauge": { 224 | "maxValue": 100, 225 | "minValue": 0, 226 | "show": false, 227 | "thresholdLabels": false, 228 | "thresholdMarkers": true 229 | }, 230 | "gridPos": { 231 | "h": 2, 232 | "w": 4, 233 | "x": 16, 234 | "y": 0 235 | }, 236 | "id": 16, 237 | "interval": null, 238 | "links": [], 239 | "mappingType": 1, 240 | "mappingTypes": [ 241 | { 242 | "name": "value to text", 243 | "value": 1 244 | }, 245 | { 246 | "name": "range to text", 247 | "value": 2 248 | } 249 | ], 250 | "maxDataPoints": 100, 251 | "nullPointMode": "connected", 252 | "nullText": null, 253 | "postfix": "", 254 | "postfixFontSize": "50%", 255 | "prefix": "", 256 | "prefixFontSize": "50%", 257 | "rangeMaps": [ 258 | { 259 | "from": "null", 260 | "text": "N/A", 261 | "to": "null" 262 | } 263 | ], 264 | "sparkline": { 265 | "fillColor": "rgba(31, 118, 189, 0.18)", 266 | "full": false, 267 | "lineColor": "rgb(31, 120, 193)", 268 | "show": false 269 | }, 270 | "tableColumn": "", 271 | "targets": [ 272 | { 273 | "expr": "sum(irate(django_http_responses_total_by_status_total{status=~\"4.+\",namespace=~\"$namespace\", app=~\"^$app$\"}[1m]))", 274 | "format": "time_series", 275 | "intervalFactor": 1, 276 | "legendFormat": "", 277 | "refId": "A" 278 | } 279 | ], 280 | "thresholds": "", 281 | "title": "4XX Responses", 282 | "type": "singlestat", 283 | "valueFontSize": "80%", 284 | "valueMaps": [ 285 | { 286 | "op": "=", 287 | "text": "N/A", 288 | "value": "null" 289 | } 290 | ], 291 | "valueName": "avg" 292 | }, 293 | { 294 | "cacheTimeout": null, 295 | "colorBackground": false, 296 | "colorValue": false, 297 | "colors": [ 298 | "#299c46", 299 | "rgba(237, 129, 40, 0.89)", 300 | "#d44a3a" 301 | ], 302 | "datasource": "$datasource", 303 | "format": "none", 304 | "gauge": { 305 | "maxValue": 100, 306 | "minValue": 0, 307 | "show": false, 308 | "thresholdLabels": false, 309 | "thresholdMarkers": true 310 | }, 311 | "gridPos": { 312 | "h": 2, 313 | "w": 4, 314 | "x": 20, 315 | "y": 0 316 | }, 317 | "id": 17, 318 | "interval": null, 319 | "links": [], 320 | "mappingType": 1, 321 | "mappingTypes": [ 322 | { 323 | "name": "value to text", 324 | "value": 1 325 | }, 326 | { 327 | "name": "range to text", 328 | "value": 2 329 | } 330 | ], 331 | "maxDataPoints": 100, 332 | "nullPointMode": "connected", 333 | "nullText": null, 334 | "postfix": "", 335 | "postfixFontSize": "50%", 336 | "prefix": "", 337 | "prefixFontSize": "50%", 338 | "rangeMaps": [ 339 | { 340 | "from": "null", 341 | "text": "N/A", 342 | "to": "null" 343 | } 344 | ], 345 | "sparkline": { 346 | "fillColor": "rgba(31, 118, 189, 0.18)", 347 | "full": false, 348 | "lineColor": "rgb(31, 120, 193)", 349 | "show": false 350 | }, 351 | "tableColumn": "", 352 | "targets": [ 353 | { 354 | "expr": "sum(irate(django_http_responses_total_by_status_total{status=~\"5.+\",namespace=~\"$namespace\", app=~\"^$app$\"}[1m]))", 355 | "format": "time_series", 356 | "intervalFactor": 1, 357 | "legendFormat": "", 358 | "refId": "A" 359 | } 360 | ], 361 | "thresholds": "", 362 | "title": "5XX Responses", 363 | "type": "singlestat", 364 | "valueFontSize": "80%", 365 | "valueMaps": [ 366 | { 367 | "op": "=", 368 | "text": "N/A", 369 | "value": "null" 370 | } 371 | ], 372 | "valueName": "avg" 373 | }, 374 | { 375 | "aliasColors": {}, 376 | "bars": false, 377 | "dashLength": 10, 378 | "dashes": false, 379 | "datasource": "$datasource", 380 | "fill": 1, 381 | "gridPos": { 382 | "h": 9, 383 | "w": 12, 384 | "x": 0, 385 | "y": 2 386 | }, 387 | "id": 2, 388 | "legend": { 389 | "avg": false, 390 | "current": false, 391 | "max": false, 392 | "min": false, 393 | "show": true, 394 | "total": false, 395 | "values": false 396 | }, 397 | "lines": true, 398 | "linewidth": 1, 399 | "links": [], 400 | "nullPointMode": "null", 401 | "percentage": false, 402 | "pointradius": 5, 403 | "points": false, 404 | "renderer": "flot", 405 | "seriesOverrides": [], 406 | "spaceLength": 10, 407 | "stack": false, 408 | "steppedLine": false, 409 | "targets": [ 410 | { 411 | "expr": "sum(irate(django_http_requests_total_by_view_transport_method_total{namespace=~\"$namespace\", app=~\"^$app$\",view!~\"prometheus-django-metrics|healthcheck\"}[1m])) by(method, view)", 412 | "format": "time_series", 413 | "hide": false, 414 | "intervalFactor": 1, 415 | "legendFormat": "{{method}} /{{view}}", 416 | "refId": "A" 417 | } 418 | ], 419 | "thresholds": [], 420 | "timeFrom": null, 421 | "timeShift": null, 422 | "title": "Requests", 423 | "tooltip": { 424 | "shared": true, 425 | "sort": 0, 426 | "value_type": "individual" 427 | }, 428 | "type": "graph", 429 | "xaxis": { 430 | "buckets": null, 431 | "mode": "time", 432 | "name": null, 433 | "show": true, 434 | "values": [] 435 | }, 436 | "yaxes": [ 437 | { 438 | "format": "short", 439 | "label": null, 440 | "logBase": 1, 441 | "max": null, 442 | "min": null, 443 | "show": true 444 | }, 445 | { 446 | "format": "short", 447 | "label": null, 448 | "logBase": 1, 449 | "max": null, 450 | "min": null, 451 | "show": true 452 | } 453 | ], 454 | "yaxis": { 455 | "align": false, 456 | "alignLevel": null 457 | } 458 | }, 459 | { 460 | "aliasColors": {}, 461 | "bars": false, 462 | "dashLength": 10, 463 | "dashes": false, 464 | "datasource": "$datasource", 465 | "fill": 1, 466 | "gridPos": { 467 | "h": 9, 468 | "w": 12, 469 | "x": 12, 470 | "y": 2 471 | }, 472 | "id": 4, 473 | "legend": { 474 | "avg": false, 475 | "current": false, 476 | "max": false, 477 | "min": false, 478 | "show": true, 479 | "total": false, 480 | "values": false 481 | }, 482 | "lines": true, 483 | "linewidth": 1, 484 | "links": [], 485 | "nullPointMode": "null", 486 | "percentage": false, 487 | "pointradius": 5, 488 | "points": false, 489 | "renderer": "flot", 490 | "seriesOverrides": [], 491 | "spaceLength": 10, 492 | "stack": false, 493 | "steppedLine": false, 494 | "targets": [ 495 | { 496 | "expr": "histogram_quantile(0.50, sum(rate(django_http_requests_latency_seconds_by_view_method_bucket{namespace=~\"$namespace\", app=~\"^$app$\",view!~\"prometheus-django-metrics|healthcheck\"}[5m])) by (job, le))", 497 | "format": "time_series", 498 | "interval": "", 499 | "intervalFactor": 1, 500 | "legendFormat": "quantile=50", 501 | "refId": "A" 502 | }, 503 | { 504 | "expr": "histogram_quantile(0.95, sum(rate(django_http_requests_latency_seconds_by_view_method_bucket{namespace=~\"$namespace\", app=~\"^$app$\",view!~\"prometheus-django-metrics|healthcheck\"}[5m])) by (job, le))", 505 | "format": "time_series", 506 | "hide": false, 507 | "interval": "", 508 | "intervalFactor": 1, 509 | "legendFormat": "quantile=95", 510 | "refId": "B" 511 | }, 512 | { 513 | "expr": "histogram_quantile(0.99, sum(rate(django_http_requests_latency_seconds_by_view_method_bucket{namespace=~\"$namespace\", app=~\"^$app$\",view!~\"prometheus-django-metrics|healthcheck\"}[5m])) by (job, le))", 514 | "format": "time_series", 515 | "hide": false, 516 | "interval": "", 517 | "intervalFactor": 1, 518 | "legendFormat": "quantile=99", 519 | "refId": "C" 520 | }, 521 | { 522 | "expr": "histogram_quantile(0.999, sum(rate(django_http_requests_latency_seconds_by_view_method_bucket{namespace=~\"$namespace\", app=~\"^$app$\",view!~\"prometheus-django-metrics|healthcheck\"}[5m])) by (job, le))", 523 | "format": "time_series", 524 | "hide": false, 525 | "interval": "", 526 | "intervalFactor": 1, 527 | "legendFormat": "quantile=99.9", 528 | "refId": "D" 529 | } 530 | ], 531 | "thresholds": [], 532 | "timeFrom": null, 533 | "timeShift": null, 534 | "title": "Request Latency", 535 | "tooltip": { 536 | "shared": true, 537 | "sort": 0, 538 | "value_type": "individual" 539 | }, 540 | "type": "graph", 541 | "xaxis": { 542 | "buckets": null, 543 | "mode": "time", 544 | "name": null, 545 | "show": true, 546 | "values": [] 547 | }, 548 | "yaxes": [ 549 | { 550 | "format": "dtdurations", 551 | "label": "", 552 | "logBase": 1, 553 | "max": null, 554 | "min": null, 555 | "show": true 556 | }, 557 | { 558 | "format": "short", 559 | "label": null, 560 | "logBase": 1, 561 | "max": null, 562 | "min": null, 563 | "show": true 564 | } 565 | ], 566 | "yaxis": { 567 | "align": false, 568 | "alignLevel": null 569 | } 570 | }, 571 | { 572 | "aliasColors": { 573 | "api-beatstream-api": "#1f78c1" 574 | }, 575 | "bars": false, 576 | "dashLength": 10, 577 | "dashes": false, 578 | "datasource": "$datasource", 579 | "fill": 1, 580 | "gridPos": { 581 | "h": 9, 582 | "w": 12, 583 | "x": 0, 584 | "y": 11 585 | }, 586 | "id": 7, 587 | "legend": { 588 | "avg": false, 589 | "current": false, 590 | "max": false, 591 | "min": false, 592 | "show": true, 593 | "total": false, 594 | "values": false 595 | }, 596 | "lines": true, 597 | "linewidth": 1, 598 | "links": [], 599 | "nullPointMode": "null", 600 | "percentage": false, 601 | "pointradius": 5, 602 | "points": false, 603 | "renderer": "flot", 604 | "seriesOverrides": [ 605 | {} 606 | ], 607 | "spaceLength": 10, 608 | "stack": false, 609 | "steppedLine": false, 610 | "targets": [ 611 | { 612 | "expr": "sum(irate(django_http_responses_before_middlewares_total{namespace=~\"$namespace\", app=~\"^$app$\", view!~\"prometheus-django-metrics|healthcheck\"}[1m])) by(job)", 613 | "format": "time_series", 614 | "interval": "", 615 | "intervalFactor": 1, 616 | "legendFormat": "{{job}}", 617 | "refId": "A" 618 | } 619 | ], 620 | "thresholds": [], 621 | "timeFrom": null, 622 | "timeShift": null, 623 | "title": "Responses", 624 | "tooltip": { 625 | "shared": true, 626 | "sort": 0, 627 | "value_type": "individual" 628 | }, 629 | "type": "graph", 630 | "xaxis": { 631 | "buckets": null, 632 | "mode": "time", 633 | "name": null, 634 | "show": true, 635 | "values": [] 636 | }, 637 | "yaxes": [ 638 | { 639 | "format": "short", 640 | "label": null, 641 | "logBase": 1, 642 | "max": null, 643 | "min": null, 644 | "show": true 645 | }, 646 | { 647 | "format": "short", 648 | "label": null, 649 | "logBase": 1, 650 | "max": null, 651 | "min": null, 652 | "show": true 653 | } 654 | ], 655 | "yaxis": { 656 | "align": false, 657 | "alignLevel": null 658 | } 659 | }, 660 | { 661 | "aliasColors": {}, 662 | "bars": false, 663 | "dashLength": 10, 664 | "dashes": false, 665 | "datasource": "$datasource", 666 | "fill": 1, 667 | "gridPos": { 668 | "h": 9, 669 | "w": 12, 670 | "x": 12, 671 | "y": 11 672 | }, 673 | "id": 11, 674 | "legend": { 675 | "avg": false, 676 | "current": false, 677 | "max": false, 678 | "min": false, 679 | "show": true, 680 | "total": false, 681 | "values": false 682 | }, 683 | "lines": true, 684 | "linewidth": 1, 685 | "links": [], 686 | "nullPointMode": "null", 687 | "percentage": false, 688 | "pointradius": 5, 689 | "points": false, 690 | "renderer": "flot", 691 | "seriesOverrides": [], 692 | "spaceLength": 10, 693 | "stack": false, 694 | "steppedLine": false, 695 | "targets": [ 696 | { 697 | "expr": "sum(irate(django_http_responses_total_by_status_total{namespace=~\"$namespace\", app=~\"^$app$\", view!~\"prometheus-django-metrics|healthcheck\"}[1m])) by(status)", 698 | "format": "time_series", 699 | "intervalFactor": 1, 700 | "legendFormat": "{{status}}", 701 | "refId": "A" 702 | } 703 | ], 704 | "thresholds": [], 705 | "timeFrom": null, 706 | "timeShift": null, 707 | "title": "Response Status", 708 | "tooltip": { 709 | "shared": true, 710 | "sort": 0, 711 | "value_type": "individual" 712 | }, 713 | "type": "graph", 714 | "xaxis": { 715 | "buckets": null, 716 | "mode": "time", 717 | "name": null, 718 | "show": true, 719 | "values": [] 720 | }, 721 | "yaxes": [ 722 | { 723 | "format": "short", 724 | "label": null, 725 | "logBase": 1, 726 | "max": null, 727 | "min": null, 728 | "show": true 729 | }, 730 | { 731 | "format": "short", 732 | "label": null, 733 | "logBase": 1, 734 | "max": null, 735 | "min": null, 736 | "show": true 737 | } 738 | ], 739 | "yaxis": { 740 | "align": false, 741 | "alignLevel": null 742 | } 743 | }, 744 | { 745 | "aliasColors": { 746 | "mysql": "#584477", 747 | "postgresql": "#0064a5" 748 | }, 749 | "bars": false, 750 | "dashLength": 10, 751 | "dashes": false, 752 | "datasource": "$datasource", 753 | "fill": 1, 754 | "gridPos": { 755 | "h": 5, 756 | "w": 24, 757 | "x": 0, 758 | "y": 20 759 | }, 760 | "id": 9, 761 | "legend": { 762 | "avg": false, 763 | "current": false, 764 | "max": false, 765 | "min": false, 766 | "show": true, 767 | "total": false, 768 | "values": false 769 | }, 770 | "lines": true, 771 | "linewidth": 1, 772 | "links": [], 773 | "nullPointMode": "null", 774 | "percentage": false, 775 | "pointradius": 5, 776 | "points": false, 777 | "renderer": "flot", 778 | "seriesOverrides": [], 779 | "spaceLength": 10, 780 | "stack": false, 781 | "steppedLine": false, 782 | "targets": [ 783 | { 784 | "expr": "sum(irate(django_db_execute_total{namespace=~\"$namespace\", app=~\"^$app$\"}[1m])) by (vendor)", 785 | "format": "time_series", 786 | "intervalFactor": 1, 787 | "legendFormat": "{{vendor}}", 788 | "refId": "A" 789 | } 790 | ], 791 | "thresholds": [], 792 | "timeFrom": null, 793 | "timeShift": null, 794 | "title": "Database Ops", 795 | "tooltip": { 796 | "shared": true, 797 | "sort": 0, 798 | "value_type": "individual" 799 | }, 800 | "type": "graph", 801 | "xaxis": { 802 | "buckets": null, 803 | "mode": "time", 804 | "name": null, 805 | "show": true, 806 | "values": [] 807 | }, 808 | "yaxes": [ 809 | { 810 | "format": "short", 811 | "label": null, 812 | "logBase": 1, 813 | "max": null, 814 | "min": null, 815 | "show": true 816 | }, 817 | { 818 | "format": "short", 819 | "label": null, 820 | "logBase": 1, 821 | "max": null, 822 | "min": null, 823 | "show": true 824 | } 825 | ], 826 | "yaxis": { 827 | "align": false, 828 | "alignLevel": null 829 | } 830 | }, 831 | { 832 | "aliasColors": {}, 833 | "bars": false, 834 | "dashLength": 10, 835 | "dashes": false, 836 | "datasource": "$datasource", 837 | "fill": 1, 838 | "gridPos": { 839 | "h": 5, 840 | "w": 24, 841 | "x": 0, 842 | "y": 25 843 | }, 844 | "id": 18, 845 | "legend": { 846 | "alignAsTable": true, 847 | "avg": true, 848 | "current": true, 849 | "hideEmpty": false, 850 | "hideZero": true, 851 | "max": true, 852 | "min": false, 853 | "rightSide": true, 854 | "show": true, 855 | "total": false, 856 | "values": true 857 | }, 858 | "lines": true, 859 | "linewidth": 1, 860 | "links": [], 861 | "nullPointMode": "null", 862 | "percentage": false, 863 | "pointradius": 5, 864 | "points": false, 865 | "renderer": "flot", 866 | "seriesOverrides": [], 867 | "spaceLength": 10, 868 | "stack": false, 869 | "steppedLine": false, 870 | "targets": [ 871 | { 872 | "expr": "sum(irate(django_model_deletes_total{namespace=~\"$namespace\", app=~\"^$app$\"}[1m])) by (model)", 873 | "format": "time_series", 874 | "intervalFactor": 1, 875 | "legendFormat": "[{{model}}] deletes", 876 | "refId": "A" 877 | }, 878 | { 879 | "expr": "sum(irate(django_model_inserts_total{namespace=~\"$namespace\", app=~\"^$app$\"}[1m])) by (model)", 880 | "format": "time_series", 881 | "intervalFactor": 1, 882 | "legendFormat": "[{{model}}] inserts", 883 | "refId": "B" 884 | }, 885 | { 886 | "expr": "sum(irate(django_model_updates_total{namespace=~\"$namespace\", app=~\"^$app$\"}[1m])) by (model)", 887 | "format": "time_series", 888 | "intervalFactor": 1, 889 | "legendFormat": "[{{model}}] updates", 890 | "refId": "C" 891 | } 892 | ], 893 | "thresholds": [], 894 | "timeFrom": null, 895 | "timeShift": null, 896 | "title": "Models stats", 897 | "tooltip": { 898 | "shared": true, 899 | "sort": 0, 900 | "value_type": "individual" 901 | }, 902 | "type": "graph", 903 | "xaxis": { 904 | "buckets": null, 905 | "mode": "time", 906 | "name": null, 907 | "show": true, 908 | "values": [] 909 | }, 910 | "yaxes": [ 911 | { 912 | "format": "short", 913 | "label": null, 914 | "logBase": 1, 915 | "max": null, 916 | "min": null, 917 | "show": true 918 | }, 919 | { 920 | "format": "short", 921 | "label": null, 922 | "logBase": 1, 923 | "max": null, 924 | "min": null, 925 | "show": true 926 | } 927 | ], 928 | "yaxis": { 929 | "align": false, 930 | "alignLevel": null 931 | } 932 | } 933 | ], 934 | "refresh": "10s", 935 | "schemaVersion": 16, 936 | "style": "dark", 937 | "tags": [], 938 | "templating": { 939 | "list": [ 940 | { 941 | "current": { 942 | "text": "Prometheus", 943 | "value": "Prometheus" 944 | }, 945 | "hide": 0, 946 | "label": null, 947 | "name": "datasource", 948 | "options": [], 949 | "query": "prometheus", 950 | "refresh": 1, 951 | "regex": "", 952 | "skipUrlSync": false, 953 | "type": "datasource" 954 | }, 955 | { 956 | "allValue": ".*", 957 | "current": {}, 958 | "datasource": "$datasource", 959 | "hide": 0, 960 | "includeAll": false, 961 | "label": "", 962 | "multi": false, 963 | "name": "namespace", 964 | "options": [], 965 | "query": "label_values(django_db_new_connections_total, namespace)", 966 | "refresh": 1, 967 | "regex": "", 968 | "skipUrlSync": false, 969 | "sort": 1, 970 | "tagValuesQuery": "", 971 | "tags": [], 972 | "tagsQuery": "", 973 | "type": "query", 974 | "useTags": false 975 | }, 976 | { 977 | "allValue": null, 978 | "current": {}, 979 | "datasource": "$datasource", 980 | "hide": 0, 981 | "includeAll": true, 982 | "label": "app", 983 | "multi": false, 984 | "name": "app", 985 | "options": [], 986 | "query": "label_values(django_db_new_connections_total{namespace=~\"$namespace\"}, app)", 987 | "refresh": 1, 988 | "regex": "", 989 | "skipUrlSync": false, 990 | "sort": 0, 991 | "tagValuesQuery": "", 992 | "tags": [], 993 | "tagsQuery": "", 994 | "type": "query", 995 | "useTags": false 996 | } 997 | ] 998 | }, 999 | "time": { 1000 | "from": "now-15m", 1001 | "to": "now" 1002 | }, 1003 | "timepicker": { 1004 | "refresh_intervals": [ 1005 | "5s", 1006 | "10s", 1007 | "30s", 1008 | "1m", 1009 | "5m", 1010 | "15m", 1011 | "30m", 1012 | "1h", 1013 | "2h", 1014 | "1d" 1015 | ], 1016 | "time_options": [ 1017 | "5m", 1018 | "15m", 1019 | "1h", 1020 | "6h", 1021 | "12h", 1022 | "24h", 1023 | "2d", 1024 | "7d", 1025 | "30d" 1026 | ] 1027 | }, 1028 | "timezone": "", 1029 | "title": "Django", 1030 | "uid": "O6v4rMpizda", 1031 | "version": 1 1032 | }{% endraw %} -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/grafana/provisioning/datasources/prometheus.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | datasources: 4 | - name: Prometheus 5 | type: prometheus 6 | access: proxy 7 | url: http://prometheus:9090 8 | isDefault: true 9 | editable: false -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jwilder/nginx-proxy 2 | COPY vhost.d/default /etc/nginx/vhost.d/default 3 | COPY custom.conf /etc/nginx/conf.d/custom.conf 4 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/nginx/custom.conf: -------------------------------------------------------------------------------- 1 | client_max_body_size 10M; 2 | -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/nginx/vhost.d/default: -------------------------------------------------------------------------------- 1 | location /staticfiles/ { 2 | alias /home/app/web/staticfiles/; 3 | add_header Access-Control-Allow-Origin *; 4 | } 5 | 6 | location /mediafiles/ { 7 | alias /home/app/web/mediafiles/; 8 | add_header Access-Control-Allow-Origin *; 9 | } 10 | {% if cookiecutter.add_prometheus_and_grafana == 'yes' %} 11 | location /prometheus/metrics { 12 | deny all; 13 | return 403; 14 | } 15 | {% endif %} -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/prometheus/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM prom/prometheus:v2.14.0 2 | 3 | COPY ./prometheus.yml /etc/prometheus/prometheus.yml 4 | COPY ./django.rules /etc/prometheus/django.rules -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/prometheus/django.rules: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: django.rules 3 | rules: 4 | - record: job:django_http_requests_before_middlewares_total:sum_rate30s 5 | expr: sum(rate(django_http_requests_before_middlewares_total[30s])) BY (job) 6 | - record: job:django_http_requests_unknown_latency_total:sum_rate30s 7 | expr: sum(rate(django_http_requests_unknown_latency_total[30s])) BY (job) 8 | - record: job:django_http_ajax_requests_total:sum_rate30s 9 | expr: sum(rate(django_http_ajax_requests_total[30s])) BY (job) 10 | - record: job:django_http_responses_before_middlewares_total:sum_rate30s 11 | expr: sum(rate(django_http_responses_before_middlewares_total[30s])) BY (job) 12 | - record: job:django_http_requests_unknown_latency_including_middlewares_total:sum_rate30s 13 | expr: sum(rate(django_http_requests_unknown_latency_including_middlewares_total[30s])) 14 | BY (job) 15 | - record: job:django_http_requests_body_total_bytes:sum_rate30s 16 | expr: sum(rate(django_http_requests_body_total_bytes[30s])) BY (job) 17 | - record: job:django_http_responses_streaming_total:sum_rate30s 18 | expr: sum(rate(django_http_responses_streaming_total[30s])) BY (job) 19 | - record: job:django_http_responses_body_total_bytes:sum_rate30s 20 | expr: sum(rate(django_http_responses_body_total_bytes[30s])) BY (job) 21 | - record: job:django_http_requests_total:sum_rate30s 22 | expr: sum(rate(django_http_requests_total_by_method[30s])) BY (job) 23 | - record: job:django_http_requests_total_by_method:sum_rate30s 24 | expr: sum(rate(django_http_requests_total_by_method[30s])) BY (job, method) 25 | - record: job:django_http_requests_total_by_transport:sum_rate30s 26 | expr: sum(rate(django_http_requests_total_by_transport[30s])) BY (job, transport) 27 | - record: job:django_http_requests_total_by_view:sum_rate30s 28 | expr: sum(rate(django_http_requests_total_by_view_transport_method[30s])) BY (job, 29 | view) 30 | - record: job:django_http_requests_total_by_view_transport_method:sum_rate30s 31 | expr: sum(rate(django_http_requests_total_by_view_transport_method[30s])) BY (job, 32 | view, transport, method) 33 | - record: job:django_http_responses_total_by_templatename:sum_rate30s 34 | expr: sum(rate(django_http_responses_total_by_templatename[30s])) BY (job, templatename) 35 | - record: job:django_http_responses_total_by_status:sum_rate30s 36 | expr: sum(rate(django_http_responses_total_by_status[30s])) BY (job, status) 37 | - record: job:django_http_responses_total_by_status_name_method:sum_rate30s 38 | expr: sum(rate(django_http_responses_total_by_status_name_method[30s])) BY (job, 39 | status, name, method) 40 | - record: job:django_http_responses_total_by_charset:sum_rate30s 41 | expr: sum(rate(django_http_responses_total_by_charset[30s])) BY (job, charset) 42 | - record: job:django_http_exceptions_total_by_type:sum_rate30s 43 | expr: sum(rate(django_http_exceptions_total_by_type[30s])) BY (job, type) 44 | - record: job:django_http_exceptions_total_by_view:sum_rate30s 45 | expr: sum(rate(django_http_exceptions_total_by_view[30s])) BY (job, view) 46 | - record: job:django_http_requests_latency_including_middlewares_seconds:quantile_rate30s 47 | expr: histogram_quantile(0.5, sum(rate(django_http_requests_latency_including_middlewares_seconds_bucket[30s])) 48 | BY (job, le)) 49 | labels: 50 | quantile: "50" 51 | - record: job:django_http_requests_latency_including_middlewares_seconds:quantile_rate30s 52 | expr: histogram_quantile(0.95, sum(rate(django_http_requests_latency_including_middlewares_seconds_bucket[30s])) 53 | BY (job, le)) 54 | labels: 55 | quantile: "95" 56 | - record: job:django_http_requests_latency_including_middlewares_seconds:quantile_rate30s 57 | expr: histogram_quantile(0.99, sum(rate(django_http_requests_latency_including_middlewares_seconds_bucket[30s])) 58 | BY (job, le)) 59 | labels: 60 | quantile: "99" 61 | - record: job:django_http_requests_latency_including_middlewares_seconds:quantile_rate30s 62 | expr: histogram_quantile(0.999, sum(rate(django_http_requests_latency_including_middlewares_seconds_bucket[30s])) 63 | BY (job, le)) 64 | labels: 65 | quantile: "99.9" 66 | - record: job:django_http_requests_latency_seconds:quantile_rate30s 67 | expr: histogram_quantile(0.5, sum(rate(django_http_requests_latency_seconds_bucket[30s])) 68 | BY (job, le)) 69 | labels: 70 | quantile: "50" 71 | - record: job:django_http_requests_latency_seconds:quantile_rate30s 72 | expr: histogram_quantile(0.95, sum(rate(django_http_requests_latency_seconds_bucket[30s])) 73 | BY (job, le)) 74 | labels: 75 | quantile: "95" 76 | - record: job:django_http_requests_latency_seconds:quantile_rate30s 77 | expr: histogram_quantile(0.99, sum(rate(django_http_requests_latency_seconds_bucket[30s])) 78 | BY (job, le)) 79 | labels: 80 | quantile: "99" 81 | - record: job:django_http_requests_latency_seconds:quantile_rate30s 82 | expr: histogram_quantile(0.999, sum(rate(django_http_requests_latency_seconds_bucket[30s])) 83 | BY (job, le)) 84 | labels: 85 | quantile: "99.9" 86 | - record: job:django_model_inserts_total:sum_rate1m 87 | expr: sum(rate(django_model_inserts_total[1m])) BY (job, model) 88 | - record: job:django_model_updates_total:sum_rate1m 89 | expr: sum(rate(django_model_updates_total[1m])) BY (job, model) 90 | - record: job:django_model_deletes_total:sum_rate1m 91 | expr: sum(rate(django_model_deletes_total[1m])) BY (job, model) 92 | - record: job:django_db_new_connections_total:sum_rate30s 93 | expr: sum(rate(django_db_new_connections_total[30s])) BY (alias, vendor) 94 | - record: job:django_db_new_connection_errors_total:sum_rate30s 95 | expr: sum(rate(django_db_new_connection_errors_total[30s])) BY (alias, vendor) 96 | - record: job:django_db_execute_total:sum_rate30s 97 | expr: sum(rate(django_db_execute_total[30s])) BY (alias, vendor) 98 | - record: job:django_db_execute_many_total:sum_rate30s 99 | expr: sum(rate(django_db_execute_many_total[30s])) BY (alias, vendor) 100 | - record: job:django_db_errors_total:sum_rate30s 101 | expr: sum(rate(django_db_errors_total[30s])) BY (alias, vendor, type) 102 | - record: job:django_migrations_applied_total:max 103 | expr: max(django_migrations_applied_total) BY (job, connection) 104 | - record: job:django_migrations_unapplied_total:max 105 | expr: max(django_migrations_unapplied_total) BY (job, connection) -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 10s 3 | evaluation_interval: 10s 4 | 5 | external_labels: 6 | monitor: django-monitor 7 | 8 | rule_files: 9 | - "django.rules" 10 | 11 | scrape_configs: 12 | - job_name: "django" 13 | metrics_path: /prometheus/metrics 14 | static_configs: 15 | - targets: ["web:8000"] -------------------------------------------------------------------------------- /{{cookiecutter.project_name}}/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 100 3 | target-version = ['py38'] 4 | include = '\.pyi?$' 5 | exclude = ''' 6 | /( 7 | | \.git 8 | | \.mypy_cache 9 | | \.tox 10 | | \.venv 11 | )/ 12 | ''' --------------------------------------------------------------------------------