diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 4899c4f91..b232b6e34 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,32 +1 @@ -**Note: for support questions, please use the `cookiecutter-django` tag on stackoverflow**. This repository's issues are reserved for feature requests and bug reports. If you need quick professional paid support for your project, contact support@cookiecutter.io. - -* **I'm submitting a ... ** - - [ ] bug report - - [ ] feature request - - [ ] support request => Please do not submit support request here, see note at the top of this template. - - -* **Do you want to request a *feature* or report a *bug*?** - - - -* **What is the current behavior?** - - - -* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** - - -* **What is the expected behavior?** - - - -* **What is the motivation / use case for changing the behavior?** - - - -* **Please tell us about your environment:** - - - -* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc) +## [Make sure to follow one of the issue templates we've got](https://github.com/pydanny/cookiecutter-django/issues/new/choose), otherwise the issue might be closed immeditely diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 000000000..75f6a19c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,23 @@ +--- +name: Bug Report +about: Report a bug +--- + +## What happened? + + + + +## What should've happened instead? + + + + +## Steps to reproduce + +[//]: # (Any or all of the following:) +[//]: # (* Host system configuration: OS, Docker & friends' versions etc.) +[//]: # (* Project generation options) +[//]: # (* Logs) + + diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 000000000..b0d560d81 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,24 @@ +--- +name: New Feature Proposal +about: Propose a new feature +--- + +## Description + +[//]: # (What's it you're proposing? How should it be implemented?) + + + + +## Rationale + +[//]: # (Why should this feature be implemented?) + + + + +## Use case(s) / visualization(s) + +[//]: # ("Better to see something once than to hear about it a thousand times.") + + diff --git a/.github/ISSUE_TEMPLATE/improvement.md b/.github/ISSUE_TEMPLATE/improvement.md new file mode 100644 index 000000000..572652373 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/improvement.md @@ -0,0 +1,24 @@ +--- +name: Improvement Suggestion +about: Let us know how we could improve +--- + +## Description + +[//]: # (What's it you're proposing? How should it be implemented?) + + + + +## Rationale + +[//]: # (Why should this feature be implemented?) + + + + +## Use case(s) / visualization(s) + +[//]: # ("Better to see something once than to hear about it a thousand times.") + + diff --git a/.github/ISSUE_TEMPLATE/paid-support.md b/.github/ISSUE_TEMPLATE/paid-support.md new file mode 100644 index 000000000..7cd2c4a57 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/paid-support.md @@ -0,0 +1,10 @@ +--- +name: Paid Support Request +about: Ask Core Team members to help you out +--- + +Provided your question goes beyound [regular support](https://github.com/pydanny/cookiecutter-django/issues/new?template=question.md), and/or the task at hand is of timely/high priority nature use the below information to reach out for contributors directly. + +* Daniel Roy Greenfeld, Project Lead ([GitHub](https://github.com/pydanny), [Patreon](https://www.patreon.com/danielroygreenfeld)): expertise in Django and AWS ELB. + +* Nikita Shupeyko, Core Developer ([GitHub](https://github.com/webyneter)): expertise in Django, Docker, and Heroku. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 000000000..0c0f3d891 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,6 @@ +--- +name: Question +about: Please, ask your question on StackOverflow or Gitter +--- + +First, make sure to examine [the docs](https://cookiecutter-django.readthedocs.io/en/latest/). If that doesn't help post a question on [StackOverflow](https://stackoverflow.com/questions/tagged/cookiecutter-django) tagged with `cookiecutter-django`. Finally, feel free to join [Gitter](https://gitter.im/pydanny/cookiecutter-django) and ask around. diff --git a/.github/ISSUE_TEMPLATE/regression.md b/.github/ISSUE_TEMPLATE/regression.md new file mode 100644 index 000000000..80384004b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/regression.md @@ -0,0 +1,28 @@ +--- +name: Regression Report +about: Let us know if something that'd been working has broke +--- + +## What happened before? + + + + +## What happens now? + + + + +## Last stable commit / Since when? + + + + +## Steps to reproduce + +[//]: # (Any or all of the following:) +[//]: # (* Host system configuration: OS, Docker & friends' versions etc.) +[//]: # (* Project generation options) +[//]: # (* Logs) + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..8dbff6c25 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,27 @@ +[//]: # (Thank you for helping us out: your efforts mean great deal to the project and the community as a whole!) + +[//]: # (Before you proceed:) + +[//]: # (1. Make sure to add yourself to `CONTRIBUTORS.rst` through this PR provided you're contributing here for the first time) +[//]: # (2. Don't forget to update the `docs/` presuming others would benefit from a concise description of whatever that you're proposing) + + +## Description + +[//]: # (What's it you're proposing?) + + + + +## Rationale + +[//]: # (Why does the project need that?) + + + + +## Use case(s) / visualization(s) + +[//]: # ("Better to see something once than to hear about it a thousand times.") + + diff --git a/.gitignore b/.gitignore index 1f80de173..9e4496f1c 100644 --- a/.gitignore +++ b/.gitignore @@ -226,3 +226,5 @@ pip-selfcheck.json # to 'run' anything within it since any particular cookiecutter # is declarative by nature. .idea/ + +.pytest_cache/ diff --git a/.travis.yml b/.travis.yml index f6e18b521..a46726d6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -# Config file for automatic testing at travis-ci.org - sudo: required services: @@ -10,27 +8,18 @@ language: python python: 3.6 env: - - TOX_ENV=py36 + - TOX_ENV=py36 before_install: - - sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-precise main" > /etc/apt/sources.list.d/docker.list' - - sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D - - sudo apt-get update - - sudo apt-key update - - sudo apt-get --force-yes -qqy -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install docker-engine=1.11.1-0~precise - - sudo rm /usr/local/bin/docker-compose - - curl -L https://github.com/docker/compose/releases/download/1.7.0/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - docker-compose -v - docker -v script: - - tox -e $TOX_ENV - - sh tests/test_docker.sh + - tox -e $TOX_ENV + - sh tests/test_docker.sh install: - - pip install tox + - pip install tox notifications: email: diff --git a/CHANGELOG.md b/CHANGELOG.md index 24f8d11cc..304732b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All enhancements and patches to Cookiecutter Django will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2018-02-16] +### Changed +- Upgraded to Django 2.0 (@epicwhale) + ## [2018-01-15] ### Changed - Removed Elastic Beanstalk support (@pydanny) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index a9a857733..0f6761ed5 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -16,8 +16,9 @@ Fábio C. Barrionuevo da Luz `@luzfcb`_ @luzfcb Saurabh Kumar `@theskumar`_ @_theskumar Jannis Gebauer `@jayfk`_ Burhan Khalid `@burhan`_ @burhan -Shupeyko Nikita `@webyneter`_ @webyneter +Nikita Shupeyko `@webyneter`_ @webyneter Bruno Alla               `@browniebroke`_ @_BrunoAlla +Wan Liuyang `@sfdye`_ @sfdye =========================== ================ =========== *Audrey is also the creator of Cookiecutter. Audrey and @@ -30,6 +31,7 @@ Daniel are on the Cookiecutter core team.* .. _@jayfk: https://github.com/jayfk .. _@webyneter: https://github.com/webyneter .. _@browniebroke: https://github.com/browniebroke +.. _@sfdye: https://github.com/sfdye Other Contributors ------------------ @@ -44,6 +46,7 @@ Listed in alphabetical order. Aaron Eikenberry `@aeikenberry`_ Adam Bogdał `@bogdal`_ Adam Dobrawy `@ad-m`_ + Adam Steele `@adammsteele` Agam Dua Alberto Sanchez `@alb3rto`_ Alex Tsai `@caffodian`_ @@ -88,6 +91,7 @@ Listed in alphabetical order. Dong Huynh `@trungdong`_ Emanuel Calso `@bloodpet`_ @bloodpet Eraldo Energy `@eraldo`_ + Eric Groom `@ericgroom`_ Eyad Al Sibai `@eyadsibai`_ Felipe Arruda `@arruda`_ Garry Cairns `@garry-cairns`_ @@ -114,7 +118,9 @@ Listed in alphabetical order. Luis Nell `@originell`_ Lukas Klein Lyla Fischer + Malik Sulaimanov `@flyudvik`_ @flyudvik Martin Blech + Martin Saizar `@msaizar`_ Mathijs Hoogland `@MathijsHoogland`_ Matt Braymer-Hayes `@mattayes`_ @mattayes Matt Linares @@ -136,6 +142,7 @@ Listed in alphabetical order. Roman Afanaskin `@siauPatrick`_ Roman Osipenko `@romanosipenko`_ Russell Davies + Sascha `@saschalalala` @saschalalala Sam Collins `@MightySCollins`_ Shupeyko Nikita `@webyneter`_ Sławek Ehlert `@slafs`_ @@ -151,7 +158,6 @@ Listed in alphabetical order. Travis McNeill `@Travistock`_ @tavistock_esq Vitaly Babiy Vivian Guillen `@viviangb`_ - Wan Liuyang `@sfdye`_ @sfdye Will Farley `@goldhand`_ @g01dhand William Archinal `@archinal`_ Yaroslav Halchenko @@ -159,6 +165,7 @@ Listed in alphabetical order. .. _@a7p: https://github.com/a7p .. _@ad-m: https://github.com/ad-m +.. _@adammsteele: https://github.com/adammsteele .. _@aeikenberry: https://github.com/aeikenberry .. _@alb3rto: https://github.com/alb3rto .. _@ameistad: https://github.com/ameistad @@ -193,6 +200,7 @@ Listed in alphabetical order. .. _@eraldo: https://github.com/eraldo .. _@eriol: https://github.com/eriol .. _@eyadsibai: https://github.com/eyadsibai +.. _@flyudvik: https://github.com/flyudvik .. _@garry-cairns: https://github.com/garry-cairns .. _@garrypolley: https://github.com/garrypolley .. _@goldhand: https://github.com/goldhand @@ -211,6 +219,7 @@ Listed in alphabetical order. .. _@kevgathuku: https://github.com/kevgathuku .. _@knitatoms: https://github.com/knitatoms .. _@krzysztofzuraw: https://github.com/krzysztofzuraw +.. _@msaizar: https://github.com/msaizar .. _@MathijsHoogland: https://github.com/MathijsHoogland .. _@mattayes: https://github.com/mattayes .. _@menzenski: https://github.com/menzenski @@ -229,7 +238,6 @@ Listed in alphabetical order. .. _@romanosipenko: https://github.com/romanosipenko .. _@shireenrao: https://github.com/shireenrao .. _@show0k: https://github.com/show0k -.. _@sfdye: https://github.com/sfdye .. _@shultz: https://github.com/shultz .. _@siauPatrick: https://github.com/siauPatrick .. _@slafs: https://github.com/slafs diff --git a/LICENSE b/LICENSE index da2bbe30b..28466d40f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013-2018, Daniel Greenfeld +Copyright (c) 2013-2018, Daniel Roy Greenfeld All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/README.rst b/README.rst index 6536ab7ec..7e24a8369 100644 --- a/README.rst +++ b/README.rst @@ -16,6 +16,10 @@ Cookiecutter Django :target: https://www.codetriage.com/pydanny/cookiecutter-django :alt: Code Helpers Badge +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/ambv/black + :alt: Code style: black + Powered by Cookiecutter_, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. @@ -23,9 +27,6 @@ production-ready Django projects quickly. * See Troubleshooting_ for common errors and obstacles * If you have problems with Cookiecutter Django, please open issues_ don't send emails to the maintainers. -* Need quick professional paid support? Contact `support@cookiecutter.io`_. - This includes configuring your servers, fixing bugs, reviewing your code and - everything in between. .. _cookiecutter: https://github.com/audreyr/cookiecutter @@ -33,15 +34,14 @@ production-ready Django projects quickly. .. _528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 .. _issues: https://github.com/pydanny/cookiecutter-django/issues/new -.. _support@cookiecutter.io: support@cookiecutter.io Features --------- -* For Django 1.11 +* For Django 2.0 * Works with Python 3.6 * Renders Django projects with 100% starting test coverage -* Twitter Bootstrap_ v4.0.0 - beta 1 (`maintained Foundation fork`_ also available) +* Twitter Bootstrap_ v4.0.0 (`maintained Foundation fork`_ also available) * 12-Factor_ based settings via django-environ_ * Secure by default. We believe in SSL. * Optimized development and production settings @@ -68,7 +68,6 @@ Optional Integrations * Configuration for Celery_ * Integration with MailHog_ for local email testing * Integration with Sentry_ for error logging -* Integration with Opbeat_ for performance monitoring .. _Bootstrap: https://github.com/twbs/bootstrap .. _django-environ: https://github.com/joke2k/django-environ @@ -83,7 +82,6 @@ Optional Integrations .. _MailHog: https://github.com/mailhog/MailHog .. _Sentry: https://sentry.io/welcome/ .. _docker-compose: https://github.com/docker/compose -.. _Opbeat: https://opbeat.com/ .. _PythonAnywhere: https://www.pythonanywhere.com/ .. _Caddy: https://caddyserver.com/ .. _LetsEncrypt: https://letsencrypt.org/ @@ -111,7 +109,7 @@ Two Scoops of Django 1.11 :name: Two Scoops of Django 1.11 Cover :align: center :alt: Two Scoops of Django - :target: http://twoscoopspress.org/products/two-scoops-of-django-1-11 + :target: http://twoscoopspress.com/products/two-scoops-of-django-1-11 Two Scoops of Django is the best dessert-themed Django reference in the universe @@ -129,7 +127,7 @@ Pyup brings you automated security and dependency updates used by Google and oth Usage ------ -Let's pretend you want to create a Django project called "redditclone". Rather than using `startproject` +Let's pretend you want to create a Django project called "redditclone". Rather than using ``startproject`` and then editing the results to include your name, email, and various configuration issues that always get forgotten until the worst possible moment, get cookiecutter_ to do all the work. First, get Cookiecutter. Trust me, it's awesome:: @@ -160,23 +158,23 @@ Answer the prompts with your own desired options_. For example:: domain_name [example.com]: myreddit.com version [0.1.0]: 0.0.1 timezone [UTC]: America/Los_Angeles - use_whitenoise [y]: n + use_whitenoise [n]: n use_celery [n]: y use_mailhog [n]: n - use_sentry_for_error_reporting [y]: y - use_opbeat [n]: y + use_sentry [n]: y use_pycharm [n]: y windows [n]: n - use_docker [y]: n + use_docker [n]: n use_heroku [n]: y use_compressor [n]: y Select postgresql_version: - 1 - 10 - 2 - 9.6 - 3 - 9.5 - 4 - 9.4 - 5 - 9.3 - 6 - 9.2 + 1 - 10.3 + 2 - 10.2 + 3 - 10.1 + 4 - 9.6 + 5 - 9.5 + 6 - 9.4 + 7 - 9.3 Choose from 1, 2, 3, 4 [1]: 1 Select js_task_runner: 1 - Gulp @@ -191,6 +189,8 @@ Answer the prompts with your own desired options_. For example:: 4 - Apache Software License 2.0 5 - Not open source Choose from 1, 2, 3, 4, 5 [1]: 1 + keep_local_envs_in_vcs [y]: y + debug[n]: n Enter the project and take a look around:: @@ -279,6 +279,8 @@ experience better. Articles --------- +* `cookiecutter-django with Nginx, Route 53 and ELB`_ - Feb. 12, 2018 +* `cookiecutter-django and Amazon RDS`_ - Feb. 7, 2018 * `Deploying Cookiecutter-Django with Docker-Compose`_ - Oct. 19, 2017 * `Using Cookiecutter to Jumpstart a Django Project on Windows with PyCharm`_ - May 19, 2017 * `Exploring with Cookiecutter`_ - Dec. 3, 2016 @@ -290,6 +292,8 @@ Articles Have a blog or online publication? Write about your cookiecutter-django tips and tricks, then send us a pull request with the link. +.. _`cookiecutter-django with Nginx, Route 53 and ELB`: https://msaizar.com/blog/cookiecutter-django-nginx-route-53-and-elb/ +.. _`cookiecutter-django and Amazon RDS`: https://msaizar.com/blog/cookiecutter-django-and-amazon-rds/ .. _`Deploying Cookiecutter-Django with Docker-Compose`: http://adamantine.me/2017/10/19/deploying-cookiecutter-django-with-docker-compose/ .. _`Exploring with Cookiecutter`: http://www.snowboardingcoder.com/django/2016/12/03/exploring-with-cookiecutter/ .. _`Using Cookiecutter to Jumpstart a Django Project on Windows with PyCharm`: https://joshuahunter.com/posts/using-cookiecutter-to-jumpstart-a-django-project-on-windows-with-pycharm/ diff --git a/cookiecutter.json b/cookiecutter.json index 933c3dfa0..21a639a3a 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,24 +1,45 @@ { - "project_name": "Project Name", - "project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_') }}", - "author_name": "Daniel Roy Greenfeld", - "email": "you@example.com", - "description": "A short description of the project.", - "domain_name": "example.com", - "version": "0.1.0", - "timezone": "UTC", - "use_whitenoise": "y", - "use_celery": "n", - "use_mailhog": "n", - "use_sentry_for_error_reporting": "y", - "use_opbeat": "n", - "use_pycharm": "n", - "windows": "n", - "use_docker": "n", - "use_heroku": "n", - "use_compressor": "n", - "postgresql_version": ["10", "9.6", "9.5", "9.4", "9.3", "9.2"], - "js_task_runner": ["Gulp", "Grunt", "None"], - "custom_bootstrap_compilation": "n", - "open_source_license": ["MIT", "BSD", "GPLv3", "Apache Software License 2.0", "Not open source"] + "project_name": "My Awesome Project", + "project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_') }}", + "description": "Behold My Awesome Project!", + "author_name": "Daniel Roy Greenfeld", + "domain_name": "example.com", + "email": "{{ cookiecutter.author_name.lower()|replace(' ', '-') }}@example.com", + "version": "0.1.0", + "open_source_license": [ + "MIT", + "BSD", + "GPLv3", + "Apache Software License 2.0", + "Not open source" + ], + "timezone": "UTC", + "windows": "n", + "use_pycharm": "n", + "use_docker": "n", + "postgresql_version": [ + "10.4", + "10.3", + "10.2", + "10.1", + "9.6", + "9.5", + "9.4", + "9.3" + ], + "js_task_runner": [ + "None", + "Gulp" + ], + "custom_bootstrap_compilation": "n", + "use_compressor": "n", + "use_celery": "n", + "use_mailhog": "n", + "use_sentry": "n", + "use_whitenoise": "n", + "use_heroku": "n", + "use_travisci": "n", + "keep_local_envs_in_vcs": "y", + + "debug": "n" } diff --git a/docs/conf.py b/docs/conf.py index f8810ca7a..e3ddae9a6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,29 +29,29 @@ now = datetime.now() extensions = [] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'Cookiecutter Django' -copyright = "2013-2016, Daniel Roy Greenfeld".format(now.year) +project = "Cookiecutter Django" +copyright = "2013-2018, Daniel Roy Greenfeld".format(now.year) # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '{}.{}.{}'.format(*now.isocalendar()) +version = "{}.{}.{}".format(*now.isocalendar()) # The full version, including alpha/beta/rc tags. -release = '{}.{}.{}'.format(*now.isocalendar()) +release = "{}.{}.{}".format(*now.isocalendar()) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -65,7 +65,7 @@ release = '{}.{}.{}'.format(*now.isocalendar()) # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. # default_role = None @@ -82,7 +82,7 @@ exclude_patterns = ['_build'] # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -92,7 +92,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -121,7 +121,7 @@ html_theme = 'default' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -165,7 +165,7 @@ html_static_path = ['_static'] # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'cookiecutter-djangodoc' +htmlhelp_basename = "cookiecutter-djangodoc" # -- Options for LaTeX output -------------------------------------------------- @@ -173,10 +173,8 @@ htmlhelp_basename = 'cookiecutter-djangodoc' latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # 'preamble': '', } @@ -184,10 +182,13 @@ latex_elements = { # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', - 'cookiecutter-django.tex', - 'cookiecutter-django Documentation', - 'cookiecutter-django', 'manual'), + ( + "index", + "cookiecutter-django.tex", + "cookiecutter-django Documentation", + "cookiecutter-django", + "manual", + ) ] # The name of an image file (relative to this directory) to place at the top of @@ -216,8 +217,13 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'Cookiecutter Django', 'Cookiecutter Django documentation', - ['Daniel Roy Greenfeld'], 1) + ( + "index", + "Cookiecutter Django", + "Cookiecutter Django documentation", + ["Daniel Roy Greenfeld"], + 1, + ) ] # If true, show URL addresses after external links. @@ -230,9 +236,15 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'Cookiecutter Django', 'Cookiecutter Django documentation', - 'Daniel Roy Greenfeld', 'Cookiecutter Django', - 'A Cookiecutter template for creating production-ready Django projects quickly.', 'Miscellaneous'), + ( + "index", + "Cookiecutter Django", + "Cookiecutter Django documentation", + "Daniel Roy Greenfeld", + "Cookiecutter Django", + "A Cookiecutter template for creating production-ready Django projects quickly.", + "Miscellaneous", + ) ] # Documents to append as an appendix to all manuals. diff --git a/docs/deployment-on-heroku.rst b/docs/deployment-on-heroku.rst index b84edfa46..7006a2877 100644 --- a/docs/deployment-on-heroku.rst +++ b/docs/deployment-on-heroku.rst @@ -14,26 +14,31 @@ Run these commands to deploy the project to Heroku: heroku pg:promote DATABASE_URL heroku addons:create heroku-redis:hobby-dev - heroku addons:create mailgun - heroku config:set DJANGO_ADMIN_URL="$(openssl rand -base64 32)" - heroku config:set DJANGO_SECRET_KEY="$(openssl rand -base64 64)" - heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production' - heroku config:set DJANGO_ALLOWED_HOSTS='.herokuapp.com' + # If using mailgun: + heroku addons:create mailgun:starter - heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE - heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE - heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE - - heroku config:set DJANGO_MAILGUN_SERVER_NAME=YOUR_MALGUN_SERVER - heroku config:set DJANGO_MAILGUN_API_KEY=YOUR_MAILGUN_API_KEY - heroku config:set MAILGUN_SENDER_DOMAIN=YOUR_MAILGUN_SENDER_DOMAIN + heroku addons:create sentry:f1 heroku config:set PYTHONHASHSEED=random - heroku config:set DJANGO_ADMIN_URL=\^somelocation/ + heroku config:set WEB_CONCURRENCY=4 + heroku config:set DJANGO_DEBUG=False + heroku config:set DJANGO_SETTINGS_MODULE=config.settings.production + heroku config:set DJANGO_SECRET_KEY="$(openssl rand -base64 64)" + # Generating a 32 character-long random string without any of the visually similiar characters "IOl01": + heroku config:set DJANGO_ADMIN_URL="$(openssl rand -base64 4096 | tr -dc 'A-HJ-NP-Za-km-z2-9' | head -c 32)/" + heroku config:set DJANGO_ALLOWED_HOSTS= # Set this to your Heroku app url, e.g. 'bionic-beaver-28392.herokuapp.com' + + heroku config:set DJANGO_AWS_ACCESS_KEY_ID= # Assign with AWS_ACCESS_KEY_ID + heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY= # Assign with AWS_SECRET_ACCESS_KEY + heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME= # Assign with AWS_STORAGE_BUCKET_NAME git push heroku master + heroku run python manage.py migrate - heroku run python manage.py check --deploy heroku run python manage.py createsuperuser + heroku run python manage.py collectstatic --no-input + + heroku run python manage.py check --deploy + heroku open diff --git a/docs/deployment-on-pythonanywhere.rst b/docs/deployment-on-pythonanywhere.rst index d70684bd9..ea25b3ae5 100644 --- a/docs/deployment-on-pythonanywhere.rst +++ b/docs/deployment-on-pythonanywhere.rst @@ -63,13 +63,13 @@ Add these exports .. code-block:: bash + export WEB_CONCURRENCY=4 export DJANGO_SETTINGS_MODULE='config.settings.production' export DJANGO_SECRET_KEY='' export DJANGO_ALLOWED_HOSTS='' export DJANGO_ADMIN_URL='' - export DJANGO_MAILGUN_API_KEY='' - export DJANGO_MAILGUN_SERVER_NAME='' - export MAILGUN_SENDER_DOMAIN='' + export MAILGUN_API_KEY='' + export MAILGUN_DOMAIN='' export DJANGO_AWS_ACCESS_KEY_ID= export DJANGO_AWS_SECRET_ACCESS_KEY= export DJANGO_AWS_STORAGE_BUCKET_NAME= @@ -83,7 +83,7 @@ Database setup: Go to the PythonAnywhere **Databases tab** and configure your database. -* For Postgres, setup your superuser password, then open a Postgres console and run a `CREATE DATABASE my-db-name`. You should probably also set up a specific role and permissions for your app, rather than using the superuser credentials. Make a note of the address and port of your postgres server. +* For Postgres, setup your superuser password, then open a Postgres console and run a ``CREATE DATABASE my-db-name``. You should probably also set up a specific role and permissions for your app, rather than using the superuser credentials. Make a note of the address and port of your postgres server. * For MySQL, set the password and create a database. More info here: https://help.pythonanywhere.com/pages/UsingMySQL @@ -138,9 +138,8 @@ Click through to the **WSGI configuration file** link (near the top) and edit th os.environ['DJANGO_SECRET_KEY'] = '' os.environ['DJANGO_ALLOWED_HOSTS'] = '' os.environ['DJANGO_ADMIN_URL'] = '' - os.environ['DJANGO_MAILGUN_API_KEY'] = '' - os.environ['DJANGO_MAILGUN_SERVER_NAME'] = '' - os.environ['MAILGUN_SENDER_DOMAIN'] = '' + os.environ['MAILGUN_API_KEY'] = '' + os.environ['MAILGUN_DOMAIN'] = '' os.environ['DJANGO_AWS_ACCESS_KEY_ID'] = '' os.environ['DJANGO_AWS_SECRET_ACCESS_KEY'] = '' os.environ['DJANGO_AWS_STORAGE_BUCKET_NAME'] = '' diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index fb383c3c5..42798aae8 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -1,83 +1,82 @@ Deployment with Docker -======================= +====================== + +.. index:: deployment, docker, docker-compose, compose -.. index:: Docker, deployment Prerequisites ------------- -* Docker (at least 1.10) -* Docker Compose (at least 1.6) +* Docker 1.10+. +* Docker Compose 1.6+ -Understand the Compose Setup --------------------------------- -Before you start, check out the `production.yml` file in the root of this project. This is where each component -of this application gets its configuration from. Notice how it provides configuration for these services: +Understanding the Docker Compose Setup +-------------------------------------- -* `postgres` service that runs the database -* `redis` for caching -* `caddy` as webserver -* `django` is the Django project run by gunicorn +Before you begin, check out the ``production.yml`` file in the root of this project. Keep note of how it provides configuration for the following services: -If you chose the `use_celery` option, there are two more services: +* ``django``: your application running behind ``Gunicorn``; +* ``postgres``: PostgreSQL database with the application's relational data; +* ``redis``: Redis instance for caching; +* ``caddy``: Caddy web server with HTTPS on by default. -* `celeryworker` which runs the celery worker process -* `celerybeat` which runs the celery beat process +Provided you have opted for Celery (via setting ``use_celery`` to ``y``) there are two more services: -Populate .env With Your Environment Variables ---------------------------------------------- +* ``celeryworker`` running a Celery worker process; +* ``celerybeat`` running a Celery beat process. -Some of these services rely on environment variables set by you. There is an `env.example` file in the -root directory of this project as a starting point. Add your own variables to the file and rename it to `.env`. This -file won't be tracked by git by default so you'll have to make sure to use some other mechanism to copy your secret if -you are relying solely on git. -It is **highly recommended** that before you build your production application, you set your POSTGRES_USER value here. This will create a non-default user for the postgres image. If you do not set this user before building the application, the default user 'postgres' will be created, and this user will not be able to create or restore backups. +Configuring the Stack +--------------------- -To obtain logs and information about crashes in a production setup, make sure that you have access to an external Sentry instance (e.g. by creating an account with `sentry.io`_), and set the `DJANGO_SENTRY_DSN` variable. This should be enough to report crashes to Sentry. +The majority of services above are configured through the use of environment variables. Just check out :ref:`envs` and you will know the drill. + +To obtain logs and information about crashes in a production setup, make sure that you have access to an external Sentry instance (e.g. by creating an account with `sentry.io`_), and set the ``SENTRY_DSN`` variable. You will probably also need to setup the Mail backend, for example by adding a `Mailgun`_ API key and a `Mailgun`_ sender domain, otherwise, the account creation view will crash and result in a 500 error when the backend attempts to send an email to the account owner. .. _sentry.io: https://sentry.io/welcome .. _Mailgun: https://mailgun.com -HTTPS is on by default + +Optional: Use AWS IAM Role for EC2 instance +------------------------------------------- + +If you are deploying to AWS, you can use the IAM role to substitute AWS credentials, after which it's safe to remove the ``AWS_ACCESS_KEY_ID`` AND ``AWS_SECRET_ACCESS_KEY`` from ``.envs/.production/.django``. To do it, create an `IAM role`_ and `attach`_ it to the existing EC2 instance or create a new EC2 instance with that role. The role should assume, at minimum, the ``AmazonS3FullAccess`` permission. + +.. _IAM role: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html +.. _attach: https://aws.amazon.com/blogs/security/easily-replace-or-attach-an-iam-role-to-an-existing-ec2-instance-by-using-the-ec2-console/ + + +HTTPS is On by Default ---------------------- SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client, typically in this case, a web server (website) and a browser. Not having HTTPS means that malicious network users can sniff authentication credentials between your website and end users' browser. It is always better to deploy a site behind HTTPS and will become crucial as the web services extend to the IoT (Internet of Things). For this reason, we have set up a number of security defaults to help make your website secure: -* In the `.env.example`, we have made it simpler for you to change the default `Django Admin` into a custom name through an environmental variable. This should make it harder to guess the access to the admin panel. - -* If you are not using a subdomain of the domain name set in the project, then remember to put the your staging/production IP address in the :code:`DJANGO_ALLOWED_HOSTS` environment variable (see :ref:`settings`) before you deploy your website. Failure to do this will mean you will not have access to your website through the HTTP protocol. +* If you are not using a subdomain of the domain name set in the project, then remember to put the your staging/production IP address in the ``DJANGO_ALLOWED_HOSTS`` environment variable (see :ref:`settings`) before you deploy your website. Failure to do this will mean you will not have access to your website through the HTTP protocol. * Access to the Django admin is set up by default to require HTTPS in production or once *live*. - -HTTPS is configured by default ------------------------------- - -The Caddy webserver used in the default configuration will get you a valid certificate from Lets Encrypt and update it automatically. All you need to do to enable this is to make sure that your DNS records are pointing to the server Caddy runs on. +The Caddy web server used in the default configuration will get you a valid certificate from Lets Encrypt and update it automatically. All you need to do to enable this is to make sure that your DNS records are pointing to the server Caddy runs on. You can read more about this here at `Automatic HTTPS`_ in the Caddy docs. .. _Automatic HTTPS: https://caddyserver.com/docs/automatic-https -Optional: Postgres Data Volume Modifications +(Optional) Postgres Data Volume Modifications --------------------------------------------- -Postgres is saving its database files to the `postgres_data` volume by default. Change that if you want something else and make sure to make backups since this is not done automatically. +Postgres is saving its database files to the ``postgres_data`` volume by default. Change that if you want something else and make sure to make backups since this is not done automatically. -Run your app with docker-compose --------------------------------- -To get started, pull your code from source control (don't forget the `.env` file) and change to your projects root -directory. +Building & Running Production Stack +----------------------------------- -You'll need to build the stack first. To do that, run:: +You will need to build the stack first. To do that, run:: docker-compose -f production.yml build @@ -85,21 +84,23 @@ Once this is ready, you can run it with:: docker-compose -f production.yml up +To run the stack and detach the containers, run:: + + docker-compose -f production.yml up -d + To run a migration, open up a second terminal and run:: - docker-compose -f production.yml run django python manage.py migrate + docker-compose -f production.yml run --rm django python manage.py migrate To create a superuser, run:: - docker-compose -f production.yml run django python manage.py createsuperuser + docker-compose -f production.yml run --rm django python manage.py createsuperuser If you need a shell, run:: - docker-compose -f production.yml run django python manage.py shell + docker-compose -f production.yml run --rm django python manage.py shell -To get an output of all running containers. - -To check your logs, run:: +To check the logs out, run:: docker-compose -f production.yml logs @@ -108,21 +109,21 @@ If you want to scale your application, run:: docker-compose -f production.yml scale django=4 docker-compose -f production.yml scale celeryworker=2 -.. warning:: Don't run the scale command on postgres, celerybeat, or caddy. +.. warning:: don't try to scale ``postgres``, ``celerybeat``, or ``caddy``. -If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: +To see how your containers are doing run:: docker-compose -f production.yml ps -Supervisor Example +Example: Supervisor ------------------- Once you are ready with your initial setup, you want to make sure that your application is run by a process manager to survive reboots and auto restarts in case of an error. You can use the process manager you are most familiar with. All -it needs to do is to run `docker-compose -f production.yml up` in your projects root directory. +it needs to do is to run ``docker-compose -f production.yml up`` in your projects root directory. -If you are using `supervisor`, you can use this file as a starting point:: +If you are using ``supervisor``, you can use this file as a starting point:: [program:{{cookiecutter.project_slug}}] command=docker-compose -f production.yml up @@ -132,11 +133,11 @@ If you are using `supervisor`, you can use this file as a starting point:: autorestart=true priority=10 -Place it in `/etc/supervisor/conf.d/{{cookiecutter.project_slug}}.conf` and run:: +Move it to ``/etc/supervisor/conf.d/{{cookiecutter.project_slug}}.conf`` and run:: supervisorctl reread supervisorctl start {{cookiecutter.project_slug}} -To get the status, run:: +For status check, run:: supervisorctl status diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 99622c3ca..207f0ea2c 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -6,23 +6,19 @@ Getting Up and Running Locally With Docker The steps below will get you up and running with a local development environment. All of these commands assume you are in the root of your generated project. + Prerequisites ------------- -You'll need at least Docker 1.10. +* Docker; if you don't have it yet, follow the `installation instructions`_; +* Docker Compose; refer to the official documentation for the `installation guide`_. -If you don't already have it installed, follow the instructions for your OS: +.. _`installation instructions`: https://docs.docker.com/install/#supported-platforms +.. _`installation guide`: https://docs.docker.com/compose/install/ - - On Mac OS X, you'll need `Docker for Mac`_ - - On Windows, you'll need `Docker for Windows`_ - - On Linux, you'll need `docker-engine`_ -.. _`Docker for Mac`: https://docs.docker.com/engine/installation/mac/ -.. _`Docker for Windows`: https://docs.docker.com/engine/installation/windows/ -.. _`docker-engine`: https://docs.docker.com/engine/installation/ - -Attention Windows users ------------------------ +Attention, Windows Users +------------------------ Currently PostgreSQL (``psycopg2`` python package) is not installed inside Docker containers for Windows users, while it is required by the generated Django project. To fix this, add ``psycopg2`` to the list of requirements inside ``requirements/base.txt``:: @@ -31,23 +27,21 @@ Currently PostgreSQL (``psycopg2`` python package) is not installed inside Docke Doing this will prevent the project from being installed in an Windows-only environment (thus without usage of Docker). If you want to use this project without Docker, make sure to remove ``psycopg2`` from the requirements again. + Build the Stack --------------- -This can take a while, especially the first time you run this particular command -on your development system:: +This can take a while, especially the first time you run this particular command on your development system:: $ docker-compose -f local.yml build -If you want to build the production environment you use ``production.yml`` as -f argument (``docker-compose.yml`` or ``docker-compose.yaml`` are the defaults). +Generally, if you want to emulate production environment use ``production.yml`` instead. And this is true for any other actions you might need to perform: whenever a switch is required, just do it! -Boot the System ---------------- -This brings up both Django and PostgreSQL. +Run the Stack +------------- -The first time it is run it might take a while to get started, but subsequent -runs will occur quickly. +This brings up both Django and PostgreSQL. The first time it is run it might take a while to get started, but subsequent runs will occur quickly. Open a terminal at the project root and run the following for local development:: @@ -61,98 +55,118 @@ And then run:: $ docker-compose up -Running management commands -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To run in a detached (background) mode, just:: -As with any shell command that we wish to run in our container, this is done -using the ``docker-compose -f local.yml run`` command. + $ docker-compose up -d -To migrate your app and to create a superuser, run:: - $ docker-compose -f local.yml run django python manage.py migrate - $ docker-compose -f local.yml run django python manage.py createsuperuser +Execute Management Commands +--------------------------- -Here we specify the ``django`` container as the location to run our management commands. +As with any shell command that we wish to run in our container, this is done using the ``docker-compose -f local.yml run --rm`` command: :: -Add your Docker development server IP -------------------------------------- + $ docker-compose -f local.yml run --rm django python manage.py migrate + $ docker-compose -f local.yml run --rm django python manage.py createsuperuser -When ``DEBUG`` is set to `True`, the host is validated against ``['localhost', '127.0.0.1', '[::1]']``. This is adequate when running a ``virtualenv``. For Docker, in the ``config.settings.local``, add your host development server IP to ``INTERNAL_IPS`` or ``ALLOWED_HOSTS`` if the variable exists. +Here, ``django`` is the target service we are executing the commands against. -Production Mode -~~~~~~~~~~~~~~~ -Instead of using `local.yml`, you would use `production.yml`. +(Optionally) Designate your Docker Development Server IP +-------------------------------------------------------- -Other Useful Tips ------------------ +When ``DEBUG`` is set to ``True``, the host is validated against ``['localhost', '127.0.0.1', '[::1]']``. This is adequate when running a ``virtualenv``. For Docker, in the ``config.settings.local``, add your host development server IP to ``INTERNAL_IPS`` or ``ALLOWED_HOSTS`` if the variable exists. -Make a machine the active unit -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This tells our computer that all future commands are specifically for the dev1 machine. -Using the ``eval`` command we can switch machines as needed. +.. _envs: -:: +Configuring the Environment +--------------------------- + +This is the excerpt from your project's ``local.yml``: :: + + # ... + + postgres: + build: + context: . + dockerfile: ./compose/production/postgres/Dockerfile + volumes: + - postgres_data_local:/var/lib/postgresql/data + - postgres_backup_local:/backups + env_file: + - ./.envs/.local/.postgres + + # ... + +The most important thing for us here now is ``env_file`` section enlisting ``./.envs/.local/.postgres``. Generally, the stack's behavior is governed by a number of environment variables (`env(s)`, for short) residing in ``envs/``, for instance, this is what we generate for you: :: + + .envs + ├── .local + │   ├── .django + │   └── .postgres + └── .production + ├── .caddy + ├── .django + └── .postgres + +By convention, for any service ``sI`` in environment ``e`` (you know ``someenv`` is an environment when there is a ``someenv.yml`` file in the project root), given ``sI`` requires configuration, a ``.envs/.e/.sI`` `service configuration` file exists. + +Consider the aforementioned ``.envs/.local/.postgres``: :: + + # PostgreSQL + # ------------------------------------------------------------------------------ + POSTGRES_HOST=postgres + POSTGRES_DB= + POSTGRES_USER=XgOWtQtJecsAbaIyslwGvFvPawftNaqO + POSTGRES_PASSWORD=jSljDz4whHuwO3aJIgVBrqEml5Ycbghorep4uVJ4xjDYQu0LfuTZdctj7y0YcCLu + +The three envs we are presented with here are ``POSTGRES_DB``, ``POSTGRES_USER``, and ``POSTGRES_PASSWORD`` (by the way, their values have also been generated for you). You might have figured out already where these definitions will end up; it's all the same with ``django`` and ``caddy`` service container envs. + +One final touch: should you ever need to merge ``.envs/production/*`` in a single ``.env`` run the ``merge_production_dotenvs_in_dotenv.py``: :: + + $ python merge_production_dotenvs_in_dotenv.py + +The ``.env`` file will then be created, with all your production envs residing beside each other. + + +Tips & Tricks +------------- + +Activate a Docker Machine +~~~~~~~~~~~~~~~~~~~~~~~~~ + +This tells our computer that all future commands are specifically for the dev1 machine. Using the ``eval`` command we can switch machines as needed.:: $ eval "$(docker-machine env dev1)" -Detached Mode -~~~~~~~~~~~~~ - -If you want to run the stack in detached mode (in the background), use the ``-d`` argument: - -:: - - $ docker-compose -f local.yml up -d - Debugging -~~~~~~~~~~~~~ +~~~~~~~~~ ipdb """"" -If you are using the following within your code to debug: - -:: +If you are using the following within your code to debug: :: import ipdb; ipdb.set_trace() -Then you may need to run the following for it to work as desired: +Then you may need to run the following for it to work as desired: :: -:: - - $ docker-compose -f local.yml run --service-ports django + $ docker-compose -f local.yml run --rm --service-ports django django-debug-toolbar """""""""""""""""""" -In order for django-debug-toolbar to work with docker you need to add your docker-machine ip address to ``INTERNAL_IPS`` in ``local.py`` +In order for ``django-debug-toolbar`` to work designate your Docker Machine IP with ``INTERNAL_IPS`` in ``local.py``. -.. May be a better place to put this, as it is not Docker specific. +Mailhog +~~~~~~~ -You may need to add the following to your css in order for the django-debug-toolbar to be visible (this applies whether Docker is being used or not): +When developing locally you can go with MailHog_ for email testing provided ``use_mailhog`` was set to ``y`` on setup. To proceed, -.. code-block:: css +#. make sure ``mailhog`` container is up and running; - /* Override Bootstrap 4 styling on Django Debug Toolbar */ - #djDebug[hidden], #djDebug [hidden] { - display: block !important; - } - - #djDebug [hidden][style='display: none;'] { - display: none !important; - } - - -Using the Mailhog Docker Container -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In development you can (optionally) use MailHog_ for email testing. If you selected `use_docker`, MailHog is added as a Docker container. To use MailHog: - -1. Make sure, that ``mailhog`` docker container is up and running -2. Open your browser and go to ``http://127.0.0.1:8025`` +#. open up ``http://127.0.0.1:8025``. .. _Mailhog: https://github.com/mailhog/MailHog/ diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 8aae8f0bd..7885f45e8 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -3,74 +3,98 @@ Getting Up and Running Locally .. index:: pip, virtualenv, PostgreSQL -The steps below will get you up and running with a local development environment. We assume you have the following installed: -* pip -* virtualenv -* PostgreSQL +Setting Up Development Environment +---------------------------------- -First make sure to create and activate a virtualenv_. +Make sure to have the following on your host: -.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ +* virtualenv_; +* pip; +* PostgreSQL. -Then install the requirements for your local development:: +First things first. + +#. `Create a virtualenv`_. + +#. Activate the virtualenv you have just created. + +#. Install development requirements: :: $ pip install -r requirements/local.txt -Then, create a PostgreSQL database with the following command, where `[project_slug]` is what value you entered for your project's `project_slug`:: +#. Create a new PostgreSQL database (note: if this is the first time a database is created on your machine you might need to alter a localhost-related entry in your ``pg_hba.conf`` so as to utilize ``trust`` policy): :: - $ createdb [project_slug] + $ createdb -You can now run the usual Django ``migrate`` and ``runserver`` commands:: +#. Apply migrations: :: $ python manage.py migrate - $ python manage.py runserver -At this point you can take a break from setup and start getting to know the files in the project. +#. See the application being served through Django development server: :: -But if you want to go further with setup, read on. + $ python manage.py runserver 0.0.0.0:8000 -(Note: the following sections still need to be revised) +.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ +.. _`Create a virtualenv`: https://virtualenv.pypa.io/en/stable/userguide/ -Setting Up Env Vars for Production ------------------------------------ -`Cookiecutter Django` uses the excellent `django-environ`_ package, which includes a ``DATABASE_URL`` environment variable to simplify database configuration in your Django settings. +Setup Email Backend +------------------- -Rename env.example to .env to begin updating the file with your own environment variables. To add your database, define ``DATABASE_URL`` and add it to the .env file, as shown below: +MailHog +~~~~~~~ -.. parsed-literal:: +.. note:: In order for the project to support MailHog_ it must have been bootstrapped with ``use_mailhog`` set to ``y``. - DATABASE_URL="postgres://**:**\ @127.0.0.1:\ **/**" +MailHog is used to receive emails during development, it is written in Go and has no external dependencies. -.. _django-environ: http://django-environ.readthedocs.io +For instance, one of the packages we depend upon, ``django-allauth`` sends verification emails to new users signing up as well as to the existing ones who have not yet verified themselves. -Setup your email backend -------------------------- +#. `Download the latest MailHog release`_ for your OS. -django-allauth sends an email to verify users (and superusers) after signup and login (if they are still not verified). To send email you need to `configure your email backend`_ +#. Rename the build to ``MailHog``. -.. _configure your email backend: https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend +#. Copy the file to the project root. -In development you can (optionally) use MailHog_ for email testing. MailHog is built with Go so there are no dependencies. To use MailHog: +#. Make it executable: :: -1. `Download the latest release`_ for your operating system -2. Rename the executable to ``mailhog`` and copy it to the root of your project directory -3. Make sure it is executable (e.g. ``chmod +x mailhog``) -4. Execute mailhog from the root of your project in a new terminal window (e.g. ``./mailhog``) -5. All emails generated from your django app can be seen on http://127.0.0.1:8025/ + $ chmod +x MailHog -.. _Mailhog: https://github.com/mailhog/MailHog/ -.. _Download the latest release: https://github.com/mailhog/MailHog/releases +#. Spin up another terminal window and start it there: :: -Alternatively simply output emails to the console via: ``EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'`` + ./MailHog -In production basic email configuration is setup to send emails with Mailgun_ +#. Check out ``_ to see how it goes. + +Now you have your own mail server running locally, ready to receive whatever you send it. + +.. _MailHog: https://github.com/mailhog/MailHog/ +.. _`properly configured`: https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend + + +Console +~~~~~~~ + +.. note:: If you have generated your project with ``use_mailhog`` set to ``n`` this will be a default setup. + +Alternatively, deliver emails over console via ``EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'``. + +In production, we have Mailgun_ configured to have your back! .. _Mailgun: https://www.mailgun.com/ -**Live reloading and Sass CSS compilation** -If you’d like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with a little bit of `prep work`_. +Sass Compilation & Live Reloading +--------------------------------- -.. _prep work: https://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html +If you’d like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with a little bit of preparation_. + +.. _`Download the latest MailHog release`: https://github.com/mailhog/MailHog/releases +.. _preparation: https://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html + + +Summary +------- + +Congratulations, you have made it! Keep on reading to unleash full potential of Cookiecutter Django. diff --git a/docs/docker-postgres-backups.rst b/docs/docker-postgres-backups.rst index d3c7ca1d4..c1a8a5e0c 100644 --- a/docs/docker-postgres-backups.rst +++ b/docs/docker-postgres-backups.rst @@ -1,40 +1,87 @@ -============================ -Database Backups with Docker -============================ +PostgreSQL Backups with Docker +============================== -The database has to be running to create/restore a backup. These examples show local examples. If you want to use it on a remote server, remove ``-f local.yml`` from each example. +.. note:: For brevity it is assumed that you will be running the below commands against local environment, however, this is by no means mandatory so feel free to switch to ``production.yml`` when needed. -Running Backups -================ -Run the app with `docker-compose -f local.yml up`. +Prerequisites +------------- + +#. the project was generated with ``use_docker`` set to ``y``; +#. the stack is up and running: ``docker-compose -f local.yml up -d postgres``. + + +Creating a Backup +----------------- To create a backup, run:: - docker-compose -f local.yml run postgres backup + $ docker-compose -f local.yml exec postgres backup + +Assuming your project's database is named ``my_project`` here is what you will see: :: + + Backing up the 'my_project' database... + SUCCESS: 'my_project' database backup 'backup_2018_03_13T09_05_07.sql.gz' has been created and placed in '/backups'. + +Keep in mind that ``/backups`` is the ``postgres`` container directory. -To list backups, run:: +Viewing the Existing Backups +---------------------------- - docker-compose -f local.yml run postgres list-backups +To list existing backups, :: + + $ docker-compose -f local.yml exec postgres backups + +These are the sample contents of ``/backups``: :: + + These are the backups you have got: + total 24K + -rw-r--r-- 1 root root 5.2K Mar 13 09:05 backup_2018_03_13T09_05_07.sql.gz + -rw-r--r-- 1 root root 5.2K Mar 12 21:13 backup_2018_03_12T21_13_03.sql.gz + -rw-r--r-- 1 root root 5.2K Mar 12 21:12 backup_2018_03_12T21_12_58.sql.gz -To restore a backup, run:: +Copying Backups Locally +----------------------- - docker-compose -f local.yml run postgres restore filename.sql +If you want to copy backups from your ``postgres`` container locally, ``docker cp`` command_ will help you on that. -Where is the ID of the Postgres container. To get it, run:: +For example, given ``9c5c3f055843`` is the container ID copying all the backups over to a local directory is as simple as :: - docker ps + $ docker cp 9c5c3f055843:/backups ./backups -To copy the files from the running Postgres container to the host system:: +With a single backup file copied to ``.`` that would be :: - docker cp :/backups /host/path/target + $ docker cp 9c5c3f055843:/backups/backup_2018_03_13T09_05_07.sql.gz . -Restoring From Backups -====================== +.. _`command`: https://docs.docker.com/engine/reference/commandline/cp/ -To restore the production database to a local PostgreSQL database:: - createdb NAME_OF_DATABASE - psql NAME_OF_DATABASE < NAME_OF_BACKUP_FILE +Restoring from the Existing Backup +---------------------------------- + +To restore from one of the backups you have already got (take the ``backup_2018_03_13T09_05_07.sql.gz`` for example), :: + + $ docker-compose -f local.yml exec postgres restore backup_2018_03_13T09_05_07.sql.gz + +You will see something like :: + + Restoring the 'my_project' database from the '/backups/backup_2018_03_13T09_05_07.sql.gz' backup... + INFO: Dropping the database... + INFO: Creating a new database... + INFO: Applying the backup to the new database... + SET + SET + SET + SET + SET + set_config + ------------ + + (1 row) + + SET + # ... + ALTER TABLE + SUCCESS: The 'my_project' database has been restored from the '/backups/backup_2018_03_13T09_05_07.sql.gz' backup. diff --git a/docs/faq.rst b/docs/faq.rst index def4ba1f9..1481a8bac 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -1,5 +1,5 @@ FAQ -==== +=== .. index:: FAQ, 12-Factor App @@ -17,11 +17,11 @@ Why aren't you using just one configuration file (12-Factor App) ---------------------------------------------------------------------- TODO +.. TODO -Why doesn't this follow the layout from Two Scoops of Django 1.8? ----------------------------------------------------------------------- +Why doesn't this follow the layout from Two Scoops of Django? +------------------------------------------------------------- -You may notice that some elements of this project do not exactly match what we describe in chapter 3 of `Two Scoops of Django`_. The reason for that is this project, amongst other things, serves as a test bed for trying out new ideas and concepts. Sometimes they work, sometimes they don't, but the end result is that it won't necessarily match precisely what is described in the book I co-authored. +You may notice that some elements of this project do not exactly match what we describe in chapter 3 of `Two Scoops of Django 1.11`_. The reason for that is this project, amongst other things, serves as a test bed for trying out new ideas and concepts. Sometimes they work, sometimes they don't, but the end result is that it won't necessarily match precisely what is described in the book I co-authored. - -.. _`Two Scoops of Django`: http://twoscoopspress.com/products/two-scoops-of-django-1-8 +.. _Two Scoops of Django 1.11: https://www.twoscoopspress.com/collections/django/products/two-scoops-of-django-1-11 diff --git a/docs/index.rst b/docs/index.rst index 41a1138f4..c9f70ab14 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,7 +24,6 @@ Contents: docker-postgres-backups faq troubleshooting - my-favorite-cookie Indices and tables ================== diff --git a/docs/live-reloading-and-sass-compilation.rst b/docs/live-reloading-and-sass-compilation.rst index 7f978ede5..e2007cb02 100644 --- a/docs/live-reloading-and-sass-compilation.rst +++ b/docs/live-reloading-and-sass-compilation.rst @@ -1,5 +1,5 @@ -Live reloading and Sass CSS compilation -======================================= +Sass Compilation & Live Reloading +================================= If you'd like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with a little bit of prep work. @@ -15,7 +15,7 @@ If you don't already have it, install `compass` (doesn't hurt if you run this co Now you just need:: - $ grunt serve + $ npm run dev The base app will now run as it would with the usual ``manage.py runserver`` but with live reloading and Sass compilation enabled. diff --git a/docs/my-favorite-cookie.rst b/docs/my-favorite-cookie.rst deleted file mode 100644 index a65833526..000000000 --- a/docs/my-favorite-cookie.rst +++ /dev/null @@ -1,100 +0,0 @@ -************************************************ -Creating your first app with Cookiecutter-Django -************************************************ - -This tutorial will show you how to build a simple app using the `Cookiecutter Django `_ templating system. We'll be building a cookie polling app to determine the most popular flavor of cookie. - -Developers who have never used Django will learn the basics of creating a Django app; developers who are experienced with Django will learn how to set up a project within the Cookiecutter system. While many Django tutorials use the default SQLite database, Cookiecutter Django uses PostGres only, so we'll have you install and use that. - - -Dependencies -============ -This tutorial was written on Windows 10 using `git bash `_; alternate instructions for Mac OS and Linux will be provided when needed. Any Linux-style shell should work for the following commands. - -You should have your preferred versions of `Python `_ -and `Django `_ installed. Use the latest stable versions if you have no preference. - -You should have `Virtualenv `_ and `Cookiecutter `_ installed: - -.. code-block:: python - - $ pip install virtualenv - $ pip install cookiecutter - -You should also have `PostgreSQL `_ installed on your machine--just download and run the installer for your OS. The install menu will prompt you for a password, which you'll use when creating the project's database. - - -Instructions -============ - -1. **Setup** -- how to set up a virtual environment -2. **Cookiecutter** -- use Cookiecutter to initialize a project with your own customized information. -3. **Building the App** -- creating the My Favorite Cookie application. - -============ -1. Setup -============ - -Virtual Environment -""""""""""""""""""" - -Create a virtual environment for your project. Cookiecutter will install a bunch of dependencies for you automatically; using a virtualenv will prevent this from interfering with your other work. - -.. code-block:: python - - $ virtualenv c:/.virtualenvs/cookie_polls - -Replace ``c:/.virtualenvs`` with the path to your own ``.virtualenvs`` folder. - -Activate the virtual environment by calling ``source`` on the ``activate`` shell script . On Windows you'll call this from the virtualenv's ``scripts`` folder: - -.. code-block:: python - - $ source /path/to/.virtualenvs/cookie_polls/scripts/activate - -On other operating systems, it'll be found in the ``bin`` folder. - -.. code-block:: python - - $ source /path/to/.virtualenvs/cookie_polls/bin/activate - -You'll know the virtual environment is active because its name will appear in parentheses before the command prompt. When you're done with this project, you can leave the virtual environment with the ``deactivate`` command. - -.. code-block:: python - - (cookie_polls) - $ deactivate - - -Now you're ready to create your project using Cookiecutter. - - -=============== -2. Cookiecutter -=============== - -Django developers may be familiar with the ``startproject`` command, which initializes the directory structure and required files for a bare-bones Django project. While this is fine when you're just learning Django for the first time, it's not great for a real production app. Cookiecutter takes care of a lot of standard tasks for you, including installing software dependencies, setting up testing files, and including and organizing common libraries like Bootstrap and AngularJS. It also generates a software license and a README. - -Change directories into the folder where you want your project to live, and run ``cookiecutter`` followed by the URL of Cookiecutter's Github repo. - -.. code-block:: python - - $ cd /my/project/folder - (cookie_polls) - my/project/folder - $ cookiecutter https://github.com/pydanny/cookiecutter-django - -This will prompt you for a bunch of values specific to your project. Press "enter" without typing anything to use the default values, which are shown in [brackets] after the question. You can learn about all the different options `here, `_ but for now we'll use the defaults for everything but your name, your email, the project's name, and the project's description. - -.. code-block:: python - - project_name [project_name]: My Favorite Cookie - project_slug [My_Favorite_Cookie]: - author_name [Your Name]: Emily Cain - email [Your email]: contact@emcain.net - description [A short description of the project.]: Poll your friends to determine the most popular cookie. - -Then hit "enter" to use the default values for everything else. - - - diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index d1d36324a..60453b870 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -1,84 +1,32 @@ Project Generation Options ========================== -project_name [project_name]: - Your human-readable project name, including any capitalization or spaces. +project_name: + Your project's human-readable name, capitals and spaces allowed. -project_slug [project_name]: - The slug of your project, without dashes or spaces. Used to name your repo +project_slug: + Your project's slug without dashes or spaces. Used to name your repo and in other places where a Python-importable version of your project name is needed. -author_name [Your Name]: - You! This goes into places like the LICENSE file. +description: + Describes your project and gets used in places like ``README.rst`` and such. -email [Your email]: - Your email address. +author_name: + This is you! The value goes into places like ``LICENSE`` and such. -description [A short description of the project.] - Used in the generated README.rst and other places. +email: + The email address you want to identify yourself in the project. -domain_name [example.com] - Whatever domain name you plan to use for your project when it goes live. +domain_name: + The domain name you plan to use for your project once it goes live. + Note that it can be safely changed later on whenever you need to. -version [0.1.0] - The starting version number for your project. +version: + The version of the project at its inception. -timezone [UTC] - Used in the base settings file for the `TIME_ZONE` value. - -use_whitenoise [y] - Whether to use WhiteNoise_ for static file serving. - -use_celery [n] - Whether to use Celery_. This gives you the ability to use distributed task - queues in your project. - -use_mailhog [n] - Whether to use MailHog_. MailHog is a tool that simulates email receiving - for development purposes. It runs a simple SMTP server which catches - any message sent to it. Messages are displayed in a web interface which - runs at ``http://localhost:8025/`` You need to download the MailHog - executable for your operating system, see the 'Developing Locally' docs - for instructions. - -use_sentry_for_error_reporting [n] - Whether to use Sentry_ to log errors from your project. - -use_opbeat [n] - Whether to use Opbeat_ for preformance monitoring and code optimization. - -use_pycharm [n] - Adds support for developing in PyCharm_ with a preconfigured .idea directory. - -windows [n] - Whether you'll be developing on Windows. - -use_docker [y] - Whether to use Docker_, separating the app and database into separate - containers. - -use_heroku [n] - Add configuration to deploy the application to a Heroku_ instance. - -use_compressor [n] - Use `Django Compressor`_ to minify and combine rendered JavaScript and CSS - into cachable static resources. - -js_task_runner [1] - Select a JavaScript task runner. The choices are: - - 1. Gulp_ - 2. Grunt_ - 3. None - -custom_bootstrap_compilation [n] - Scaffold out recompiling Bootstrap as as task, with Gulp_ or Grunt_. - Useful for letting you change Bootstrap variables in real time. - Consult project README for more details. - -open_source_license [1] - Select a software license for the project. The choices are: +open_source_license: + A software license for the project. The choices are: 1. MIT_ 2. BSD_ @@ -86,23 +34,96 @@ open_source_license [1] 4. `Apache Software License 2.0`_ 5. Not open source -**NOTE:** *If you choose to use Docker, selecting a JavaScript task runner is -not supported out of the box.* +timezone: + The value to be used for the ``TIME_ZONE`` setting of the project. + +windows: + Indicates whether the project should be configured for development on Windows. + +use_pycharm: + Indicates whether the project should be configured for development with PyCharm_. + +use_docker: + Indicates whether the project should be configured to use Docker_ and `Docker Compose`_. + +postgresql_version: + Select a PostgreSQL_ version to use. The choices are: + + 1. 10.3 + 2. 10.2 + 3. 10.1 + 4. 9.6 + 5. 9.5 + 6. 9.4 + 7. 9.3 + +js_task_runner: + Select a JavaScript task runner. The choices are: + + 1. None + 2. Gulp_ + +custom_bootstrap_compilation: + Indicates whether the project should support Bootstrap recompilation + via the selected JavaScript task runner's task. This can be useful + for real-time Bootstrap variable alteration. + +use_compressor: + Indicates whether the project should be configured to use `Django Compressor`_. + +use_celery: + Indicates whether the project should be configured to use Celery_. + +use_mailhog: + Indicates whether the project should be configured to use MailHog_. + +use_sentry: + Indicates whether the project should be configured to use Sentry_. + +use_whitenoise: + Indicates whether the project should be configured to use WhiteNoise_. + +use_heroku: + Indicates whether the project should be configured so as to be deployable + to Heroku_. + +use_travisci: + Indicates whether the project should be configured to use `Travis CI`_. + +keep_local_envs_in_vcs: + Indicates whether the project's ``.envs/.local/`` should be kept in VCS + (comes in handy when working in teams where local environment reproducibility + is strongly encouraged). + +debug: + Indicates whether the project should be configured for debugging. + This option is relevant for Cookiecutter Django developers only. + -.. _WhiteNoise: https://github.com/evansd/whitenoise -.. _Celery: https://github.com/celery/celery -.. _MailHog: https://github.com/mailhog/MailHog -.. _Sentry: https://github.com/getsentry/sentry -.. _Opbeat: https://github.com/opbeat/opbeat_python -.. _PyCharm: https://www.jetbrains.com/pycharm/ -.. _Docker: https://github.com/docker/docker -.. _Heroku: https://github.com/heroku/heroku-buildpack-python -.. _Django Compressor: https://github.com/django-compressor/django-compressor -.. _Gulp: https://github.com/gulpjs/gulp -.. _Grunt: https://github.com/gruntjs/grunt -.. _Webpack: https://github.com/webpack/webpack -.. _Let's Encrypt: https://github.com/certbot/certbot .. _MIT: https://opensource.org/licenses/MIT .. _BSD: https://opensource.org/licenses/BSD-3-Clause .. _GPLv3: https://www.gnu.org/licenses/gpl.html .. _Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0 + +.. _PyCharm: https://www.jetbrains.com/pycharm/ + +.. _Docker: https://github.com/docker/docker +.. _Docker Compose: https://docs.docker.com/compose/ + +.. _PostgreSQL: https://www.postgresql.org/docs/ + +.. _Gulp: https://github.com/gulpjs/gulp + +.. _Django Compressor: https://github.com/django-compressor/django-compressor + +.. _Celery: https://github.com/celery/celery + +.. _MailHog: https://github.com/mailhog/MailHog + +.. _Sentry: https://github.com/getsentry/sentry + +.. _WhiteNoise: https://github.com/evansd/whitenoise + +.. _Heroku: https://github.com/heroku/heroku-buildpack-python + +.. _Travis CI: https://travis-ci.org/ diff --git a/docs/settings.rst b/docs/settings.rst index 20bf9e5e1..6e71a5151 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -18,7 +18,7 @@ DJANGO_READ_DOT_ENV_FILE READ_DOT_ENV_FILE False ======================================= =========================== ============================================== ====================================================================== Environment Variable Django Setting Development Default Production Default ======================================= =========================== ============================================== ====================================================================== -DJANGO_ADMIN_URL n/a r'^admin/' raises error +DJANGO_ADMIN_URL n/a 'admin/' raises error DJANGO_CACHES CACHES (default) locmem redis DJANGO_DATABASES DATABASES (default) See code See code DJANGO_DEBUG DEBUG True False @@ -44,17 +44,13 @@ Environment Variable Django Setting Development DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error -DJANGO_SENTRY_DSN SENTRY_DSN n/a raises error +SENTRY_DSN SENTRY_DSN n/a raises error DJANGO_SENTRY_CLIENT SENTRY_CLIENT n/a raven.contrib.django.raven_compat.DjangoClient DJANGO_SENTRY_LOG_LEVEL SENTRY_LOG_LEVEL n/a logging.INFO -DJANGO_MAILGUN_API_KEY MAILGUN_ACCESS_KEY n/a raises error -DJANGO_MAILGUN_SERVER_NAME MAILGUN_SERVER_NAME n/a raises error -MAILGUN_SENDER_DOMAIN MAILGUN_SENDER_DOMAIN n/a raises error +MAILGUN_API_KEY MAILGUN_ACCESS_KEY n/a raises error +MAILGUN_DOMAIN MAILGUN_SENDER_DOMAIN n/a raises error NEW_RELIC_APP_NAME NEW_RELIC_APP_NAME n/a raises error NEW_RELIC_LICENSE_KEY NEW_RELIC_LICENSE_KEY n/a raises error -DJANGO_OPBEAT_APP_ID OPBEAT['APP_ID'] n/a raises error -DJANGO_OPBEAT_SECRET_TOKEN OPBEAT['SECRET_TOKEN'] n/a raises error -DJANGO_OPBEAT_ORGANIZATION_ID OPBEAT['ORGANIZATION_ID'] n/a raises error ======================================= =========================== ============================================== ====================================================================== -------------------------- diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index fe121b9cd..0c827acf4 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -3,7 +3,10 @@ Troubleshooting This page contains some advice about errors and problems commonly encountered during the development of Cookiecutter Django applications. -#. If you get the error ``jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'.`` , please upgrade your cookiecutter version to >= 1.4 (see issue # 528_ ) #. ``project_slug`` must be a valid Python module name or you will have issues on imports. -.. _528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 \ No newline at end of file +#. ``jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'.``: please upgrade your cookiecutter version to >= 1.4 (see `#528`_) + +#. Internal server error on user registration: make sure you have configured the mail backend (e.g. Mailgun) by adding the API key and sender domain + +.. _#528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 0e16ffb70..6b48471e5 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -7,12 +7,12 @@ NOTE: TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only """ +from __future__ import print_function import os import random import shutil import string -import sys try: # Inspired by @@ -22,113 +22,81 @@ try: except NotImplementedError: using_sysrandom = False -PROJECT_DIR_PATH = os.path.realpath(os.path.curdir) +TERMINATOR = "\x1b[0m" +WARNING = "\x1b[1;33m [WARNING]: " +INFO = "\x1b[1;33m [INFO]: " +HINT = "\x1b[3;33m" +SUCCESS = "\x1b[1;32m [SUCCESS]: " + +DEBUG_VALUE = "debug" -def remove_file(file_path): - if os.path.exists(file_path): - os.remove(file_path) - - -def remove_open_source_project_only_files(): - file_names = [ - 'CONTRIBUTORS.txt', - ] +def remove_open_source_files(): + file_names = ["CONTRIBUTORS.txt"] for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_gplv3_files(): - file_names = [ - 'COPYING', - ] + file_names = ["COPYING"] for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_pycharm_files(): - idea_dir_path = os.path.join(PROJECT_DIR_PATH, '.idea') + idea_dir_path = ".idea" if os.path.exists(idea_dir_path): shutil.rmtree(idea_dir_path) - docs_dir_path = os.path.join(PROJECT_DIR_PATH, 'docs', 'pycharm') + docs_dir_path = os.path.join("docs", "pycharm") if os.path.exists(docs_dir_path): shutil.rmtree(docs_dir_path) def remove_docker_files(): - shutil.rmtree(os.path.join(PROJECT_DIR_PATH, 'compose')) + shutil.rmtree("compose") - file_names = [ - 'local.yml', - 'production.yml', - '.dockerignore', - ] + file_names = ["local.yml", "production.yml", ".dockerignore"] for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_heroku_files(): - file_names = [ - 'Procfile', - 'runtime.txt', - ] + file_names = ["Procfile", "runtime.txt", "requirements.txt"] for file_name in file_names: - remove_file(os.path.join(PROJECT_DIR_PATH, file_name)) - - -def remove_paas_files(): - none_paas_files_left = True - - if '{{ cookiecutter.use_heroku }}'.lower() == 'n': - remove_heroku_files() - none_paas_files_left &= True - else: - none_paas_files_left &= False - - if none_paas_files_left: - remove_file(os.path.join(PROJECT_DIR_PATH, 'requirements.txt')) - - -def remove_grunt_files(): - file_names = [ - 'Gruntfile.js', - ] - for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_gulp_files(): - file_names = [ - 'gulpfile.js', - ] + file_names = ["gulpfile.js"] for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_packagejson_file(): - file_names = [ - 'package.json', - ] + file_names = ["package.json"] for file_name in file_names: - os.remove(os.path.join(PROJECT_DIR_PATH, file_name)) + os.remove(file_name) def remove_celery_app(): - shutil.rmtree(os.path.join(PROJECT_DIR_PATH, '{{ cookiecutter.project_slug }}', 'taskapp')) + shutil.rmtree(os.path.join("{{ cookiecutter.project_slug }}", "taskapp")) + + +def remove_dottravisyml_file(): + os.remove(".travis.yml") def append_to_project_gitignore(path): - gitignore_file_path = os.path.join(PROJECT_DIR_PATH, '.gitignore') - with open(gitignore_file_path, 'a') as gitignore_file: + gitignore_file_path = ".gitignore" + with open(gitignore_file_path, "a") as gitignore_file: gitignore_file.write(path) gitignore_file.write(os.linesep) -def generate_random_string(length, - using_digits=False, - using_ascii_letters=False, - using_punctuation=False): +def generate_random_string( + length, using_digits=False, using_ascii_letters=False, using_punctuation=False +): """ Example: opting out for 50 symbol-long, [a-z][A-Z][0-9] string @@ -143,30 +111,26 @@ def generate_random_string(length, if using_ascii_letters: symbols += string.ascii_letters if using_punctuation: - symbols += string.punctuation \ - .replace('"', '') \ - .replace("'", '') \ - .replace('\\', '') - return ''.join([random.choice(symbols) for _ in range(length)]) + symbols += string.punctuation.replace('"', "").replace("'", "").replace( + "\\", "" + ) + return "".join([random.choice(symbols) for _ in range(length)]) -def set_flag(file_path, - flag, - value=None, - *args, - **kwargs): +def set_flag(file_path, flag, value=None, formatted=None, *args, **kwargs): if value is None: random_string = generate_random_string(*args, **kwargs) if random_string is None: - import sys - sys.stdout.write( + print( "We couldn't find a secure pseudo-random number generator on your system. " "Please, make sure to manually {} later.".format(flag) ) random_string = flag + if formatted is not None: + random_string = formatted.format(random_string) value = random_string - with open(file_path, 'r+') as f: + with open(file_path, "r+") as f: file_contents = f.read().replace(flag, value) f.seek(0) f.write(file_contents) @@ -178,106 +142,151 @@ def set_flag(file_path, def set_django_secret_key(file_path): django_secret_key = set_flag( file_path, - '!!!SET DJANGO_SECRET_KEY!!!', - length=50, + "!!!SET DJANGO_SECRET_KEY!!!", + length=64, using_digits=True, - using_ascii_letters=True + using_ascii_letters=True, ) return django_secret_key -def set_postgres_user(file_path, - value=None): +def set_django_admin_url(file_path): + django_admin_url = set_flag( + file_path, + "!!!SET DJANGO_ADMIN_URL!!!", + formatted="{}/", + length=32, + using_digits=True, + using_ascii_letters=True, + ) + return django_admin_url + + +def generate_postgres_user(debug=False): + return DEBUG_VALUE if debug else generate_random_string(length=32, using_ascii_letters=True) + + +def set_postgres_user(file_path, value): postgres_user = set_flag( file_path, - '!!!SET POSTGRES_USER!!!', + "!!!SET POSTGRES_USER!!!", value=value, - length=8, - using_ascii_letters=True ) return postgres_user -def set_postgres_password(file_path): +def set_postgres_password(file_path, value=None): postgres_password = set_flag( file_path, - '!!!SET POSTGRES_PASSWORD!!!', - length=42, + "!!!SET POSTGRES_PASSWORD!!!", + value=value, + length=64, using_digits=True, - using_ascii_letters=True + using_ascii_letters=True, ) return postgres_password -def initialize_dotenv(postgres_user): - # Initializing `env.example` first. - envexample_file_path = os.path.join(PROJECT_DIR_PATH, 'env.example') - set_django_secret_key(envexample_file_path) - set_postgres_user(envexample_file_path, value=postgres_user) - set_postgres_password(envexample_file_path) - # Renaming `env.example` to `.env`. - dotenv_file_path = os.path.join(PROJECT_DIR_PATH, '.env') - shutil.move(envexample_file_path, dotenv_file_path) +def append_to_gitignore_file(s): + with open(".gitignore", "a") as gitignore_file: + gitignore_file.write(s) + gitignore_file.write(os.linesep) -def initialize_localyml(postgres_user): - set_postgres_user(os.path.join(PROJECT_DIR_PATH, 'local.yml'), value=postgres_user) +def set_flags_in_envs(postgres_user, debug=False): + local_postgres_envs_path = os.path.join(".envs", ".local", ".postgres") + set_postgres_user(local_postgres_envs_path, value=postgres_user) + set_postgres_password(local_postgres_envs_path, value=DEBUG_VALUE if debug else None) + + production_django_envs_path = os.path.join(".envs", ".production", ".django") + set_django_secret_key(production_django_envs_path) + set_django_admin_url(production_django_envs_path) + + production_postgres_envs_path = os.path.join(".envs", ".production", ".postgres") + set_postgres_user(production_postgres_envs_path, value=postgres_user) + set_postgres_password(production_postgres_envs_path, value=DEBUG_VALUE if debug else None) -def initialize_local_settings(): - set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'local.py')) +def set_flags_in_settings_files(): + set_django_secret_key(os.path.join("config", "settings", "local.py")) + set_django_secret_key(os.path.join("config", "settings", "test.py")) -def initialize_test_settings(): - set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'test.py')) +def remove_envs_and_associated_files(): + shutil.rmtree(".envs") + os.remove("merge_production_dotenvs_in_dotenv.py") + + +def remove_celery_compose_dirs(): + shutil.rmtree(os.path.join("compose", "local", "django", "celery")) + shutil.rmtree(os.path.join("compose", "production", "django", "celery")) def main(): - postgres_user = generate_random_string(length=16, using_ascii_letters=True) - initialize_dotenv(postgres_user) - initialize_localyml(postgres_user) - initialize_local_settings() - initialize_test_settings() + postgres_user = generate_postgres_user(debug="{{ cookiecutter.debug }}".lower() == "y") + set_flags_in_envs(postgres_user, debug="{{ cookiecutter.debug }}".lower() == "y") + set_flags_in_settings_files() - if '{{ cookiecutter.open_source_license }}' == 'Not open source': - remove_open_source_project_only_files() - elif '{{ cookiecutter.open_source_license}}' != 'GPLv3': + if "{{ cookiecutter.open_source_license }}" == "Not open source": + remove_open_source_files() + if "{{ cookiecutter.open_source_license}}" != "GPLv3": remove_gplv3_files() - if '{{ cookiecutter.use_pycharm }}'.lower() == 'n': + if "{{ cookiecutter.use_pycharm }}".lower() == "n": remove_pycharm_files() - if '{{ cookiecutter.use_docker }}'.lower() == 'n': + if "{{ cookiecutter.use_docker }}".lower() == "n": remove_docker_files() - remove_paas_files() + if "{{ cookiecutter.use_heroku }}".lower() == "n": + remove_heroku_files() - if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp': - remove_grunt_files() - elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': - remove_gulp_files() + if ( + "{{ cookiecutter.use_docker }}".lower() == "n" + and "{{ cookiecutter.use_heroku }}".lower() == "n" + ): + if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y": + print( + INFO + ".env(s) are only utilized when Docker Compose and/or " + "Heroku support is enabled so keeping them does not " + "make sense given your current setup." + TERMINATOR + ) + remove_envs_and_associated_files() else: - remove_gulp_files() - remove_grunt_files() - remove_packagejson_file() + append_to_gitignore_file(".env") + append_to_gitignore_file(".envs/*") + if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y": + append_to_gitignore_file("!.envs/.local/") - if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] \ - and '{{ cookiecutter.use_docker }}'.lower() == 'y': - TERMINATOR = "\x1b[0m" - INFO = "\x1b[1;33m [INFO]: " - sys.stdout.write( - INFO + - "Docker and {} JS task runner ".format('{{ cookiecutter.js_task_runner }}'.lower().capitalize()) + - "working together not supported yet. " - "You can continue using the generated project like you normally would, " - "however you would need to add a JS task runner service " - "to your Docker Compose configuration manually." + - TERMINATOR + if "{{ cookiecutter.js_task_runner}}".lower() == "none": + remove_gulp_files() + remove_packagejson_file() + if ( + "{{ cookiecutter.js_task_runner }}".lower() != "none" + and "{{ cookiecutter.use_docker }}".lower() == "y" + ): + print( + WARNING + + "Docker and {} JS task runner ".format( + "{{ cookiecutter.js_task_runner }}".lower().capitalize() + ) + + "working together not supported yet. " + "You can continue using the generated project like you " + "normally would, however you would need to add a JS " + "task runner service to your Docker Compose configuration " + "manually." + TERMINATOR ) - if '{{ cookiecutter.use_celery }}'.lower() == 'n': + if "{{ cookiecutter.use_celery }}".lower() == "n": remove_celery_app() + if "{{ cookiecutter.use_docker }}".lower() == "y": + remove_celery_compose_dirs() + + if "{{ cookiecutter.use_travisci }}".lower() == "n": + remove_dottravisyml_file() + + print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index a65fedae8..b7f4dfbbb 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -6,54 +6,51 @@ NOTE: TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only """ +from __future__ import print_function -project_slug = '{{ cookiecutter.project_slug }}' -if hasattr(project_slug, 'isidentifier'): - assert project_slug.isidentifier(), "'{}' project slug is not a valid Python identifier.".format(project_slug) +import sys -using_docker = '{{ cookiecutter.use_docker }}'.lower() -if using_docker == 'n': - TERMINATOR = "\x1b[0m" - WARNING = "\x1b[1;33m [WARNING]: " - INFO = "\x1b[1;33m [INFO]: " - HINT = "\x1b[3;33m" - SUCCESS = "\x1b[1;32m [SUCCESS]: " +TERMINATOR = "\x1b[0m" +WARNING = "\x1b[1;33m [WARNING]: " +INFO = "\x1b[1;33m [INFO]: " +HINT = "\x1b[3;33m" +SUCCESS = "\x1b[1;32m [SUCCESS]: " - import sys +project_slug = "{{ cookiecutter.project_slug }}" +if hasattr(project_slug, "isidentifier"): + assert project_slug.isidentifier(), "'{}' project slug is not a valid Python identifier.".format( + project_slug + ) +assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name." + +if "{{ cookiecutter.use_docker }}".lower() == "n": python_major_version = sys.version_info[0] if python_major_version == 2: - sys.stdout.write( - WARNING + - "Cookiecutter Django does not support Python 2. " + print( + WARNING + "Cookiecutter Django does not support Python 2. " "Stability is guaranteed with Python 3.6+ only, " - "are you sure you want to proceed (y/n)? " + - TERMINATOR + "are you sure you want to proceed (y/n)? " + TERMINATOR ) - yes_options, no_options = frozenset(['y']), frozenset(['n']) + yes_options, no_options = frozenset(["y"]), frozenset(["n"]) while True: choice = raw_input().lower() if choice in yes_options: break + elif choice in no_options: - sys.stdout.write( - INFO + - "Generation process stopped as requested." + - TERMINATOR - ) + print(INFO + "Generation process stopped as requested." + TERMINATOR) sys.exit(1) else: - sys.stdout.write( - HINT + - "Please respond with {} or {}: ".format( - ', '.join(["'{}'".format(o) for o in yes_options if not o == '']), - ', '.join(["'{}'".format(o) for o in no_options if not o == '']) - ) + - TERMINATOR + print( + HINT + + "Please respond with {} or {}: ".format( + ", ".join( + ["'{}'".format(o) for o in yes_options if not o == ""] + ), + ", ".join( + ["'{}'".format(o) for o in no_options if not o == ""] + ), + ) + + TERMINATOR ) - - sys.stdout.write( - SUCCESS + - "Project initialized, keep up the good work!" + - TERMINATOR - ) diff --git a/setup.cfg b/pytest.ini similarity index 88% rename from setup.cfg rename to pytest.ini index 140796cff..c5b301991 100644 --- a/setup.cfg +++ b/pytest.ini @@ -1,3 +1,3 @@ -[tool:pytest] +[pytest] python_paths = . norecursedirs = .tox .git */migrations/* */static/* docs venv */{{cookiecutter.project_slug}}/* diff --git a/requirements.txt b/requirements.txt index 1790a0216..9f378fdaa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,13 @@ cookiecutter==1.6.0 -flake8==3.5.0 # pyup: != 2.6.0 sh==1.12.14 binaryornot==0.4.4 +# Code quality +# ------------------------------------------------------------------------------ +flake8==3.5.0 + # Testing -pytest==3.3.2 -pycodestyle==2.3.1 -pyflakes==1.6.0 -tox==2.9.1 +# ------------------------------------------------------------------------------ +tox==3.0.0 +pytest==3.6.1 pytest-cookies==0.3.0 diff --git a/requirements_to_watch.txt b/requirements_to_watch.txt deleted file mode 100644 index 91f0041bf..000000000 --- a/requirements_to_watch.txt +++ /dev/null @@ -1,2 +0,0 @@ -# These requirements prevented an upgrade to Django 1.11. -django-autoslug==1.9.3 diff --git a/setup.py b/setup.py index 56306f92d..65bcd8fcf 100644 --- a/setup.py +++ b/setup.py @@ -10,43 +10,42 @@ except ImportError: # Our version ALWAYS matches the version of Django we support # If Django has a new release, we branch, tag, then update this setting after the tag. -version = '1.11.9' +version = "2.0.2" -if sys.argv[-1] == 'tag': +if sys.argv[-1] == "tag": os.system('git tag -a %s -m "version %s"' % (version, version)) - os.system('git push --tags') + os.system("git push --tags") sys.exit() -with open('README.rst') as readme_file: +with open("README.rst") as readme_file: long_description = readme_file.read() setup( - name='cookiecutter-django', + name="cookiecutter-django", version=version, - description='A Cookiecutter template for creating production-ready Django projects quickly.', + description="A Cookiecutter template for creating production-ready Django projects quickly.", long_description=long_description, - author='Daniel Roy Greenfeld', - author_email='pydanny@gmail.com', - url='https://github.com/pydanny/cookiecutter-django', + author="Daniel Roy Greenfeld", + author_email="pydanny@gmail.com", + url="https://github.com/pydanny/cookiecutter-django", packages=[], - license='BSD', + license="BSD", zip_safe=False, classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Framework :: Django :: 1.11', - 'Intended Audience :: Developers', - 'Natural Language :: English', - 'License :: OSI Approved :: BSD License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Topic :: Software Development', + "Development Status :: 4 - Beta", + "Environment :: Console", + "Framework :: Django :: 2.0", + "Intended Audience :: Developers", + "Natural Language :: English", + "License :: OSI Approved :: BSD License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Software Development", ], keywords=( - 'cookiecutter, Python, projects, project templates, django, ' - 'skeleton, scaffolding, project directory, setup.py' + "cookiecutter, Python, projects, project templates, django, " + "skeleton, scaffolding, project directory, setup.py" ), ) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index acbc2c09b..cf173576b 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -5,21 +5,21 @@ import sh import pytest from binaryornot.check import is_binary -PATTERN = '{{(\s?cookiecutter)[.](.*?)}}' +PATTERN = "{{(\s?cookiecutter)[.](.*?)}}" RE_OBJ = re.compile(PATTERN) @pytest.fixture def context(): return { - 'project_name': 'My Test Project', - 'project_slug': 'my_test_project', - 'author_name': 'Test Author', - 'email': 'test@example.com', - 'description': 'A short description of the project.', - 'domain_name': 'example.com', - 'version': '0.1.0', - 'timezone': 'UTC', + "project_name": "My Test Project", + "project_slug": "my_test_project", + "author_name": "Test Author", + "email": "test@example.com", + "description": "A short description of the project.", + "domain_name": "example.com", + "version": "0.1.0", + "timezone": "UTC", } @@ -40,9 +40,10 @@ def check_paths(paths): for path in paths: if is_binary(path): continue - for line in open(path, 'r'): + + for line in open(path, "r"): match = RE_OBJ.search(line) - msg = 'cookiecutter variable not replaced in {}' + msg = "cookiecutter variable not replaced in {}" assert match is None, msg.format(path) @@ -50,7 +51,7 @@ def test_default_configuration(cookies, context): result = cookies.bake(extra_context=context) assert result.exit_code == 0 assert result.exception is None - assert result.project.basename == context['project_slug'] + assert result.project.basename == context["project_slug"] assert result.project.isdir() paths = build_files_list(str(result.project)) @@ -58,9 +59,9 @@ def test_default_configuration(cookies, context): check_paths(paths) -@pytest.fixture(params=['use_mailhog', 'use_celery', 'windows']) +@pytest.fixture(params=["use_mailhog", "use_celery", "windows"]) def feature_context(request, context): - context.update({request.param: 'y'}) + context.update({request.param: "y"}) return context @@ -68,7 +69,7 @@ def test_enabled_features(cookies, feature_context): result = cookies.bake(extra_context=feature_context) assert result.exit_code == 0 assert result.exception is None - assert result.project.basename == feature_context['project_slug'] + assert result.project.basename == feature_context["project_slug"] assert result.project.isdir() paths = build_files_list(str(result.project)) diff --git a/tests/test_docker.sh b/tests/test_docker.sh index 137694d7a..bebac1488 100755 --- a/tests/test_docker.sh +++ b/tests/test_docker.sh @@ -11,11 +11,14 @@ mkdir -p .cache/docker cd .cache/docker # create the project using the default settings in cookiecutter.json -cookiecutter ../../ --no-input --overwrite-if-exists use_docker=y js_task_runner=None -cd project_name +cookiecutter ../../ --no-input --overwrite-if-exists use_docker=y +cd my_awesome_project # run the project's tests docker-compose -f local.yml run django python manage.py test # return non-zero status code if there are migrations that have not been created docker-compose -f local.yml run django python manage.py makemigrations --dry-run --check || { echo "ERROR: there were changes in the models, but migration listed above have not been created and are not saved in version control"; exit 1; } + +# Test support for translations +docker-compose -f local.yml run django python manage.py makemessages diff --git a/tox.ini b/tox.ini index a16b80ed6..040c8a41c 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,5 @@ skipsdist = true envlist = py36 [testenv] -passenv = LC_ALL, LANG, HOME -deps = - binaryornot - flake8==2.5.5 - pytest-cookies - sh -commands = py.test {posargs:tests} +deps = -rrequirements.txt +commands = pytest {posargs:./tests} diff --git a/{{cookiecutter.project_slug}}/.envs/.local/.django b/{{cookiecutter.project_slug}}/.envs/.local/.django new file mode 100644 index 000000000..8aa9a9946 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.envs/.local/.django @@ -0,0 +1,7 @@ +# General +# ------------------------------------------------------------------------------ +USE_DOCKER=yes + +# Redis +# ------------------------------------------------------------------------------ +REDIS_URL=redis://redis:6379/0 diff --git a/{{cookiecutter.project_slug}}/.envs/.local/.postgres b/{{cookiecutter.project_slug}}/.envs/.local/.postgres new file mode 100644 index 000000000..f190db8e6 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.envs/.local/.postgres @@ -0,0 +1,7 @@ +# PostgreSQL +# ------------------------------------------------------------------------------ +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_DB={{ cookiecutter.project_slug }} +POSTGRES_USER=!!!SET POSTGRES_USER!!! +POSTGRES_PASSWORD=!!!SET POSTGRES_PASSWORD!!! diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.caddy b/{{cookiecutter.project_slug}}/.envs/.production/.caddy new file mode 100644 index 000000000..83d7fc7af --- /dev/null +++ b/{{cookiecutter.project_slug}}/.envs/.production/.caddy @@ -0,0 +1,3 @@ +# Caddy +# ------------------------------------------------------------------------------ +DOMAIN_NAME={{ cookiecutter.domain_name }} diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.django b/{{cookiecutter.project_slug}}/.envs/.production/.django new file mode 100644 index 000000000..5cb90897b --- /dev/null +++ b/{{cookiecutter.project_slug}}/.envs/.production/.django @@ -0,0 +1,45 @@ +# General +# ------------------------------------------------------------------------------ +# DJANGO_READ_DOT_ENV_FILE=True +DJANGO_SETTINGS_MODULE=config.settings.production +DJANGO_SECRET_KEY=!!!SET DJANGO_SECRET_KEY!!! +DJANGO_ADMIN_URL=!!!SET DJANGO_ADMIN_URL!!! +DJANGO_ALLOWED_HOSTS=.{{ cookiecutter.domain_name }} + +# Security +# ------------------------------------------------------------------------------ +# TIP: better off using DNS, however, redirect is OK too +DJANGO_SECURE_SSL_REDIRECT=False + +# Email +# ------------------------------------------------------------------------------ +MAILGUN_API_KEY= +DJANGO_SERVER_EMAIL= +MAILGUN_DOMAIN= + +# AWS +# ------------------------------------------------------------------------------ +DJANGO_AWS_ACCESS_KEY_ID= +DJANGO_AWS_SECRET_ACCESS_KEY= +DJANGO_AWS_STORAGE_BUCKET_NAME= + +# django-allauth +# ------------------------------------------------------------------------------ +DJANGO_ACCOUNT_ALLOW_REGISTRATION=True +{% if cookiecutter.use_compressor == 'y' %} +# django-compressor +# ------------------------------------------------------------------------------ +COMPRESS_ENABLED= +{% endif %} +# Gunicorn +# ------------------------------------------------------------------------------ +WEB_CONCURRENCY=4 +{% if cookiecutter.use_sentry == 'y' %} +# Sentry +# ------------------------------------------------------------------------------ +SENTRY_DSN= +{% endif %} + +# Redis +# ------------------------------------------------------------------------------ +REDIS_URL=redis://redis:6379/0 diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.postgres b/{{cookiecutter.project_slug}}/.envs/.production/.postgres new file mode 100644 index 000000000..f190db8e6 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.envs/.production/.postgres @@ -0,0 +1,7 @@ +# PostgreSQL +# ------------------------------------------------------------------------------ +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_DB={{ cookiecutter.project_slug }} +POSTGRES_USER=!!!SET POSTGRES_USER!!! +POSTGRES_PASSWORD=!!!SET POSTGRES_PASSWORD!!! diff --git a/{{cookiecutter.project_slug}}/.gitignore b/{{cookiecutter.project_slug}}/.gitignore index 65feea000..c6273596b 100644 --- a/{{cookiecutter.project_slug}}/.gitignore +++ b/{{cookiecutter.project_slug}}/.gitignore @@ -53,42 +53,25 @@ coverage.xml # Django stuff: staticfiles/ -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - # Sphinx documentation docs/_build/ # PyBuilder target/ -# Jupyter Notebook -.ipynb_checkpoints - # pyenv .python-version +{% if cookiecutter.use_celery == 'y' -%} # celery beat schedule file celerybeat-schedule - -# SageMath parsed files -*.sage.py +{%- endif %} # Environments -.env .venv -env/ venv/ ENV/ -# Spyder project settings -.spyderproject -.spyproject - # Rope project settings .ropeproject @@ -122,9 +105,6 @@ coverage # nyc test coverage .nyc_output -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - # Bower dependency directory (https://bower.io/) bower_components @@ -341,7 +321,7 @@ Session.vim # Auto-generated tag files tags - +{% if cookiecutter.use_docker == 'n' %} ### VirtualEnv template # Virtualenv @@ -354,16 +334,12 @@ tags [Ss]cripts pyvenv.cfg pip-selfcheck.json - - -{% if cookiecutter.use_mailhog == 'y' and cookiecutter.use_docker == 'n' -%} -mailhog {% endif %} +### Project template +{% if cookiecutter.use_mailhog == 'y' and cookiecutter.use_docker == 'n' %} +MailHog +{%- endif %} {{ cookiecutter.project_slug }}/media/ -{% if cookiecutter.use_docker == 'y' -%} -# Added to maintain local compose files which are ignored by something above. -# See issue https://github.com/pydanny/cookiecutter-django/issues/1321 -!/compose/local/ -{% endif %} +.pytest_cache/ diff --git a/{{cookiecutter.project_slug}}/.idea/misc.xml b/{{cookiecutter.project_slug}}/.idea/misc.xml new file mode 100644 index 000000000..10af178fd --- /dev/null +++ b/{{cookiecutter.project_slug}}/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/{{cookiecutter.project_slug}}/.idea/modules.xml b/{{cookiecutter.project_slug}}/.idea/modules.xml new file mode 100644 index 000000000..1418fcddf --- /dev/null +++ b/{{cookiecutter.project_slug}}/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__runserver.xml b/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__runserver.xml deleted file mode 100644 index 77b9a5875..000000000 --- a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__runserver.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - diff --git a/{{cookiecutter.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml b/{{cookiecutter.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml new file mode 100644 index 000000000..cf2c5dd89 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__migrate.xml b/{{cookiecutter.project_slug}}/.idea/runConfigurations/migrate.xml similarity index 80% rename from {{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__migrate.xml rename to {{cookiecutter.project_slug}}/.idea/runConfigurations/migrate.xml index cc2fe0bb0..b457c5f55 100644 --- a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__migrate.xml +++ b/{{cookiecutter.project_slug}}/.idea/runConfigurations/migrate.xml @@ -1,17 +1,17 @@ - + +