From 0328032cbf9647ae6b18ae33a2e14a55e19de938 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Thu, 2 Jun 2016 18:57:01 -0700 Subject: [PATCH 01/73] Add bigger comments to better section the css --- .../static/sass/project.scss | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index e737d593f..bbb2da283 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -1,5 +1,10 @@ + // project specific CSS goes here +//////////////////////////////// + //Variables// +//////////////////////////////// + // Alert colors $white: #fff; @@ -9,6 +14,10 @@ $pink: #f2dede; $dark-pink: #eed3d7; $red: #b94a48; +//////////////////////////////// + //Alerts// +//////////////////////////////// + // bootstrap alert CSS, translated to the django-standard levels of // debug, info, success, warning, error @@ -24,6 +33,10 @@ $red: #b94a48; color: $red; } +//////////////////////////////// + //Navbar// +//////////////////////////////// + // This is a fix for the bootstrap4 alpha release @media (max-width: 47.9em) { @@ -42,6 +55,10 @@ $red: #b94a48; } } +//////////////////////////////// + //Django Toolbar// +//////////////////////////////// + // Display django-debug-toolbar. // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 // and https://github.com/pydanny/cookiecutter-django/issues/317 From 329ff5755152d1601dc7839332de9ec8c63aebce Mon Sep 17 00:00:00 2001 From: mjsisley Date: Fri, 3 Jun 2016 06:04:16 -0700 Subject: [PATCH 02/73] Adding documentation for debugging with Docker --- docs/developing-locally-docker.rst | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 03e9221c5..58817c9c8 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -141,3 +141,45 @@ If you want to run the stack in detached mode (in the background), use the ``-d` :: $ docker-compose -f dev.yml up -d + +Debugging +~~~~~~~~~~~~~ + +ipdb +""""" + +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: + +:: + + $ docker-compose run --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 (the output of `Get the IP ADDRESS`_) to INTERNAL_IPS in local.py + + +.. May be a better place to put this, as it is not Docker specific. + +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): + +.. code-block:: css + + /* Override Bootstrap 4 styling on Django Debug Toolbar */ + #djDebug[hidden], #djDebug [hidden] { + display: block !important; + } + + #djDebug [hidden][style='display: none;'] { + display: none !important; + } + + + From b8e02d21890a557fee447c0024ab8e8042303023 Mon Sep 17 00:00:00 2001 From: mjsisley Date: Fri, 3 Jun 2016 08:07:39 -0700 Subject: [PATCH 03/73] Add certbot(letsencrypt) support for docker --- CONTRIBUTORS.rst | 2 + cookiecutter.json | 1 + docs/deployment-with-docker.rst | 44 +++++++++ hooks/post_gen_project.py | 33 +++++-- .../compose/nginx/Dockerfile | 9 +- .../compose/nginx/dhparams.example.pem | 3 + .../compose/nginx/nginx-secure.conf | 92 +++++++++++++++++++ .../compose/nginx/nginx.conf | 37 ++++++-- .../compose/nginx/start.sh | 81 ++++++++++++++++ .../docker-compose.yml | 30 +++++- 10 files changed, 312 insertions(+), 20 deletions(-) create mode 100755 {{cookiecutter.project_slug}}/compose/nginx/dhparams.example.pem create mode 100755 {{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf create mode 100755 {{cookiecutter.project_slug}}/compose/nginx/start.sh diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 4e0bc3bc5..b6de7a3c0 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -96,6 +96,7 @@ Listed in alphabetical order. Matt Linares Matt Menzenski `@menzenski`_ Matt Warren `@mfwarren`_ + Matthew Sisley `@mjsisley`_ Meghan Heintz `@dot2dotseurat`_ mozillazg `@mozillazg`_ Pablo `@oubiga`_ @@ -175,6 +176,7 @@ Listed in alphabetical order. .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho .. _@noisy: https://github.com/noisy +.. _@mjsisley: https://github.com/mjsisley Special Thanks ~~~~~~~~~~~~~~ diff --git a/cookiecutter.json b/cookiecutter.json index 8fe7010a2..5ad55886e 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -22,5 +22,6 @@ "use_heroku": "n", "use_grunt": "n", "use_angular": "n", + "use_certbot": "n", "open_source_license": ["MIT", "BSD", "Not open source"] } diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index de3abf7d4..61ed05f49 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -110,3 +110,47 @@ To get the status, run:: If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: docker-compose ps + +If you are using certbot for https, you must do the following before running anything with docker-compose: + +Replace dhparam.pem.example with a generated dhparams.pem file before running anything with docker-compose. You can generate this on ubuntu or OS X by running the following in the project root: + +:: + + $ openssl dhparam -out /path/to/project/compose/nginx/dhparams.pem 2048 + +If you would like to add additional subdomains to your certificate, you must add additional parameters to the certbot command in the `docker-compose.yml` file: + +Replace: + +:: + + command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email mjsisley@relawgo.com --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + +With: + +:: + + command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} -d www.{{ cookiecutter.domain_name }} -d etc.{{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + +Please be cognizant of Certbot/Letsencrypt certificate requests limits when getting this set up. The provide a test server that does not count against the limit while you are getting set up. + +The certbot certificates expire after 3 months. +If you would like to set up autorenewal of your certificates, the following commands can be put into a bash script: + +:: + + #!/bin/bash + cd + docker-compose run certbot bash -c "sleep 6 && certbot certonly --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + docker exec pearl_nginx_1 nginx -s reload + +And then set a cronjob by running `crontab -e` and placing in it (period can be adjusted as desired): + +0 4 * * 1 /path/to/bashscript/renew_certbot.sh + + + + + + diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index cffb052e8..5f7235504 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -139,6 +139,16 @@ def remove_grunt_files(): PROJECT_DIRECTORY, filename )) +def remove_certbot_files(): + """ + Removes files needed for certbot if it isn't going to be used + """ + nginx_dir_location = os.path.join(PROJECT_DIRECTORY, 'compose/nginx') + for filename in ["nginx-secure.conf", "start.sh", "dhparams.example.pem"]: + os.remove(os.path.join( + nginx_dir_location, filename + )) + # IN PROGRESS # def copy_doc_files(project_directory): # cookiecutters_dir = DEFAULT_CONFIG['cookiecutters_dir'] @@ -180,8 +190,11 @@ if '{{ cookiecutter.use_docker }}'.lower() != 'y': if '{{ cookiecutter.use_grunt }}'.lower() != 'y': remove_grunt_files() +# 7. Removes all certbot/letsencrypt files if it isn't going to be used +if '{{ cookiecutter.use_certbot }}'.lower() != 'y': + remove_certbot_files() -# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our +# 8. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our # docker config atm. if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( @@ -190,13 +203,19 @@ if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker " grunt service to your docker configuration manually." ) -# 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our -# docker config atm. -if '{{ cookiecutter.use_mailhog }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +# 9. Removes the certbot/letsencrypt files and display a warning if use_certbot is selected and use_docker isn't. +if '{{ cookiecutter.use_certbot }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': + remove_certbot_files() print( - "You selected to use docker and mailhog. This is NOT supported out of the box for now. You" - " can continue to use the project like you normally would, but you will need to add a " - " mailhog service to your docker configuration manually." + "You selected to use certbot(letsencrypt) and didn't select to use docker. This is NOT supported out of the box for now. You " + "can continue to use the project like you normally would, but you will no certbot files have been included" + ) + +# 10. Directs the user to the documentation if certbot and docker are selected. +if '{{ cookiecutter.use_certbot }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': + print( + "You selected to use certbot(letsencrypt), please see the documentation for instructions on how to use this in production. " + "You must generate a dhparams.pem file before running docker-compose in a production environment." ) # 4. Copy files from /docs/ to {{ cookiecutter.project_slug }}/docs/ diff --git a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile index 196395763..6a08a744b 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile @@ -1,2 +1,9 @@ FROM nginx:latest -ADD nginx.conf /etc/nginx/nginx.conf \ No newline at end of file +COPY nginx.conf /etc/nginx/nginx.conf + +{% if cookiecutter.use_certbot == 'y' and cookiecutter.use_docker == 'y' %} +COPY start.sh /start.sh +COPY nginx-secure.conf /etc/nginx/nginx-secure.conf +COPY dhparams.pem /etc/ssl/private/dhparams.pem +CMD /start.sh +{% endif %} diff --git a/{{cookiecutter.project_slug}}/compose/nginx/dhparams.example.pem b/{{cookiecutter.project_slug}}/compose/nginx/dhparams.example.pem new file mode 100755 index 000000000..e88d8123f --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/nginx/dhparams.example.pem @@ -0,0 +1,3 @@ +-----BEGIN DH PARAMETERS----- +EXAMPLE_FILE +-----END DH PARAMETERS----- diff --git a/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf b/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf new file mode 100755 index 000000000..78f90279f --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf @@ -0,0 +1,92 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + +http { + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + proxy_headers_hash_bucket_size 52; + + gzip on; + + upstream app { + server django:5000; + } + server { + listen 80; + server_name ___my.example.com___ www.___my.example.com___; + + location /.well-known/acme-challenge { + proxy_pass http://___LETSENCRYPT_IP___:___LETSENCRYPT_PORT___; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location / { + return 301 https://$server_name$request_uri; + } + + } + + server { + listen 443; + server_name ___my.example.com___ www.___my.example.com___; + + ssl on; + ssl_certificate /etc/letsencrypt/live/___my.example.com___/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/___my.example.com___/privkey.pem; + ssl_session_timeout 5m; + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; + ssl_prefer_server_ciphers on; + + ssl_session_cache shared:SSL:10m; + ssl_dhparam /etc/ssl/private/dhparams.pem; + + location /.well-known/acme-challenge { + proxy_pass http://___LETSENCRYPT_HTTPS_IP___:___LETSENCRYPT_HTTPS_PORT___; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + } + + location / { + # checks for static file, if not found proxy to app + try_files $uri @proxy_to_app; + } + + # cookiecutter-django app + location @proxy_to_app { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + + proxy_pass http://app; + + } + + } + +} diff --git a/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf b/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf index 720b22e5b..54d955d7f 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf +++ b/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf @@ -9,9 +9,9 @@ events { worker_connections 1024; } - http { - include /etc/nginx/mime.types; + + include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' @@ -31,23 +31,40 @@ http { server django:5000; } - server { - listen 80; - charset utf-8; + server { + listen 80; + charset utf-8; + {% if cookiecutter.use_certbot == 'y' and cookiecutter.use_docker == 'y' %} + server_name ___my.example.com___ ; - location / { + location /.well-known/acme-challenge { + proxy_pass http://___LETSENCRYPT_IP___:___LETSENCRYPT_PORT___; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + } + + {% endif %} + + location / { # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; } - location @proxy_to_app { + + # cookiecutter-django app + location @proxy_to_app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app; - } - } -} \ No newline at end of file + } + } +} + + + + diff --git a/{{cookiecutter.project_slug}}/compose/nginx/start.sh b/{{cookiecutter.project_slug}}/compose/nginx/start.sh new file mode 100755 index 000000000..2079e194c --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/nginx/start.sh @@ -0,0 +1,81 @@ +echo sleep 5 +sleep 5 + +echo build starting nginx config + + +echo replacing ___my.example.com___/$MY_DOMAIN_NAME +echo replacing ___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR +echo replacing ___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT +echo replacing ___APPLICATION_IP___/$APP_PORT_80_TCP_ADDR +echo replacing ___APPLICATION_PORT___/$APP_PORT_80_TCP_PORT + +# Put your domain name into the nginx reverse proxy config. +sed -i "s/___my.example.com___/$MY_DOMAIN_NAME/g" /etc/nginx/nginx.conf +# Add your app's container IP and port into config +sed -i "s/___APPLICATION_IP___/$APP_PORT_80_TCP_ADDR/g" /etc/nginx/nginx.conf +sed -i "s/___APPLICATION_PORT___/$APP_PORT_80_TCP_PORT/g" /etc/nginx/nginx.conf +sed -i "s/___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR/g" /etc/nginx/nginx.conf +sed -i "s/___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT/g" /etc/nginx/nginx.conf + +cat /etc/nginx/nginx.conf +echo . +echo Firing up nginx in the background. +nginx + +# # Check user has specified domain name +if [ -z "$MY_DOMAIN_NAME" ]; then + echo "Need to set MY_DOMAIN_NAME (to a letsencrypt-registered name)." + exit 1 +fi + +# This bit waits until the letsencrypt container has done its thing. +# We see the changes here bceause there's a docker volume mapped. +echo Waiting for folder /etc/letsencrypt/live/$MY_DOMAIN_NAME to exist +while [ ! -d /etc/letsencrypt/live/$MY_DOMAIN_NAME ] ; +do + sleep 2 +done + +while [ ! -f /etc/letsencrypt/live/$MY_DOMAIN_NAME/fullchain.pem ] ; +do + echo Waiting for file fullchain.pem to exist + sleep 2 +done + +while [ ! -f /etc/letsencrypt/live/$MY_DOMAIN_NAME/privkey.pem ] ; +do + echo Waiting for file privkey.pem to exist + sleep 2 +done + +# This is added so that when the certificate is being renewed or is already in place, nginx waits for everything to be good. +sleep 15 + +echo replacing ___my.example.com___/$MY_DOMAIN_NAME +echo replacing ___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR +echo replacing ___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT +echo replacing ___LETSENCRYPT_HTTPS_IP___/$LETSENCRYPT_PORT_443_TCP_ADDR +echo replacing ___LETSENCRYPT_HTTPS_PORT___/$LETSENCRYPT_PORT_443_TCP_PORT +echo replacing ___APPLICATION_IP___/$APP_PORT_80_TCP_ADDR +echo replacing ___APPLICATION_PORT___/$APP_PORT_80_TCP_PORT + + +# Put your domain name into the nginx reverse proxy config. +sed -i "s/___my.example.com___/$MY_DOMAIN_NAME/g" /etc/nginx/nginx-secure.conf + +# Add LE container IP and port into config +sed -i "s/___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR/g" /etc/nginx/nginx-secure.conf +sed -i "s/___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT/g" /etc/nginx/nginx-secure.conf +sed -i "s/___LETSENCRYPT_HTTPS_IP___/$LETSENCRYPT_PORT_443_TCP_ADDR/g" /etc/nginx/nginx-secure.conf +sed -i "s/___LETSENCRYPT_HTTPS_PORT___/$LETSENCRYPT_PORT_443_TCP_PORT/g" /etc/nginx/nginx-secure.conf + +# Add your app's container IP and port into config +sed -i "s/___APPLICATION_IP___/$APP_PORT_80_TCP_ADDR/g" /etc/nginx/nginx-secure.conf +sed -i "s/___APPLICATION_PORT___/$APP_PORT_80_TCP_PORT/g" /etc/nginx/nginx-secure.conf + +#go! +kill $(ps aux | grep 'nginx' | awk '{print $2}') +cp /etc/nginx/nginx-secure.conf /etc/nginx/nginx.conf + +nginx -g 'daemon off;' diff --git a/{{cookiecutter.project_slug}}/docker-compose.yml b/{{cookiecutter.project_slug}}/docker-compose.yml index df7ddb49c..a67ec0bb4 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.yml @@ -27,12 +27,38 @@ services: build: ./compose/nginx depends_on: - django +{% if cookiecutter.use_certbot == 'y' %} + - certbot +{% endif %} ports: - "0.0.0.0:80:80" +{% if cookiecutter.use_certbot == 'y' %} + environment: + - MY_DOMAIN_NAME={{ cookiecutter.domain_name }} + ports: + - "0.0.0.0:80:80" + - "0.0.0.0:443:443" + volumes: + - /etc/letsencrypt:/etc/letsencrypt + - /var/lib/letsencrypt:/var/lib/letsencrypt + + certbot: + image: quay.io/letsencrypt/letsencrypt + command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + entrypoint: "" + volumes: + - /etc/letsencrypt:/etc/letsencrypt + - /var/lib/letsencrypt:/var/lib/letsencrypt + ports: + - "80" + - "443" + environment: + - TERM=xterm +{% endif %} redis: image: redis:3.0 - {% if cookiecutter.use_celery == 'y' %} +{% if cookiecutter.use_celery == 'y' %} celeryworker: build: context: . @@ -54,4 +80,4 @@ services: - postgres - redis command: celery -A {{cookiecutter.project_slug}}.taskapp beat -l INFO - {% endif %} +{% endif %} From 4b05499d49d28d103457c5df85e4896ad9da2f1e Mon Sep 17 00:00:00 2001 From: mjsisley Date: Fri, 3 Jun 2016 08:39:45 -0700 Subject: [PATCH 04/73] swap COPY to ADD in nginx Dockerfile --- {{cookiecutter.project_slug}}/compose/nginx/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile index 6a08a744b..addd333ed 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile @@ -1,9 +1,9 @@ FROM nginx:latest -COPY nginx.conf /etc/nginx/nginx.conf +ADD nginx.conf /etc/nginx/nginx.conf {% if cookiecutter.use_certbot == 'y' and cookiecutter.use_docker == 'y' %} -COPY start.sh /start.sh -COPY nginx-secure.conf /etc/nginx/nginx-secure.conf -COPY dhparams.pem /etc/ssl/private/dhparams.pem -CMD /start.sh +ADD start.sh /start.sh +ADD nginx-secure.conf /etc/nginx/nginx-secure.conf +ADD dhparams.pem /etc/ssl/private/dhparams.pem +ADD /start.sh {% endif %} From 0efd49203b5fa44344c5ee07bbc6502959a7a09f Mon Sep 17 00:00:00 2001 From: Leonardo Jimenez Date: Fri, 3 Jun 2016 11:51:28 -0700 Subject: [PATCH 05/73] Eliminate django-secure from requirements and settings files --- {{cookiecutter.project_slug}}/config/settings/common.py | 2 +- {{cookiecutter.project_slug}}/config/settings/production.py | 6 +----- {{cookiecutter.project_slug}}/requirements/base.txt | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 3668b4274..3e11ee433 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -53,7 +53,7 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS # MIDDLEWARE CONFIGURATION # ------------------------------------------------------------------------------ MIDDLEWARE_CLASSES = ( - # Make sure djangosecure.middleware.SecurityMiddleware is listed first + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 80302bee4..43b9b6e32 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -41,9 +41,7 @@ INSTALLED_APPS += ('djangosecure', ) # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) {%- endif %} -SECURITY_MIDDLEWARE = ( - 'djangosecure.middleware.SecurityMiddleware', -) + {% if cookiecutter.use_whitenoise == 'y' -%} # Use Whitenoise to serve static files # See: https://whitenoise.readthedocs.io/ @@ -59,8 +57,6 @@ RAVEN_MIDDLEWARE = ( MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES {%- endif %} -# Make sure djangosecure.middleware.SecurityMiddleware is listed first -MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + MIDDLEWARE_CLASSES {% if cookiecutter.use_opbeat == 'y' -%} # opbeat integration diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index f5e35acd6..67a6fd6b0 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -11,7 +11,6 @@ django==1.9.6 # Configuration django-environ==0.4.0 -django-secure==1.0.1 {% if cookiecutter.use_whitenoise == 'y' -%} whitenoise==3.0 {%- endif %} From 97ddd3da1b626d3815bdc9fac89fc3ccf6da625a Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 12:22:57 -0700 Subject: [PATCH 06/73] Fix navbar right top corner issue --- .../{{cookiecutter.project_slug}}/static/sass/project.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index bbb2da283..54632b2d6 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -39,6 +39,10 @@ $red: #b94a48; // This is a fix for the bootstrap4 alpha release +.navbar { + border-radius: 0px; +} + @media (max-width: 47.9em) { .navbar-nav .nav-item { display: inline-block; From 0fa5261f4ad307b6d3c6b67d7144f2f9c48f6e10 Mon Sep 17 00:00:00 2001 From: Leonardo Jimenez Date: Fri, 3 Jun 2016 12:24:11 -0700 Subject: [PATCH 07/73] Include secure defaults for django security middleware --- {{cookiecutter.project_slug}}/config/settings/production.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 43b9b6e32..6a2734315 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -78,9 +78,12 @@ SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( SECURE_CONTENT_TYPE_NOSNIFF = env.bool( 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) SECURE_BROWSER_XSS_FILTER = True -SESSION_COOKIE_SECURE = False +SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) +CSRF_COOKIE_SECURE = True +CSRF_COOKIE_HTTPONLY = True +X_FRAME_OPTIONS = 'DENY' # SITE CONFIGURATION # ------------------------------------------------------------------------------ From 54575f02de700c151c2c6bb3dec8adc5d1dcd3c8 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Fri, 3 Jun 2016 12:29:20 -0700 Subject: [PATCH 08/73] Add settings required by SecurityMiddleware also remove django-secure in prod settings --- .../config/settings/production.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 6a2734315..1fc16a537 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -33,9 +33,6 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -# django-secure -# ------------------------------------------------------------------------------ -INSTALLED_APPS += ('djangosecure', ) {% if cookiecutter.use_sentry == 'y' -%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ @@ -71,6 +68,12 @@ MIDDLEWARE_CLASSES = ( 'opbeat.contrib.django.middleware.OpbeatAPMMiddleware', ) + MIDDLEWARE_CLASSES {%- endif %} + +# SECURITY CONFIGURATION +# ------------------------------------------------------------------------------ +# See https://docs.djangoproject.com/en/1.9/ref/middleware/#module-django.middleware.security +# and https://docs.djangoproject.com/ja/1.9/howto/deployment/checklist/#run-manage-py-check-deploy + # set this to 60 seconds and then to 518400 when you can prove it works SECURE_HSTS_SECONDS = 60 SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( @@ -78,11 +81,14 @@ SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( SECURE_CONTENT_TYPE_NOSNIFF = env.bool( 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) SECURE_BROWSER_XSS_FILTER = True + SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True + SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) CSRF_COOKIE_SECURE = True CSRF_COOKIE_HTTPONLY = True + X_FRAME_OPTIONS = 'DENY' # SITE CONFIGURATION From 7610a7978a20ade7fecbc39ce01b2d2823598b55 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 15:04:04 -0700 Subject: [PATCH 09/73] Add gulp with autoprefixing and minification for sass --- {{cookiecutter.project_slug}}/gulpfile.js | 52 ++++++++++++++++++++++ {{cookiecutter.project_slug}}/package.json | 34 +++++++++----- 2 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/gulpfile.js diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js new file mode 100644 index 000000000..6dddcf29c --- /dev/null +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -0,0 +1,52 @@ + +//////////////////////////////// + //Setup// +//////////////////////////////// + +// Plugins +var gulp = require('gulp'), + pjson = require('./package.json'), + gutil = require('gulp-util'), + sass = require('gulp-sass'), + autoprefixer = require('gulp-autoprefixer'), + cssnano = require('gulp-cssnano'), + rename = require('gulp-rename'), + del = require('del'), + plumber = require('gulp-plumber'), + pixrem = require('gulp-pixrem'), + browserSync = require('browser-sync'); + + +// Relative paths function +var pathsConfig = function (appName) { + this.app = "./" + (appName || pjson.name); + + return { + app: this.app, + templates: this.app + '/templates', + css: this.app + '/static/css', + sass: this.app + '/static/sass', + fonts: this.app + '/static/fonts', + images: this.app + '/static/images', + js: this.app + '/static/js', + } +}; + +var paths = pathsConfig(); + +//////////////////////////////// + //Tasks// +//////////////////////////////// + +// Styles +gulp.task('styles', function() { + return gulp.src(paths.sass + '/project.scss', { style: 'expanded' }) + .pipe(sass().on('error', sass.logError)) + .pipe(plumber()) // It checks for errors + .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes + .pipe(pixrem()) // add fallbacks for rem units + .pipe(gulp.dest('./static/css/')) + .pipe(rename({ suffix: '.min' })) + .pipe(cssnano()) // Minifies the result + .pipe(gulp.dest('./static/css/')); +}); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 47cf69441..5c8b82d2b 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -1,19 +1,29 @@ { - "name": "{{cookiecutter.project_slug}}", - "version": "{{ cookiecutter.version }}", + "name": "testing", + "version": "0.1.0", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-watch": "~0.6.1", - "grunt-bg-shell": "~2.3.1", - "connect-livereload": "~0.3.2", - "time-grunt": "~1.2.1", - "load-grunt-tasks": "~3.2.0", - "grunt-sass": "~1.0.0", - "grunt-postcss": "~0.5.5", - "cssnano": "~2.1.0", "autoprefixer-core": "~5.2.1", - "pixrem": "~1.3.1" + "browser-sync": "^2.12.10", + "connect-livereload": "~0.3.2", + "cssnano": "~2.1.0", + "del": "^2.2.0", + "grunt": "~0.4.5", + "grunt-bg-shell": "~2.3.1", + "grunt-contrib-watch": "~0.6.1", + "grunt-postcss": "~0.5.5", + "grunt-sass": "~1.0.0", + "gulp": "^3.9.1", + "gulp-autoprefixer": "^3.1.0", + "gulp-cssnano": "^2.1.2", + "gulp-pixrem": "^1.0.0", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^2.3.1", + "gulp-util": "^3.0.7", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" }, "engines": { "node": ">=0.8.0" From ffc83080c77ff866cf2c9e868d2100bd13890406 Mon Sep 17 00:00:00 2001 From: Emily C Date: Fri, 3 Jun 2016 15:23:00 -0700 Subject: [PATCH 10/73] initial commit --- docs/index.rst | 2 +- docs/my-favorite-cookie.rst | 100 ++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 docs/my-favorite-cookie.rst diff --git a/docs/index.rst b/docs/index.rst index aa88fe246..b7b3885db 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,7 +14,7 @@ Contents: .. toctree:: :maxdepth: 2 - + my-favorite-cookie project-generation-options developing-locally developing-locally-docker diff --git a/docs/my-favorite-cookie.rst b/docs/my-favorite-cookie.rst new file mode 100644 index 000000000..a65833526 --- /dev/null +++ b/docs/my-favorite-cookie.rst @@ -0,0 +1,100 @@ +************************************************ +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. + + + From 87845bd81700d75b983ed7322f016e064ed6fa8f Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Fri, 3 Jun 2016 15:31:50 -0700 Subject: [PATCH 11/73] Temp quick fixes to improve developing-locally doc --- docs/developing-locally.rst | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 119856909..a7f0269f3 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -9,20 +9,32 @@ The steps below will get you up and running with a local development environment * virtualenv * PostgreSQL -First make sure to create and activate a virtualenv_, then open a terminal at the project root and install the os dependencies:: +First make sure to create and activate a virtualenv_. - $ sudo ./install_os_dependencies.sh install +.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ Then install the requirements for your local development:: $ pip install -r requirements/local.txt -.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ - Then, create a PostgreSQL database with the following command, where `[project_slug]` is what value you entered for your project's `project_slug`:: $ createdb [project_slug] +You can now run the usual Django ``migrate`` and ``runserver`` commands:: + + $ 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. + +But if you want to go further with setup, read on. + +(Note: the following sections still need to be revised) + +Setting Up Env Vars for Production +----------------------------------- + `Cookiecutter Django` uses the excellent `django-environ`_ package with its ``DATABASE_URL`` environment variable to simplify database configuration in your Django settings. Now all you have to do is rename env.example to .env and then compose a definition for ``DATABASE_URL`` as shown below and add it to the .env file: .. parsed-literal:: @@ -31,12 +43,8 @@ Then, create a PostgreSQL database with the following command, where `[project_s .. _django-environ: http://django-environ.readthedocs.io -You can now run the usual Django ``migrate`` and ``runserver`` commands:: - - $ python manage.py migrate - $ python manage.py runserver - -**Setup your email backend** +Setup your email backend +------------------------- 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`_ @@ -85,5 +93,3 @@ The base app will now run as it would with the usual ``manage.py runserver`` but To get live reloading to work you'll probably need to install an `appropriate browser extension`_ .. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- - -It's time to write the code!!! From a7eb85208d1908276fe91960a4d2b558d60bd577 Mon Sep 17 00:00:00 2001 From: Leonardo Jimenez Date: Fri, 3 Jun 2016 13:22:52 -0700 Subject: [PATCH 12/73] Eliminate empty spaces generated on Jinja on config/settings/production.py --- .../config/settings/production.py | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 1fc16a537..346bf7cb6 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -29,33 +29,26 @@ from .common import * # noqa # Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ SECRET_KEY = env('DJANGO_SECRET_KEY') + # This ensures that Django will be able to detect a secure connection # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') - -{% if cookiecutter.use_sentry == 'y' -%} +{%- if cookiecutter.use_sentry == 'y'-%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) -{%- endif %} - -{% if cookiecutter.use_whitenoise == 'y' -%} +{% endif %} +{%- if cookiecutter.use_whitenoise == 'y' %} # Use Whitenoise to serve static files # See: https://whitenoise.readthedocs.io/ -WHITENOISE_MIDDLEWARE = ( - 'whitenoise.middleware.WhiteNoiseMiddleware', -) +WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', ) MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} -{% if cookiecutter.use_sentry == 'y' -%} -RAVEN_MIDDLEWARE = ( - 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', -) +{% endif %} +{%- if cookiecutter.use_sentry == 'y' -%} +RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ) MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} - - -{% if cookiecutter.use_opbeat == 'y' -%} +{% endif %} +{%- if cookiecutter.use_opbeat == 'y' -%} # opbeat integration # See https://opbeat.com/languages/django/ INSTALLED_APPS += ('opbeat.contrib.django',) @@ -67,7 +60,7 @@ OPBEAT = { MIDDLEWARE_CLASSES = ( 'opbeat.contrib.django.middleware.OpbeatAPMMiddleware', ) + MIDDLEWARE_CLASSES -{%- endif %} +{% endif %} # SECURITY CONFIGURATION # ------------------------------------------------------------------------------ @@ -81,14 +74,11 @@ SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( SECURE_CONTENT_TYPE_NOSNIFF = env.bool( 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) SECURE_BROWSER_XSS_FILTER = True - SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True - SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) CSRF_COOKIE_SECURE = True CSRF_COOKIE_HTTPONLY = True - X_FRAME_OPTIONS = 'DENY' # SITE CONFIGURATION @@ -100,6 +90,7 @@ ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['{{cookiecutter.domain INSTALLED_APPS += ('gunicorn', ) + # STORAGE CONFIGURATION # ------------------------------------------------------------------------------ # Uploaded Media Files From 907b8ecfbda0e54b1cf535476b7127434db8585a Mon Sep 17 00:00:00 2001 From: Leonardo Date: Fri, 3 Jun 2016 16:07:27 -0700 Subject: [PATCH 13/73] Remove django-secure (#579) * Eliminate django-secure from requirements and settings files * Include secure defaults for django security middleware * Add settings required by SecurityMiddleware also remove django-secure in prod settings * Eliminate empty spaces generated on Jinja on config/settings/production.py --- .../config/settings/common.py | 2 +- .../config/settings/production.py | 48 +++++++++---------- .../requirements/base.txt | 1 - 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 3668b4274..3e11ee433 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -53,7 +53,7 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS # MIDDLEWARE CONFIGURATION # ------------------------------------------------------------------------------ MIDDLEWARE_CLASSES = ( - # Make sure djangosecure.middleware.SecurityMiddleware is listed first + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 80302bee4..346bf7cb6 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -29,40 +29,26 @@ from .common import * # noqa # Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ SECRET_KEY = env('DJANGO_SECRET_KEY') + # This ensures that Django will be able to detect a secure connection # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') - -# django-secure -# ------------------------------------------------------------------------------ -INSTALLED_APPS += ('djangosecure', ) -{% if cookiecutter.use_sentry == 'y' -%} +{%- if cookiecutter.use_sentry == 'y'-%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) -{%- endif %} -SECURITY_MIDDLEWARE = ( - 'djangosecure.middleware.SecurityMiddleware', -) -{% if cookiecutter.use_whitenoise == 'y' -%} +{% endif %} +{%- if cookiecutter.use_whitenoise == 'y' %} # Use Whitenoise to serve static files # See: https://whitenoise.readthedocs.io/ -WHITENOISE_MIDDLEWARE = ( - 'whitenoise.middleware.WhiteNoiseMiddleware', -) +WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', ) MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} -{% if cookiecutter.use_sentry == 'y' -%} -RAVEN_MIDDLEWARE = ( - 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', -) +{% endif %} +{%- if cookiecutter.use_sentry == 'y' -%} +RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ) MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} - -# Make sure djangosecure.middleware.SecurityMiddleware is listed first -MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + MIDDLEWARE_CLASSES - -{% if cookiecutter.use_opbeat == 'y' -%} +{% endif %} +{%- if cookiecutter.use_opbeat == 'y' -%} # opbeat integration # See https://opbeat.com/languages/django/ INSTALLED_APPS += ('opbeat.contrib.django',) @@ -74,7 +60,13 @@ OPBEAT = { MIDDLEWARE_CLASSES = ( 'opbeat.contrib.django.middleware.OpbeatAPMMiddleware', ) + MIDDLEWARE_CLASSES -{%- endif %} +{% endif %} + +# SECURITY CONFIGURATION +# ------------------------------------------------------------------------------ +# See https://docs.djangoproject.com/en/1.9/ref/middleware/#module-django.middleware.security +# and https://docs.djangoproject.com/ja/1.9/howto/deployment/checklist/#run-manage-py-check-deploy + # set this to 60 seconds and then to 518400 when you can prove it works SECURE_HSTS_SECONDS = 60 SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( @@ -82,9 +74,12 @@ SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool( SECURE_CONTENT_TYPE_NOSNIFF = env.bool( 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) SECURE_BROWSER_XSS_FILTER = True -SESSION_COOKIE_SECURE = False +SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) +CSRF_COOKIE_SECURE = True +CSRF_COOKIE_HTTPONLY = True +X_FRAME_OPTIONS = 'DENY' # SITE CONFIGURATION # ------------------------------------------------------------------------------ @@ -95,6 +90,7 @@ ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['{{cookiecutter.domain INSTALLED_APPS += ('gunicorn', ) + # STORAGE CONFIGURATION # ------------------------------------------------------------------------------ # Uploaded Media Files diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index f5e35acd6..67a6fd6b0 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -11,7 +11,6 @@ django==1.9.6 # Configuration django-environ==0.4.0 -django-secure==1.0.1 {% if cookiecutter.use_whitenoise == 'y' -%} whitenoise==3.0 {%- endif %} From c64027a5cfbe94d7056edb27723433f45bff7dee Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 16:09:55 -0700 Subject: [PATCH 14/73] Add @xpostudio4 as a contributor --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 088fb47a8..3038b6f5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Deleted - AngularJS (@pydanny) +- django-secure (@xpostudio4) ##[2016-06-02] ### Added diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 5a0ab6eb4..99239b71d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -87,6 +87,7 @@ Listed in alphabetical order. Kevin Ndung'u `@kevgathuku`_ Krzysztof Szumny `@noisy`_ Krzysztof Żuraw `@krzysztofzuraw`_ + Leonardo Jimenez `@xpostudio4`_ Lin Xianyi `@iynaix`_ Luis Nell `@originell`_ Lukas Klein @@ -152,6 +153,7 @@ Listed in alphabetical order. .. _@ikkebr: https://github.com/ikkebr .. _@iynaix: https://github.com/iynaix .. _@jazztpt: https://github.com/jazztpt +.. _@xpostudio4: https://github.com/xpostudio4 .. _@juliocc: https://github.com/juliocc .. _@jvanbrug: https://github.com/jvanbrug .. _@ka7eh: https://github.com/ka7eh From fa89445f6668c7668937c3f6b1d93f10ef557206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sul=C3=A9?= Date: Fri, 3 Jun 2016 16:35:10 -0700 Subject: [PATCH 15/73] Removing unnecessary version check #534 (#584) * Address issue #534 * missing comma added * remove unecesssary version check #534 --- cookiecutter.json | 3 ++- hooks/pre_gen_project.py | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 36aa3c300..65879a69e 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -21,5 +21,6 @@ "use_docker": "y", "use_heroku": "n", "use_grunt": "n", - "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] + "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"], + "_cookiecutter_version": "Minimum cookiecutter version" } diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 3dfc190a2..9cd168bce 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -1,8 +1,6 @@ -import cookiecutter - project_slug = '{{ cookiecutter.project_slug }}' if hasattr(project_slug, 'isidentifier'): assert project_slug.isidentifier(), 'Project slug should be valid Python identifier!' -assert cookiecutter.__version__ > '1.3.0', 'Please upgrade your Cookiecutter installation' + From 700ee39be81dd5c0bf529a285ae75c79dd0fbba4 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 16:49:04 -0700 Subject: [PATCH 16/73] Added @suledev to contributors list --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3038b6f5e..f6362f495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - Documentation for debugging with Docker (@mjsisley) - Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) +- Removed unnecessary version check from `pre_gen_project.py` (@suledev) ### Deleted - AngularJS (@pydanny) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 99239b71d..0f559e00b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -109,6 +109,7 @@ Listed in alphabetical order. stepmr `@stepmr`_ Sławek Ehlert `@slafs`_ Srinivas Nyayapati `@shireenrao`_ + Sule Marshall `@suledev`_ Taylor Baldwin Théo Segonds `@show0k`_ Tom Atkins `@knitatoms`_ @@ -174,6 +175,7 @@ Listed in alphabetical order. .. _@shireenrao: https://github.com/shireenrao .. _@slafs: https://github.com/slafs .. _@stepmr: https://github.com/stepmr +.. _@suledev: https://github.com/suledev .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong .. _@yunti: https://github.com/yunti From 8a925db024b114930eacd3caa1509496516183a3 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 17:05:57 -0700 Subject: [PATCH 17/73] Add gulp alternative as a js task runner --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 38 ++++++++++--- {{cookiecutter.project_slug}}/gulpfile.js | 65 ++++++++++++++++++++-- {{cookiecutter.project_slug}}/package.json | 21 ++++--- 4 files changed, 106 insertions(+), 20 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 8fe7010a2..0536bfc9f 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,7 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_grunt": "n", + "js_task_runner": ["Gulp", "Grunt", "None"], "use_angular": "n", "open_source_license": ["MIT", "BSD", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index cffb052e8..72abbfcad 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -134,7 +134,25 @@ def remove_grunt_files(): """ Removes files needed for grunt if it isn't going to be used """ - for filename in ["Gruntfile.js", "package.json"]: + for filename in ["Gruntfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_gulp_files(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["gulpfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_packageJSON_file(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["package.json"]: os.remove(os.path.join( PROJECT_DIRECTORY, filename )) @@ -176,18 +194,24 @@ if '{{ cookiecutter.use_heroku }}'.lower() != 'y': if '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_docker_files() -# 6. Removes all grunt files if it isn't going to be used -if '{{ cookiecutter.use_grunt }}'.lower() != 'y': +# 6. Removes all JS task manager files if it isn't going to be used +if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp': remove_grunt_files() +elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': + remove_gulp_files() +else: + remove_gulp_files() + remove_grunt_files() + remove_packageJSON_file() -# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our +# 7. Display a warning if use_docker and js task runner are selected. Grunt isn't supported by our # docker config atm. -if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( - "You selected to use docker and grunt. This is NOT supported out of the box for now. You " + "You selected to use docker and a JS task runner. This is NOT supported out of the box for now. You " "can continue to use the project like you normally would, but you will need to add a " - " grunt service to your docker configuration manually." + "js task runner service to your docker configuration manually." ) # 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js index 6dddcf29c..e5b0df9dc 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.js +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -14,6 +14,10 @@ var gulp = require('gulp'), del = require('del'), plumber = require('gulp-plumber'), pixrem = require('gulp-pixrem'), + uglify = require('gulp-uglify'), + imagemin = require('gulp-imagemin'), + exec = require('gulp-exec'), + runSequence = require('run-sequence'), browserSync = require('browser-sync'); @@ -38,15 +42,66 @@ var paths = pathsConfig(); //Tasks// //////////////////////////////// -// Styles +// Styles autoprefixing and minification gulp.task('styles', function() { - return gulp.src(paths.sass + '/project.scss', { style: 'expanded' }) + return gulp.src(paths.sass + '/project.scss') .pipe(sass().on('error', sass.logError)) - .pipe(plumber()) // It checks for errors + .pipe(plumber()) // Checks for errors .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes .pipe(pixrem()) // add fallbacks for rem units - .pipe(gulp.dest('./static/css/')) + .pipe(gulp.dest(paths.css)) .pipe(rename({ suffix: '.min' })) .pipe(cssnano()) // Minifies the result - .pipe(gulp.dest('./static/css/')); + .pipe(gulp.dest(paths.css)); +}); + +// Javascript minification +gulp.task('scripts', function() { + return gulp.src(paths.js + '/project.js') + .pipe(plumber()) // Checks for errors + .pipe(uglify()) // Minifies the js + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.js)); +}); + +// Image compression +gulp.task('imgCompression', function(){ + return gulp.src(paths.images + '/*') + .pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images + .pipe(gulp.dest(paths.images)) +}); + +// Run django server +gulp.task('runServer', function() { + exec('python manage.py runserver', function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + }); +}); + +// Browser sync server for live reload +gulp.task('browserSync', function() { + browserSync.init( + [paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], { + proxy: "localhost:8000" + }); +}); + +// Default task +gulp.task('default', function() { + runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync'); +}); + +//////////////////////////////// + //Watch// +//////////////////////////////// + +// Watch +gulp.task('watch', ['default'], function() { + + gulp.watch(paths.sass + '/*.scss', ['styles']); + gulp.watch(paths.js + '/*.js', ['scripts']); + gulp.watch(paths.images + '/*', ['imgCompression']); + gulp.watch('templates/*.html'); + }); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 5c8b82d2b..2be4b50c8 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -1,29 +1,36 @@ { - "name": "testing", - "version": "0.1.0", + "name": "{{cookiecutter.project_slug}}", + "version": "{{ cookiecutter.version }}", "dependencies": {}, "devDependencies": { + {% if cookiecutter.js_task_runner == 'Grunt' %} "autoprefixer-core": "~5.2.1", - "browser-sync": "^2.12.10", "connect-livereload": "~0.3.2", "cssnano": "~2.1.0", - "del": "^2.2.0", "grunt": "~0.4.5", "grunt-bg-shell": "~2.3.1", "grunt-contrib-watch": "~0.6.1", "grunt-postcss": "~0.5.5", "grunt-sass": "~1.0.0", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" + {% elif cookiecutter.js_task_runner == 'Gulp' %} + "browser-sync": "^2.12.10", + "del": "^2.2.0", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.0", "gulp-cssnano": "^2.1.2", + "gulp-exec": "^2.1.2", + "gulp-imagemin": "^3.0.1", "gulp-pixrem": "^1.0.0", "gulp-plumber": "^1.1.0", "gulp-rename": "^1.2.2", "gulp-sass": "^2.3.1", + "gulp-uglify": "^1.5.3", "gulp-util": "^3.0.7", - "load-grunt-tasks": "~3.2.0", - "pixrem": "~1.3.1", - "time-grunt": "~1.2.1" + "run-sequence": "^1.2.1" + {% endif %} }, "engines": { "node": ">=0.8.0" From 60bfc7afa167a133eeb42d75dc1081efbde9fdf7 Mon Sep 17 00:00:00 2001 From: mjsisley Date: Fri, 3 Jun 2016 17:07:07 -0700 Subject: [PATCH 18/73] remove typo /start.sh --- {{cookiecutter.project_slug}}/compose/nginx/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile index addd333ed..7bb605584 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile @@ -5,5 +5,4 @@ ADD nginx.conf /etc/nginx/nginx.conf ADD start.sh /start.sh ADD nginx-secure.conf /etc/nginx/nginx-secure.conf ADD dhparams.pem /etc/ssl/private/dhparams.pem -ADD /start.sh {% endif %} From cda3cfc641d0ab66f4b4f86acc8cfc5747341824 Mon Sep 17 00:00:00 2001 From: Vivian Guillen Date: Fri, 3 Jun 2016 17:31:36 -0700 Subject: [PATCH 19/73] merge in @@viviangb #585 --- cookiecutter.json | 5 +- hooks/post_gen_project.py | 38 +++++-- {{cookiecutter.project_slug}}/gulpfile.js | 107 ++++++++++++++++++ {{cookiecutter.project_slug}}/package.json | 37 ++++-- .../static/sass/project.scss | 21 ++++ 5 files changed, 188 insertions(+), 20 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/gulpfile.js diff --git a/cookiecutter.json b/cookiecutter.json index 65879a69e..fb01784ab 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,6 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_grunt": "n", - "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"], - "_cookiecutter_version": "Minimum cookiecutter version" + "js_task_runner": ["Gulp", "Grunt", "None"], + "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index cffb052e8..72abbfcad 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -134,7 +134,25 @@ def remove_grunt_files(): """ Removes files needed for grunt if it isn't going to be used """ - for filename in ["Gruntfile.js", "package.json"]: + for filename in ["Gruntfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_gulp_files(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["gulpfile.js"]: + os.remove(os.path.join( + PROJECT_DIRECTORY, filename + )) + +def remove_packageJSON_file(): + """ + Removes files needed for grunt if it isn't going to be used + """ + for filename in ["package.json"]: os.remove(os.path.join( PROJECT_DIRECTORY, filename )) @@ -176,18 +194,24 @@ if '{{ cookiecutter.use_heroku }}'.lower() != 'y': if '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_docker_files() -# 6. Removes all grunt files if it isn't going to be used -if '{{ cookiecutter.use_grunt }}'.lower() != 'y': +# 6. Removes all JS task manager files if it isn't going to be used +if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp': remove_grunt_files() +elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt': + remove_gulp_files() +else: + remove_gulp_files() + remove_grunt_files() + remove_packageJSON_file() -# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our +# 7. Display a warning if use_docker and js task runner are selected. Grunt isn't supported by our # docker config atm. -if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( - "You selected to use docker and grunt. This is NOT supported out of the box for now. You " + "You selected to use docker and a JS task runner. This is NOT supported out of the box for now. You " "can continue to use the project like you normally would, but you will need to add a " - " grunt service to your docker configuration manually." + "js task runner service to your docker configuration manually." ) # 7. Display a warning if use_docker and use_mailhog are selected. Mailhog isn't supported by our diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js new file mode 100644 index 000000000..e5b0df9dc --- /dev/null +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -0,0 +1,107 @@ + +//////////////////////////////// + //Setup// +//////////////////////////////// + +// Plugins +var gulp = require('gulp'), + pjson = require('./package.json'), + gutil = require('gulp-util'), + sass = require('gulp-sass'), + autoprefixer = require('gulp-autoprefixer'), + cssnano = require('gulp-cssnano'), + rename = require('gulp-rename'), + del = require('del'), + plumber = require('gulp-plumber'), + pixrem = require('gulp-pixrem'), + uglify = require('gulp-uglify'), + imagemin = require('gulp-imagemin'), + exec = require('gulp-exec'), + runSequence = require('run-sequence'), + browserSync = require('browser-sync'); + + +// Relative paths function +var pathsConfig = function (appName) { + this.app = "./" + (appName || pjson.name); + + return { + app: this.app, + templates: this.app + '/templates', + css: this.app + '/static/css', + sass: this.app + '/static/sass', + fonts: this.app + '/static/fonts', + images: this.app + '/static/images', + js: this.app + '/static/js', + } +}; + +var paths = pathsConfig(); + +//////////////////////////////// + //Tasks// +//////////////////////////////// + +// Styles autoprefixing and minification +gulp.task('styles', function() { + return gulp.src(paths.sass + '/project.scss') + .pipe(sass().on('error', sass.logError)) + .pipe(plumber()) // Checks for errors + .pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes + .pipe(pixrem()) // add fallbacks for rem units + .pipe(gulp.dest(paths.css)) + .pipe(rename({ suffix: '.min' })) + .pipe(cssnano()) // Minifies the result + .pipe(gulp.dest(paths.css)); +}); + +// Javascript minification +gulp.task('scripts', function() { + return gulp.src(paths.js + '/project.js') + .pipe(plumber()) // Checks for errors + .pipe(uglify()) // Minifies the js + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.js)); +}); + +// Image compression +gulp.task('imgCompression', function(){ + return gulp.src(paths.images + '/*') + .pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images + .pipe(gulp.dest(paths.images)) +}); + +// Run django server +gulp.task('runServer', function() { + exec('python manage.py runserver', function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + }); +}); + +// Browser sync server for live reload +gulp.task('browserSync', function() { + browserSync.init( + [paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], { + proxy: "localhost:8000" + }); +}); + +// Default task +gulp.task('default', function() { + runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync'); +}); + +//////////////////////////////// + //Watch// +//////////////////////////////// + +// Watch +gulp.task('watch', ['default'], function() { + + gulp.watch(paths.sass + '/*.scss', ['styles']); + gulp.watch(paths.js + '/*.js', ['scripts']); + gulp.watch(paths.images + '/*', ['imgCompression']); + gulp.watch('templates/*.html'); + +}); diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index 47cf69441..2be4b50c8 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -3,17 +3,34 @@ "version": "{{ cookiecutter.version }}", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-watch": "~0.6.1", - "grunt-bg-shell": "~2.3.1", - "connect-livereload": "~0.3.2", - "time-grunt": "~1.2.1", - "load-grunt-tasks": "~3.2.0", - "grunt-sass": "~1.0.0", - "grunt-postcss": "~0.5.5", - "cssnano": "~2.1.0", + {% if cookiecutter.js_task_runner == 'Grunt' %} "autoprefixer-core": "~5.2.1", - "pixrem": "~1.3.1" + "connect-livereload": "~0.3.2", + "cssnano": "~2.1.0", + "grunt": "~0.4.5", + "grunt-bg-shell": "~2.3.1", + "grunt-contrib-watch": "~0.6.1", + "grunt-postcss": "~0.5.5", + "grunt-sass": "~1.0.0", + "load-grunt-tasks": "~3.2.0", + "pixrem": "~1.3.1", + "time-grunt": "~1.2.1" + {% elif cookiecutter.js_task_runner == 'Gulp' %} + "browser-sync": "^2.12.10", + "del": "^2.2.0", + "gulp": "^3.9.1", + "gulp-autoprefixer": "^3.1.0", + "gulp-cssnano": "^2.1.2", + "gulp-exec": "^2.1.2", + "gulp-imagemin": "^3.0.1", + "gulp-pixrem": "^1.0.0", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^2.3.1", + "gulp-uglify": "^1.5.3", + "gulp-util": "^3.0.7", + "run-sequence": "^1.2.1" + {% endif %} }, "engines": { "node": ">=0.8.0" diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss index e737d593f..54632b2d6 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/static/sass/project.scss @@ -1,5 +1,10 @@ + // project specific CSS goes here +//////////////////////////////// + //Variables// +//////////////////////////////// + // Alert colors $white: #fff; @@ -9,6 +14,10 @@ $pink: #f2dede; $dark-pink: #eed3d7; $red: #b94a48; +//////////////////////////////// + //Alerts// +//////////////////////////////// + // bootstrap alert CSS, translated to the django-standard levels of // debug, info, success, warning, error @@ -24,8 +33,16 @@ $red: #b94a48; color: $red; } +//////////////////////////////// + //Navbar// +//////////////////////////////// + // This is a fix for the bootstrap4 alpha release +.navbar { + border-radius: 0px; +} + @media (max-width: 47.9em) { .navbar-nav .nav-item { display: inline-block; @@ -42,6 +59,10 @@ $red: #b94a48; } } +//////////////////////////////// + //Django Toolbar// +//////////////////////////////// + // Display django-debug-toolbar. // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 // and https://github.com/pydanny/cookiecutter-django/issues/317 From 38c6fb75ed86bfc20ad17e2e16a90ea02f62e499 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Fri, 3 Jun 2016 17:39:13 -0700 Subject: [PATCH 20/73] Added @viviangb to contributors --- CHANGELOG.md | 1 + CONTRIBUTORS.rst | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6362f495..bffc76890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Documentation for debugging with Docker (@mjsisley) - Apache 2 License option in `cookiecutter.json` (@dot2dotseurat) - Removed unnecessary version check from `pre_gen_project.py` (@suledev) +- Add gulp alternative as a js task runner and fix navbar style issue (@viviangb and @xpostudio4) ### Deleted - AngularJS (@pydanny) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 0f559e00b..d1d4f2f7d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -114,8 +114,9 @@ Listed in alphabetical order. Théo Segonds `@show0k`_ Tom Atkins `@knitatoms`_ Tom Offermann - Travis McNeill `@Travistock`_ @tavistock_esq + Travis McNeill `@Travistock`_ @tavistock_esq Vitaly Babiy + Vivian Guillen `@viviangb`_ Yaroslav Halchenko ========================== ============================ ============== @@ -178,6 +179,7 @@ Listed in alphabetical order. .. _@suledev: https://github.com/suledev .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong +.. _@viviangb: httpsL//github.com/viviangb .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho .. _@noisy: https://github.com/noisy From fc67ecf17431de8e879f07334e312e5259f599ed Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Fri, 3 Jun 2016 18:12:18 -0700 Subject: [PATCH 21/73] Remove use_angular option again --- cookiecutter.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index 2240a7d0b..fb01784ab 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,7 +20,6 @@ "use_python2": "n", "use_docker": "y", "use_heroku": "n", - "use_angular": "n", "js_task_runner": ["Gulp", "Grunt", "None"], "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } From c5e984cf2365dba59061b930fe5fa14571c25659 Mon Sep 17 00:00:00 2001 From: Leonardo Jimenez Date: Fri, 3 Jun 2016 23:55:51 -0700 Subject: [PATCH 22/73] Include Licensing on the template --- LICENSE | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index 9a5d2fc08..2afdb0d8c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,17 @@ -Copyright (c) 2013-2016, Daniel Greenfeld +{% if cookiecutter.open_source_license == 'MIT' %} +MIT License + +Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }} + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +{% elif cookiecutter.open_source_license == 'BSD' %} +BSD License + +Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }} All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -11,9 +24,9 @@ are permitted provided that the following conditions are met: list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -* Neither the name of Cookiecutter Django nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. +* Neither the name of {{ cookiecutter.project_name }} nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -21,7 +34,25 @@ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIME IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +{% elif cookiecutter.open_source_license == 'Apache Software License 2.0' %} +Apache Software License 2.0 + +Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }} + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +{% endif %} From 95724dfbbc441936a39b9a13288ce4e415d61383 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sat, 4 Jun 2016 10:28:12 -0700 Subject: [PATCH 23/73] Add @chrisdev to contributors --- CHANGELOG.md | 4 ++++ CONTRIBUTORS.rst | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bffc76890..2ea494cfa 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/). +##[2016-06-04] +### Added +- Let's Encrypt automation and instruction (@mjsisley and @chrisdev) + ##[2016-06-03] ### Added - Documentation for debugging with Docker (@mjsisley) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index e5164aca1..fb7be02e8 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -61,6 +61,7 @@ Listed in alphabetical order. Chris Franklin Chris Franklin `@hairychris`_ Chris Pappalardo `@ChrisPappalardo`_ + Christopher Clarke `@chrisdev`_ Collederas `@Collederas`_ Cristian Vargas `@cdvv7788`_ Cullen Rhodes `@c-rhodes`_ @@ -99,7 +100,6 @@ Listed in alphabetical order. Matt Warren `@mfwarren`_ Matthew Sisley `@mjsisley`_ Meghan Heintz `@dot2dotseurat`_ - mjsisley `@mjsisley`_ mozillazg `@mozillazg`_ Pablo `@oubiga`_ Raphael Pierzina `@hackebrot`_ @@ -138,6 +138,7 @@ Listed in alphabetical order. .. _@catherinedevlin: https://github.com/catherinedevlin .. _@ccurvey: https://github.com/ccurvey .. _@cdvv7788: https://github.com/cdvv7788 +.. _@chrisdev: https://github.com/chrisdev .. _@ChrisPappalardo: https://github.com/ChrisPappalardo .. _@Collederas: https://github.com/Collederas .. _@ddiazpinto: https://github.com/ddiazpinto @@ -184,7 +185,7 @@ Listed in alphabetical order. .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho .. _@noisy: https://github.com/noisy -.. _@mjsisley: https://github.com/mjsisley + Special Thanks ~~~~~~~~~~~~~~ From e5b3b85620d0d00e5ac1f715659f4aa3a26154e9 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sat, 4 Jun 2016 16:11:14 -0700 Subject: [PATCH 24/73] Reorder index --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index b7b3885db..146c05572 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,7 +14,6 @@ Contents: .. toctree:: :maxdepth: 2 - my-favorite-cookie project-generation-options developing-locally developing-locally-docker @@ -26,6 +25,7 @@ Contents: deployment-with-docker faq troubleshooting + my-favorite-cookie Indices and tables ================== From b2d0a863448f383f1f944e9346ad82b9f3118b36 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sat, 4 Jun 2016 17:16:48 -0700 Subject: [PATCH 25/73] simplify cookiecutter.json --- README.rst | 2 -- cookiecutter.json | 2 -- docs/conf.py | 2 +- tests/test_cookiecutter_generation.py | 2 -- {{cookiecutter.project_slug}}/LICENSE | 4 ++-- {{cookiecutter.project_slug}}/docs/conf.py | 2 +- 6 files changed, 4 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 23fb79d64..915cfa9be 100644 --- a/README.rst +++ b/README.rst @@ -115,8 +115,6 @@ 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 - now [2016/03/01]: 2016/03/05 - year [2016]: use_whitenoise [y]: n use_celery [n]: y use_mailhog [n]: n diff --git a/cookiecutter.json b/cookiecutter.json index 8004d2988..0cae40739 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -7,8 +7,6 @@ "domain_name": "example.com", "version": "0.1.0", "timezone": "UTC", - "now": "{% now 'local' %}", - "year": "{{ cookiecutter.now[:4] }}", "use_whitenoise": "y", "use_celery": "n", "use_mailhog": "n", diff --git a/docs/conf.py b/docs/conf.py index 2fdeb69e6..d33c8f316 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,7 +46,7 @@ master_doc = 'index' # General information about the project. project = 'Cookiecutter Django' -copyright = '2013-{}, Daniel Roy Greenfeld'.format(now.year) +copyright = '2013-{% now 'utc', '%Y' %}, 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 diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 6815751a8..e0e06ce6a 100644 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -22,8 +22,6 @@ def context(): 'domain_name': 'example.com', 'version': '0.1.0', 'timezone': 'UTC', - 'now': '2015/01/13', - 'year': '2015' } diff --git a/{{cookiecutter.project_slug}}/LICENSE b/{{cookiecutter.project_slug}}/LICENSE index e6d8e8103..413f8af56 100644 --- a/{{cookiecutter.project_slug}}/LICENSE +++ b/{{cookiecutter.project_slug}}/LICENSE @@ -1,6 +1,6 @@ {% if cookiecutter.open_source_license == 'MIT' %} The MIT License (MIT) -Copyright (c) {{ cookiecutter.year }}, {{ cookiecutter.author_name }} +Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -8,7 +8,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. {% elif cookiecutter.open_source_license == 'BSD' %} -Copyright (c) {{ cookiecutter.year }}, {{ cookiecutter.author_name }} +Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/{{cookiecutter.project_slug}}/docs/conf.py b/{{cookiecutter.project_slug}}/docs/conf.py index 78ca7ce5e..03cbe319b 100644 --- a/{{cookiecutter.project_slug}}/docs/conf.py +++ b/{{cookiecutter.project_slug}}/docs/conf.py @@ -44,7 +44,7 @@ master_doc = 'index' # General information about the project. project = '{{ cookiecutter.project_name }}' -copyright = """{{ cookiecutter.year }}, {{ cookiecutter.author_name }}""" +copyright = """{% now 'utc', '%Y' %}, {{ cookiecutter.author_name }}""" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the From f40f30445799176a12628d89d66a90ddf4bc459b Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 10:47:07 -0700 Subject: [PATCH 26/73] Use sentry for error reporting --- README.rst | 3 +-- cookiecutter.json | 3 +-- docs/project-generation-options.rst | 2 +- {{cookiecutter.project_slug}}/Procfile | 2 +- {{cookiecutter.project_slug}}/README.rst | 2 +- {{cookiecutter.project_slug}}/app.json | 8 ++------ .../config/settings/production.py | 18 +++++++----------- {{cookiecutter.project_slug}}/config/wsgi.py | 13 ++----------- {{cookiecutter.project_slug}}/env.example | 6 +----- .../requirements/production.txt | 8 +------- .../taskapp/celery.py | 2 +- 11 files changed, 19 insertions(+), 48 deletions(-) diff --git a/README.rst b/README.rst index 915cfa9be..fa7c88d35 100644 --- a/README.rst +++ b/README.rst @@ -118,8 +118,7 @@ Answer the prompts with your own desired options_. For example:: use_whitenoise [y]: n use_celery [n]: y use_mailhog [n]: n - use_sentry [n]: y - use_newrelic [n]: y + use_sentry_for_error_reporting [y]: y use_opbeat [n]: y use_pycharm [n]: y windows [n]: n diff --git a/cookiecutter.json b/cookiecutter.json index 0cae40739..89148ec21 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -10,8 +10,7 @@ "use_whitenoise": "y", "use_celery": "n", "use_mailhog": "n", - "use_sentry": "n", - "use_newrelic": "n", + "use_sentry_for_error_reporting": "y", "use_opbeat": "n", "use_pycharm": "n", "windows": "n", diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 9ffad1e5f..2ea27c53b 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -39,7 +39,7 @@ use_mailhog [n] 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 [n] +use_sentry_for_error_reporting [n] Whether to use Sentry_ to log errors from your project. windows [n] diff --git a/{{cookiecutter.project_slug}}/Procfile b/{{cookiecutter.project_slug}}/Procfile index a5476341a..c77d76d96 100644 --- a/{{cookiecutter.project_slug}}/Procfile +++ b/{{cookiecutter.project_slug}}/Procfile @@ -1,4 +1,4 @@ web: gunicorn config.wsgi:application {% if cookiecutter.use_celery == "y" -%} -worker: {% if cookiecutter.use_newrelic == "y" %}newrelic-admin run-program {% endif %}celery worker --app={{cookiecutter.project_slug}}.taskapp --loglevel=info +worker: celery worker --app={{cookiecutter.project_slug}}.taskapp --loglevel=info {%- endif %} diff --git a/{{cookiecutter.project_slug}}/README.rst b/{{cookiecutter.project_slug}}/README.rst index 38d923b66..170f66a71 100644 --- a/{{cookiecutter.project_slug}}/README.rst +++ b/{{cookiecutter.project_slug}}/README.rst @@ -104,7 +104,7 @@ The email server will exit when you exit the Grunt task on the CLI with Ctrl+C. {% endif %} {% endif %} -{% if cookiecutter.use_sentry == "y" %} +{% if cookiecutter.use_sentry_for_error_reporting == "y" %} Sentry ^^^^^^ diff --git a/{{cookiecutter.project_slug}}/app.json b/{{cookiecutter.project_slug}}/app.json index 6e6585fd7..a23494587 100644 --- a/{{cookiecutter.project_slug}}/app.json +++ b/{{cookiecutter.project_slug}}/app.json @@ -20,12 +20,8 @@ "DJANGO_AWS_SECRET_ACCESS_KEY": "", "DJANGO_AWS_STORAGE_BUCKET_NAME": "", "DJANGO_MAILGUN_SERVER_NAME": "", - {% if cookiecutter.use_newrelic == "y" -%} - "NEW_RELIC_LICENSE_KEY": "", - "NEW_RELIC_APP_NAME": "", - {%- endif %} - "DJANGO_MAILGUN_API_KEY": ""{% if cookiecutter.use_sentry == "y" -%}, - "DJANGO_SENTRY_DSN": ""{%- endif %} + "DJANGO_MAILGUN_API_KEY": ""{% if cookiecutter.use_sentry_for_error_reporting == "y" -%}, + "DJANGO_SENTRY_DSN": ""{%- endif %} }, "scripts": { "postdeploy": "python manage.py migrate" diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 346bf7cb6..ae00b4723 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -6,7 +6,7 @@ Production Configurations - Use Amazon's S3 for storing static files and uploaded media - Use mailgun to send emails - Use Redis on Heroku -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} - Use sentry for error logging {% endif %} {% if cookiecutter.use_opbeat == 'y' %} @@ -17,7 +17,7 @@ from __future__ import absolute_import, unicode_literals from boto.s3.connection import OrdinaryCallingFormat from django.utils import six -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} import logging {% endif %} @@ -33,7 +33,8 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') # This ensures that Django will be able to detect a secure connection # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -{%- if cookiecutter.use_sentry == 'y'-%} + +{%- if cookiecutter.use_sentry_for_error_reporting == 'y'-%} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) @@ -44,7 +45,7 @@ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', ) MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES {% endif %} -{%- if cookiecutter.use_sentry == 'y' -%} +{%- if cookiecutter.use_sentry_for_error_reporting == 'y' -%} RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ) MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES {% endif %} @@ -161,11 +162,6 @@ ANYMAIL = { } EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend" -{% if cookiecutter.use_newrelic == 'y'-%}# NEW RELIC -# ------------------------------------------------------------------------------ -NEW_RELIC_LICENSE_KEY = env('NEW_RELIC_LICENSE_KEY') -NEW_RELIC_APP_NAME = env('NEW_RELIC_APP_NAME') -{%- endif %} # TEMPLATE CONFIGURATION # ------------------------------------------------------------------------------ # See: @@ -195,7 +191,7 @@ CACHES = { } } -{% if cookiecutter.use_sentry == 'y' %} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' %} # Sentry Configuration SENTRY_DSN = env('DJANGO_SENTRY_DSN') SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient') @@ -251,7 +247,7 @@ RAVEN_CONFIG = { 'CELERY_LOGLEVEL': env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO), 'DSN': SENTRY_DSN } -{% elif cookiecutter.use_sentry == 'n' %} +{% elif cookiecutter.use_sentry_for_error_reporting == 'n' %} # LOGGING CONFIGURATION # ------------------------------------------------------------------------------ # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging diff --git a/{{cookiecutter.project_slug}}/config/wsgi.py b/{{cookiecutter.project_slug}}/config/wsgi.py index 4790b1b50..636f547a4 100644 --- a/{{cookiecutter.project_slug}}/config/wsgi.py +++ b/{{cookiecutter.project_slug}}/config/wsgi.py @@ -15,13 +15,8 @@ framework. """ import os -{% if cookiecutter.use_newrelic == 'y' -%} -if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': - import newrelic.agent - newrelic.agent.initialize() -{%- endif %} from django.core.wsgi import get_wsgi_application -{% if cookiecutter.use_sentry == 'y' -%} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': from raven.contrib.django.raven_compat.middleware.wsgi import Sentry {%- endif %} @@ -36,14 +31,10 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. application = get_wsgi_application() -{% if cookiecutter.use_sentry == 'y' -%} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': application = Sentry(application) {%- endif %} -{% if cookiecutter.use_newrelic == 'y' -%} -if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': - application = newrelic.agent.WSGIApplicationWrapper(application) -{%- endif %} # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) diff --git a/{{cookiecutter.project_slug}}/env.example b/{{cookiecutter.project_slug}}/env.example index bbea38b22..a982dc92f 100644 --- a/{{cookiecutter.project_slug}}/env.example +++ b/{{cookiecutter.project_slug}}/env.example @@ -12,13 +12,9 @@ DJANGO_MAILGUN_API_KEY= DJANGO_SERVER_EMAIL= DJANGO_SECURE_SSL_REDIRECT=False DJANGO_ACCOUNT_ALLOW_REGISTRATION=True -{% if cookiecutter.use_sentry == 'y' -%} +{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} DJANGO_SENTRY_DSN= {% endif %} -{% if cookiecutter.use_newrelic == 'y' -%} -NEW_RELIC_LICENSE_KEY= -NEW_RELIC_APP_NAME={{cookiecutter.project_slug}} -{% endif %} {% if cookiecutter.use_opbeat == 'y' -%} DJANGO_OPBEAT_ORGANIZATION_ID DJANGO_OPBEAT_APP_ID diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 5ac46e62d..16c7ea800 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -26,18 +26,12 @@ Collectfast==0.2.3 # ------------------------------------------------------- django-anymail==0.3.1 -{% if cookiecutter.use_sentry == "y" -%} +{% if cookiecutter.use_sentry_for_error_reporting == "y" -%} # Raven is the Sentry client # -------------------------- raven {%- endif %} -{% if cookiecutter.use_newrelic == "y" -%} -# Newrelic agent for performance monitoring -# ----------------------------------------- -newrelic -{%- endif %} - {% if cookiecutter.use_opbeat == "y" -%} # Opbeat agent for performance monitoring # ----------------------------------------- diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py index 44c57f7c1..7905e3660 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/taskapp/celery.py @@ -24,7 +24,7 @@ class CeleryConfig(AppConfig): app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.INSTALLED_APPS, force=True) - {% if cookiecutter.use_sentry == 'y' -%} + {% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} if hasattr(settings, 'RAVEN_CONFIG'): # Celery signal registration from raven import Client as RavenClient From fd2e7dd0fe2ca0ea4254cbbbc47eac1b84c5d9e1 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 11:04:48 -0700 Subject: [PATCH 27/73] Whitespace fix --- {{cookiecutter.project_slug}}/config/settings/production.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index ae00b4723..e2bac6c9e 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -34,7 +34,7 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') # properly on Heroku. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -{%- if cookiecutter.use_sentry_for_error_reporting == 'y'-%} +{%- if cookiecutter.use_sentry_for_error_reporting == 'y' %} # raven sentry client # See https://docs.getsentry.com/hosted/clients/python/integrations/django/ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) From 783e7f644e2fc659d432d447bbbe6a01f2ac74c1 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 12:32:05 -0700 Subject: [PATCH 28/73] Fix #390 #450 --- .../{{cookiecutter.project_slug}}/users/admin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py index bd437fe1e..ce6d8e13a 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py @@ -5,7 +5,6 @@ from django import forms from django.contrib import admin from django.contrib.auth.admin import UserAdmin as AuthUserAdmin from django.contrib.auth.forms import UserChangeForm, UserCreationForm - from .models import User @@ -24,7 +23,7 @@ class MyUserCreationForm(UserCreationForm): model = User def clean_username(self): - username = self.cleaned_data['username'] + username = self.cleaned_data["username"] try: User.objects.get(username=username) except User.DoesNotExist: @@ -33,6 +32,11 @@ class MyUserCreationForm(UserCreationForm): @admin.register(User) -class UserAdmin(AuthUserAdmin): +class MyUserAdmin(AuthUserAdmin): form = MyUserChangeForm add_form = MyUserCreationForm + fieldsets = ( + ('User Profile', {'fields': ('name',)}), + ) + AuthUserAdmin.fieldsets + list_display = ('username', 'name', 'is_superuser') + search_fields = ['name'] From 8e258ee611e55e76e5badab0a456def13d9f1549 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 12:33:36 -0700 Subject: [PATCH 29/73] Changelog update --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea494cfa..838b3dada 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/). +##[2016-06-05] +### Added +- Configurable admin for users (@pydanny, @jayfk, @dezoito) + ##[2016-06-04] ### Added - Let's Encrypt automation and instruction (@mjsisley and @chrisdev) From a65a75046451f7c71c34574372e7358d2bef0509 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 13:17:19 -0700 Subject: [PATCH 30/73] Switch use_certbot to the MUCH more explicit use_letsencrypt --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 8 ++++---- {{cookiecutter.project_slug}}/compose/nginx/Dockerfile | 2 +- {{cookiecutter.project_slug}}/compose/nginx/nginx.conf | 2 +- {{cookiecutter.project_slug}}/docker-compose.yml | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 89148ec21..9b21f3cdc 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -18,6 +18,6 @@ "use_docker": "y", "use_heroku": "n", "js_task_runner": ["Gulp", "Grunt", "None"], - "use_certbot": "n", + "use_lets_encrypt": "n", "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 22e9acb9e..0d970f3f8 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -215,7 +215,7 @@ else: remove_packageJSON_file() # 7. Removes all certbot/letsencrypt files if it isn't going to be used -if '{{ cookiecutter.use_certbot }}'.lower() != 'y': +if '{{ cookiecutter.use_lets_encrypt }}'.lower() != 'y': remove_certbot_files() # 8. Display a warning if use_docker and use_grunt are selected. Grunt isn't @@ -227,8 +227,8 @@ if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cook "js task runner service to your docker configuration manually." ) -# 9. Removes the certbot/letsencrypt files and display a warning if use_certbot is selected and use_docker isn't. -if '{{ cookiecutter.use_certbot }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': +# 9. Removes the certbot/letsencrypt files and display a warning if use_lets_encrypt is selected and use_docker isn't. +if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_certbot_files() print( "You selected to use certbot(letsencrypt) and didn't select to use docker. This is NOT supported out of the box for now. You " @@ -236,7 +236,7 @@ if '{{ cookiecutter.use_certbot }}'.lower() == 'y' and '{{ cookiecutter.use_dock ) # 10. Directs the user to the documentation if certbot and docker are selected. -if '{{ cookiecutter.use_certbot }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( "You selected to use certbot(letsencrypt), please see the documentation for instructions on how to use this in production. " "You must generate a dhparams.pem file before running docker-compose in a production environment." diff --git a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile index 7bb605584..b9e7985f8 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile @@ -1,7 +1,7 @@ FROM nginx:latest ADD nginx.conf /etc/nginx/nginx.conf -{% if cookiecutter.use_certbot == 'y' and cookiecutter.use_docker == 'y' %} +{% if cookiecutter.use_lets_encrypt == 'y' and cookiecutter.use_docker == 'y' %} ADD start.sh /start.sh ADD nginx-secure.conf /etc/nginx/nginx-secure.conf ADD dhparams.pem /etc/ssl/private/dhparams.pem diff --git a/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf b/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf index 54d955d7f..91bd96ec9 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf +++ b/{{cookiecutter.project_slug}}/compose/nginx/nginx.conf @@ -35,7 +35,7 @@ http { listen 80; charset utf-8; - {% if cookiecutter.use_certbot == 'y' and cookiecutter.use_docker == 'y' %} + {% if cookiecutter.use_lets_encrypt == 'y' and cookiecutter.use_docker == 'y' %} server_name ___my.example.com___ ; location /.well-known/acme-challenge { diff --git a/{{cookiecutter.project_slug}}/docker-compose.yml b/{{cookiecutter.project_slug}}/docker-compose.yml index a67ec0bb4..f0c48406e 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.yml @@ -27,12 +27,12 @@ services: build: ./compose/nginx depends_on: - django -{% if cookiecutter.use_certbot == 'y' %} +{% if cookiecutter.use_lets_encrypt == 'y' %} - certbot {% endif %} ports: - "0.0.0.0:80:80" -{% if cookiecutter.use_certbot == 'y' %} +{% if cookiecutter.use_lets_encrypt == 'y' %} environment: - MY_DOMAIN_NAME={{ cookiecutter.domain_name }} ports: From c56e4ef61618280c12d7bba69d361c782194ecbd Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 14:16:02 -0700 Subject: [PATCH 31/73] Fix the remove file problem --- hooks/post_gen_project.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 0d970f3f8..c59d7d65f 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -82,6 +82,11 @@ def make_secret_key(project_directory): set_secret_key(env_file) +def remove_file(file_name): + if os.path.exists(file_name): + os.remove(file_name) + + def remove_task_app(project_directory): """Removes the taskapp if celery isn't going to be used""" # Determine the local_setting_file_location @@ -111,9 +116,8 @@ def remove_heroku_files(): Removes files needed for heroku if it isn't going to be used """ for filename in ["app.json", "Procfile", "requirements.txt", "runtime.txt"]: - os.remove(os.path.join( - PROJECT_DIRECTORY, filename - )) + file_name = os.path.join(PROJECT_DIRECTORY, filename) + remove_file(file_name) def remove_docker_files(): @@ -163,9 +167,8 @@ def remove_certbot_files(): """ nginx_dir_location = os.path.join(PROJECT_DIRECTORY, 'compose/nginx') for filename in ["nginx-secure.conf", "start.sh", "dhparams.example.pem"]: - os.remove(os.path.join( - nginx_dir_location, filename - )) + file_name = os.path.join(nginx_dir_location, filename) + remove_file(file_name) # IN PROGRESS # def copy_doc_files(project_directory): From df56488f01998a02fd8b25a350c1c9495afdb836 Mon Sep 17 00:00:00 2001 From: "requires.io" Date: Sun, 5 Jun 2016 16:30:17 -0700 Subject: [PATCH 32/73] [requires.io] dependency update --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d63bed873..3d6afb30e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ sh==1.11 binaryornot==0.4.0 # Testing -pytest==2.9.1 +pytest==2.9.2 pep8==1.7.0 pyflakes==1.2.3 tox==2.3.1 From 4f552745038028e75a0ff06dacd8c86ccae9853d Mon Sep 17 00:00:00 2001 From: "requires.io" Date: Sun, 5 Jun 2016 16:30:18 -0700 Subject: [PATCH 33/73] [requires.io] dependency update --- {{cookiecutter.project_slug}}/requirements/test.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/requirements/test.txt b/{{cookiecutter.project_slug}}/requirements/test.txt index 0451bc60f..b8531505a 100644 --- a/{{cookiecutter.project_slug}}/requirements/test.txt +++ b/{{cookiecutter.project_slug}}/requirements/test.txt @@ -7,10 +7,10 @@ psycopg2==2.6.1 {%- endif %} -coverage==4.0.3 -django_coverage_plugin==1.3 +coverage==4.1 +django-coverage-plugin==1.3.1 flake8==2.5.4 -django-test-plus==1.0.12 +django-test-plus==1.0.13 factory_boy==2.7.0 # pytest From d14be9939b9a3dd0855101ce69fb344731aa14cb Mon Sep 17 00:00:00 2001 From: "requires.io" Date: Sun, 5 Jun 2016 16:30:19 -0700 Subject: [PATCH 34/73] [requires.io] dependency update --- {{cookiecutter.project_slug}}/requirements/base.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index 67a6fd6b0..5450a0988 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -7,17 +7,17 @@ wheel==0.29.0 {%- endif %} # Bleeding edge Django -django==1.9.6 +django==1.9.7 # Configuration django-environ==0.4.0 {% if cookiecutter.use_whitenoise == 'y' -%} -whitenoise==3.0 +whitenoise==3.2 {%- endif %} # Forms -django-braces==1.8.1 +django-braces==1.9.0 django-crispy-forms==1.6.0 django-floppyforms==1.6.2 @@ -47,7 +47,7 @@ django-autoslug==1.9.3 pytz==2016.4 # Redis support -django-redis==4.4.2 +django-redis==4.4.3 redis>=2.10.0 {% if cookiecutter.use_celery == "y" %} From 5408ccbef92575553544d367a022258cc446eeb0 Mon Sep 17 00:00:00 2001 From: "requires.io" Date: Sun, 5 Jun 2016 16:30:20 -0700 Subject: [PATCH 35/73] [requires.io] dependency update --- {{cookiecutter.project_slug}}/requirements/production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 16c7ea800..2db9d2678 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -12,7 +12,7 @@ psycopg2==2.6.1 # WSGI Handler # ------------------------------------------------ gevent==1.1.1 -gunicorn==19.5.0 +gunicorn==19.6.0 # Static and Media Storage # ------------------------------------------------ From faa8eaf32dd9d33d6d281219c66d30bef1c2cd18 Mon Sep 17 00:00:00 2001 From: "requires.io" Date: Sun, 5 Jun 2016 16:30:21 -0700 Subject: [PATCH 36/73] [requires.io] dependency update --- {{cookiecutter.project_slug}}/requirements/local.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/{{cookiecutter.project_slug}}/requirements/local.txt b/{{cookiecutter.project_slug}}/requirements/local.txt index c88093fef..0b43dde2d 100644 --- a/{{cookiecutter.project_slug}}/requirements/local.txt +++ b/{{cookiecutter.project_slug}}/requirements/local.txt @@ -1,11 +1,11 @@ # Local development dependencies go here -r base.txt -coverage==4.0.3 -django_coverage_plugin==1.3 +coverage==4.1 +django-coverage-plugin==1.3.1 Sphinx django-extensions==1.6.7 -Werkzeug==0.11.9 -django-test-plus==1.0.12 +Werkzeug==0.11.10 +django-test-plus==1.0.13 factory_boy==2.7.0 django-debug-toolbar==1.4 From 203afd5c19b44596beda62e88ce43fd34cddd0c5 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 5 Jun 2016 17:21:59 -0700 Subject: [PATCH 37/73] Fix borked Americanese to be English --- hooks/post_gen_project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index c59d7d65f..d83d92287 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -234,14 +234,14 @@ if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cook if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_certbot_files() print( - "You selected to use certbot(letsencrypt) and didn't select to use docker. This is NOT supported out of the box for now. You " - "can continue to use the project like you normally would, but you will no certbot files have been included" + "You selected to use Let's Encrypt and didn't select to use docker. This is NOT supported out of the box for now. You " + "can continue to use the project like you normally would, but Let's Encrypt files have been included." ) # 10. Directs the user to the documentation if certbot and docker are selected. if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( - "You selected to use certbot(letsencrypt), please see the documentation for instructions on how to use this in production. " + "You selected to use Let's Encrypt, please see the documentation for instructions on how to use this in production. " "You must generate a dhparams.pem file before running docker-compose in a production environment." ) From 83db25211d12c818cecfa6ed037e37434f8c151b Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 13:47:26 +0000 Subject: [PATCH 38/73] Update Bootstrap CSS and JS to v4.0.0-alpha.2 minified. Fixes #589 --- .../{{cookiecutter.project_slug}}/templates/base.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html index a1e2a5ace..bc9dc5527 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html @@ -15,7 +15,7 @@ {% block css %} - + @@ -95,7 +95,7 @@ - + From 437e5898c7df254fcee436a11c3f9c9d3708c680 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 14:14:41 +0000 Subject: [PATCH 39/73] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 838b3dada..4c41c8ceb 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/). +##[2016-06-06] +### Changed +- Pin Bootstrap CSS and JS to v4.0.0-alpha.2, use minified versions + ##[2016-06-05] ### Added - Configurable admin for users (@pydanny, @jayfk, @dezoito) From 7f1e4e29d692a8dd37af395759e9eafcc933476d Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 14:15:41 +0000 Subject: [PATCH 40/73] Add self to CONTRIBUTORS.rst --- CONTRIBUTORS.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index fb7be02e8..80025914b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -83,6 +83,7 @@ Listed in alphabetical order. Jens Nilsson `@phiberjenz` Julio Castillo `@juliocc`_ Kaido Kert `@kaidokert`_ + kappataumu `@kappataumu`_ @kappataumu Kaveh `@ka7eh`_ Kevin A. Stone Kevin Ndung'u `@kevgathuku`_ @@ -162,6 +163,7 @@ Listed in alphabetical order. .. _@jvanbrug: https://github.com/jvanbrug .. _@ka7eh: https://github.com/ka7eh .. _@kaidokert: https://github.com/kaidokert +.. _@kappataumu: https://github.com/kappataumu .. _@kevgathuku: https://github.com/kevgathuku .. _@knitatoms: https://github.com/knitatoms .. _@MathijsHoogland: https://github.com/MathijsHoogland From b388ec1f57ac66748a94ebc14e303ab597f828a9 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 15:45:02 +0000 Subject: [PATCH 41/73] Fix malformed table in CONTRIBUTORS.rst (broke in 38c6fb75ed) --- CONTRIBUTORS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 80025914b..cbec308a9 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -116,7 +116,7 @@ Listed in alphabetical order. Théo Segonds `@show0k`_ Tom Atkins `@knitatoms`_ Tom Offermann - Travis McNeill `@Travistock`_ @tavistock_esq + Travis McNeill `@Travistock`_ @tavistock_esq Vitaly Babiy Vivian Guillen `@viviangb`_ Yaroslav Halchenko From febd154ac84391bc15a0696b09f7a116d96ab60b Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 16:24:19 +0000 Subject: [PATCH 42/73] Fix unknown target name docutil errors --- CONTRIBUTORS.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index cbec308a9..810dcea9e 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -187,6 +187,8 @@ Listed in alphabetical order. .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho .. _@noisy: https://github.com/noisy +.. _@krzysztofzuraw: https://github.com/krzysztofzuraw +.. _@blopker: https://github.com/blopker Special Thanks ~~~~~~~~~~~~~~ From c881b4ec338c945820ec6d9ff37397c6d0fb4bad Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 6 Jun 2016 17:18:18 +0000 Subject: [PATCH 43/73] [OCD] Sort alphabetically even though not needed --- CONTRIBUTORS.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 810dcea9e..ee41b6b45 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -122,7 +122,6 @@ Listed in alphabetical order. Yaroslav Halchenko ========================== ============================ ============== -.. _@dezoito: https://github.com/dezoito .. _@a7p: https://github.com/a7p .. _@ad-m: https://github.com/ad-m .. _@aeikenberry: https://github.com/aeikenberry @@ -132,6 +131,7 @@ Listed in alphabetical order. .. _@areski: https://github.com/areski .. _@arruda: https://github.com/arruda .. _@bloodpet: https://github.com/bloodpet +.. _@blopker: https://github.com/blopker .. _@bogdal: https://github.com/bogdal .. _@burhan: https://github.com/burhan .. _@c-rhodes: https://github.com/c-rhodes @@ -143,6 +143,7 @@ Listed in alphabetical order. .. _@ChrisPappalardo: https://github.com/ChrisPappalardo .. _@Collederas: https://github.com/Collederas .. _@ddiazpinto: https://github.com/ddiazpinto +.. _@dezoito: https://github.com/dezoito .. _@dot2dotseurat: https://github.com/dot2dotseurat .. _@dsclementsen: https://github.com/dsclementsen .. _@epileptic-fish: https://gihub.com/epileptic-fish @@ -158,7 +159,6 @@ Listed in alphabetical order. .. _@ikkebr: https://github.com/ikkebr .. _@iynaix: https://github.com/iynaix .. _@jazztpt: https://github.com/jazztpt -.. _@xpostudio4: https://github.com/xpostudio4 .. _@juliocc: https://github.com/juliocc .. _@jvanbrug: https://github.com/jvanbrug .. _@ka7eh: https://github.com/ka7eh @@ -166,29 +166,29 @@ Listed in alphabetical order. .. _@kappataumu: https://github.com/kappataumu .. _@kevgathuku: https://github.com/kevgathuku .. _@knitatoms: https://github.com/knitatoms +.. _@krzysztofzuraw: https://github.com/krzysztofzuraw .. _@MathijsHoogland: https://github.com/MathijsHoogland .. _@menzenski: https://github.com/menzenski .. _@mfwarren: https://github.com/mfwarren .. _@mjsisley: https://github.com/mjsisley .. _@mozillazg: https://github.com/mozillazg +.. _@noisy: https://github.com/noisy .. _@originell: https://github.com/originell .. _@oubiga: https://github.com/oubiga -.. _@romanosipenko: https://github.com/romanosipenko .. _@raonyguimaraes: https://github.com/raonyguimaraes +.. _@romanosipenko: https://github.com/romanosipenko +.. _@shireenrao: https://github.com/shireenrao .. _@show0k: https://github.com/show0k .. _@siauPatrick: https://github.com/siauPatrick -.. _@shireenrao: https://github.com/shireenrao .. _@slafs: https://github.com/slafs .. _@stepmr: https://github.com/stepmr .. _@suledev: https://github.com/suledev .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong .. _@viviangb: httpsL//github.com/viviangb +.. _@xpostudio4: https://github.com/xpostudio4 .. _@yunti: https://github.com/yunti .. _@zcho: https://github.com/zcho -.. _@noisy: https://github.com/noisy -.. _@krzysztofzuraw: https://github.com/krzysztofzuraw -.. _@blopker: https://github.com/blopker Special Thanks ~~~~~~~~~~~~~~ From b8f58a08aa1b72a29a760d9f337f1ee56756a938 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Tue, 7 Jun 2016 03:21:39 +0300 Subject: [PATCH 44/73] Fixes issue #588 (#597) --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index fa7c88d35..8836630a1 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,8 @@ Cookiecutter Django Powered by Cookiecutter_, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. -See Troubleshooting_ for common errors and obstacles. +* Documentation: https://cookiecutter-django.readthedocs.io +* See Troubleshooting_ for common errors and obstacles .. _cookiecutter: https://github.com/audreyr/cookiecutter From e24b777a412008558ffd60811f359d1309184d19 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Tue, 7 Jun 2016 15:19:25 -0700 Subject: [PATCH 45/73] Added direct signup --- {{cookiecutter.project_slug}}/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/README.rst b/{{cookiecutter.project_slug}}/README.rst index 170f66a71..55a520c54 100644 --- a/{{cookiecutter.project_slug}}/README.rst +++ b/{{cookiecutter.project_slug}}/README.rst @@ -109,7 +109,7 @@ The email server will exit when you exit the Grunt task on the CLI with Ctrl+C. Sentry ^^^^^^ -Sentry is an error logging aggregator service. You can sign up for a free account at http://getsentry.com or download and host it yourself. +Sentry is an error logging aggregator service. You can sign up for a free account at https://getsentry.com/signup/?code=cookiecutter or download and host it yourself. The system is setup with reasonable defaults, including 404 logging and integration with the WSGI application. You must set the DSN url in production. From f358204bdc82cb6c5d1ddaec826ee2c8623970a9 Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Wed, 8 Jun 2016 11:12:10 -0700 Subject: [PATCH 46/73] Minor improvements to 'Deployment with Docker'. Part of #566 --- docs/deployment-with-docker.rst | 60 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index 61ed05f49..09f7883b3 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -3,47 +3,66 @@ Deployment with Docker .. index:: Docker, deployment -TODO: Review and revise - -**Warning** - -Docker is evolving extremely fast, but it has still some rough edges here and there. Compose is currently (as of version 1.4) +.. warning:: Docker is evolving extremely fast, but it has still some rough edges here and there. +Compose is currently (as of version 1.4) not considered production ready. That means you won't be able to scale to multiple servers and you won't be able to run zero downtime deployments out of the box. Consider all this as experimental until you understand all the implications to run docker (with compose) on production. -**Run your app with docker-compose** - Prerequisites: -* docker (at least 1.10) -* docker-compose (at least 1.6) +* Docker (at least 1.10) +* Docker Compose (at least 1.6) + +Understand the Compose Setup +-------------------------------- Before you start, check out the `docker-compose.yml` file in the root of this project. This is where each component -of this application gets its configuration from. It consists of a `postgres` service that runs the database, `redis` -for caching, `nginx` as reverse proxy and last but not least the `django` application run by gunicorn. -{% if cookiecutter.use_celery == 'y' -%} -Since this application also runs Celery, there are two more services with a service called `celeryworker` that runs the -celery worker process and `celerybeat` that runs the celery beat process. -{% endif %} +of this application gets its configuration from. Notice how it provides configuration for these services: +* `postgres` service that runs the database +* `redis` for caching +* `nginx` as reverse proxy +* `django` is the Django project run by gunicorn -All of these services except `redis` rely on environment variables set by you. There is an `env.example` file in the +If you chose the `use_celery` option, there are two more services: + +* `celeryworker` which runs the celery worker process +* `celerybeat` which runs the celery beat process + +If you chose the `use_letsencrypt` option, you also have: + +* `certbot` which keeps your certs from letsencrypt up-to-date + +Populate .env With Your Environment Variables +--------------------------------------------- + +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. +Optional: nginx-proxy Setup +--------------------------- By default, the application is configured to listen on all interfaces on port 80. If you want to change that, open the -`docker-compose.yml` file and replace `0.0.0.0` with your own ip. If you are using `nginx-proxy`_ to run multiple -application stacks on one host, remove the port setting entirely and add `VIRTUAL_HOST={{cookiecutter.domain_name}}` to your env file. +`docker-compose.yml` file and replace `0.0.0.0` with your own ip. + +If you are using `nginx-proxy`_ to run multiple application stacks on one host, remove the port setting entirely and add `VIRTUAL_HOST=example.com` to your env file. Here, replace example.com with the value you entered for `domain_name`. + This pass all incoming requests on `nginx-proxy`_ to the nginx service your application is using. .. _nginx-proxy: https://github.com/jwilder/nginx-proxy +Optional: Postgres Data Volume Modifications +--------------------------------------------- + Postgres is saving its database files to the `postgres_data` volume by default. Change that if you wan't 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. @@ -55,7 +74,6 @@ Once this is ready, you can run it with:: docker-compose up - To run a migration, open up a second terminal and run:: docker-compose run django python manage.py migrate @@ -64,7 +82,6 @@ To create a superuser, run:: docker-compose run django python manage.py createsuperuser - If you need a shell, run:: docker-compose run django python manage.py shell @@ -81,7 +98,8 @@ If you want to scale your application, run:: docker-compose scale celeryworker=2 -**Don't run the scale command on postgres or celerybeat** +Don't run the scale command on postgres or celerybeat +------------------------------------------------------ Once you are ready with your initial setup, you wan't 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 From 7de7aed7ab06a9e151c8230eff2cd9b7a7fb43b4 Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Wed, 8 Jun 2016 11:31:33 -0700 Subject: [PATCH 47/73] Copyright year in non-templated docs/ folder can't be templated --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index d33c8f316..293d0fc14 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,7 +46,7 @@ master_doc = 'index' # General information about the project. project = 'Cookiecutter Django' -copyright = '2013-{% now 'utc', '%Y' %}, Daniel Roy Greenfeld'.format(now.year) +copyright = "2013-2016, 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 From 3c980f13a37a45e563cf4c1263023aa83d5cf8a4 Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Wed, 8 Jun 2016 12:33:18 -0700 Subject: [PATCH 48/73] More Docker docs tidying --- docs/deployment-with-docker.rst | 64 +++++++++++++++------------------ 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index 09f7883b3..9ec4cd0ae 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -3,12 +3,6 @@ Deployment with Docker .. index:: Docker, deployment -.. warning:: Docker is evolving extremely fast, but it has still some rough edges here and there. -Compose is currently (as of version 1.4) -not considered production ready. That means you won't be able to scale to multiple servers and you won't be able to run -zero downtime deployments out of the box. Consider all this as experimental until you understand all the implications -to run docker (with compose) on production. - Prerequisites: * Docker (at least 1.10) @@ -97,37 +91,10 @@ If you want to scale your application, run:: docker-compose scale django=4 docker-compose scale celeryworker=2 +.. warning:: Don't run the scale command on postgres, celerybeat, certbot. -Don't run the scale command on postgres or celerybeat ------------------------------------------------------- - -Once you are ready with your initial setup, you wan't 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 up` in your projects root directory. - -If you are using `supervisor`, you can use this file as a starting point:: - - [program:{{cookiecutter.project_slug}}] - command=docker-compose up - directory=/path/to/{{cookiecutter.project_slug}} - redirect_stderr=true - autostart=true - autorestart=true - priority=10 - - -Place it in `/etc/supervisor/conf.d/{{cookiecutter.project_slug}}.conf` and run:: - - supervisorctl reread - supervisorctl start {{cookiecutter.project_slug}} - -To get the status, run:: - - supervisorctl status - -If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: - - docker-compose ps +Certbot and Let's Encrypt Setup +------------------------------- If you are using certbot for https, you must do the following before running anything with docker-compose: @@ -167,8 +134,33 @@ And then set a cronjob by running `crontab -e` and placing in it (period can be 0 4 * * 1 /path/to/bashscript/renew_certbot.sh +Supervisor Example +------------------- + +Once you are ready with your initial setup, you wan't 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 up` in your projects root directory. + +If you are using `supervisor`, you can use this file as a starting point:: + + [program:{{cookiecutter.project_slug}}] + command=docker-compose up + directory=/path/to/{{cookiecutter.project_slug}} + redirect_stderr=true + autostart=true + autorestart=true + priority=10 +Place it in `/etc/supervisor/conf.d/{{cookiecutter.project_slug}}.conf` and run:: + supervisorctl reread + supervisorctl start {{cookiecutter.project_slug}} +To get the status, run:: + supervisorctl status + +If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: + + docker-compose ps From ae5be42ff4670ca9ae8ba29efc0f01af0089f36f Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Wed, 8 Jun 2016 12:36:34 -0700 Subject: [PATCH 49/73] Reorder Docker deployment sections. Fix #606 --- docs/deployment-with-docker.rst | 85 +++++++++++++++++---------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index 9ec4cd0ae..c1e527aec 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -54,6 +54,47 @@ Optional: Postgres Data Volume Modifications Postgres is saving its database files to the `postgres_data` volume by default. Change that if you wan't something else and make sure to make backups since this is not done automatically. +Optional: Certbot and Let's Encrypt Setup +------------------------------------------ + +If you chose `use_letsencrypt` and will be using certbot for https, you must do the following before running anything with docker-compose: + +Replace dhparam.pem.example with a generated dhparams.pem file before running anything with docker-compose. You can generate this on ubuntu or OS X by running the following in the project root: + +:: + + $ openssl dhparam -out /path/to/project/compose/nginx/dhparams.pem 2048 + +If you would like to add additional subdomains to your certificate, you must add additional parameters to the certbot command in the `docker-compose.yml` file: + +Replace: + +:: + + command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email mjsisley@relawgo.com --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + +With: + +:: + + command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} -d www.{{ cookiecutter.domain_name }} -d etc.{{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + +Please be cognizant of Certbot/Letsencrypt certificate requests limits when getting this set up. The provide a test server that does not count against the limit while you are getting set up. + +The certbot certificates expire after 3 months. +If you would like to set up autorenewal of your certificates, the following commands can be put into a bash script: + +:: + + #!/bin/bash + cd + docker-compose run certbot bash -c "sleep 6 && certbot certonly --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" + docker exec pearl_nginx_1 nginx -s reload + +And then set a cronjob by running `crontab -e` and placing in it (period can be adjusted as desired): + +0 4 * * 1 /path/to/bashscript/renew_certbot.sh + Run your app with docker-compose -------------------------------- @@ -93,46 +134,10 @@ If you want to scale your application, run:: .. warning:: Don't run the scale command on postgres, celerybeat, certbot. -Certbot and Let's Encrypt Setup -------------------------------- +If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: -If you are using certbot for https, you must do the following before running anything with docker-compose: + docker-compose ps -Replace dhparam.pem.example with a generated dhparams.pem file before running anything with docker-compose. You can generate this on ubuntu or OS X by running the following in the project root: - -:: - - $ openssl dhparam -out /path/to/project/compose/nginx/dhparams.pem 2048 - -If you would like to add additional subdomains to your certificate, you must add additional parameters to the certbot command in the `docker-compose.yml` file: - -Replace: - -:: - - command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email mjsisley@relawgo.com --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" - -With: - -:: - - command: bash -c "sleep 6 && certbot certonly -n --standalone -d {{ cookiecutter.domain_name }} -d www.{{ cookiecutter.domain_name }} -d etc.{{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" - -Please be cognizant of Certbot/Letsencrypt certificate requests limits when getting this set up. The provide a test server that does not count against the limit while you are getting set up. - -The certbot certificates expire after 3 months. -If you would like to set up autorenewal of your certificates, the following commands can be put into a bash script: - -:: - - #!/bin/bash - cd - docker-compose run certbot bash -c "sleep 6 && certbot certonly --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" - docker exec pearl_nginx_1 nginx -s reload - -And then set a cronjob by running `crontab -e` and placing in it (period can be adjusted as desired): - -0 4 * * 1 /path/to/bashscript/renew_certbot.sh Supervisor Example ------------------- @@ -160,7 +165,3 @@ Place it in `/etc/supervisor/conf.d/{{cookiecutter.project_slug}}.conf` and run: To get the status, run:: supervisorctl status - -If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: - - docker-compose ps From 56efcaa475db18f300a8c7275877e773f30787dd Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Wed, 8 Jun 2016 12:51:55 -0700 Subject: [PATCH 50/73] Minor deployment-with-docker.rst improvements --- docs/deployment-with-docker.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index c1e527aec..e4545f770 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -1,9 +1,10 @@ Deployment with Docker -================================================= +======================= .. index:: Docker, deployment -Prerequisites: +Prerequisites +------------- * Docker (at least 1.10) * Docker Compose (at least 1.6) @@ -91,9 +92,9 @@ If you would like to set up autorenewal of your certificates, the following comm docker-compose run certbot bash -c "sleep 6 && certbot certonly --standalone -d {{ cookiecutter.domain_name }} --text --agree-tos --email {{ cookiecutter.email }} --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01" docker exec pearl_nginx_1 nginx -s reload -And then set a cronjob by running `crontab -e` and placing in it (period can be adjusted as desired): +And then set a cronjob by running `crontab -e` and placing in it (period can be adjusted as desired):: -0 4 * * 1 /path/to/bashscript/renew_certbot.sh + 0 4 * * 1 /path/to/bashscript/renew_certbot.sh Run your app with docker-compose -------------------------------- @@ -156,7 +157,6 @@ 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:: supervisorctl reread From b59d1b152058363ee6825b83f76c6451f8498573 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Wed, 8 Jun 2016 20:11:12 -0700 Subject: [PATCH 51/73] Begin addition of pyup.io per #608 --- README.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.rst b/README.rst index 8836630a1..aacecba22 100644 --- a/README.rst +++ b/README.rst @@ -1,10 +1,6 @@ Cookiecutter Django ======================= -.. image:: https://requires.io/github/pydanny/cookiecutter-django/requirements.svg?branch=master - :target: https://requires.io/github/pydanny/cookiecutter-django/requirements/?branch=master - :alt: Requirements Status - .. image:: https://travis-ci.org/pydanny/cookiecutter-django.svg?branch=master :target: https://travis-ci.org/pydanny/cookiecutter-django?branch=master :alt: Build Status From 1812546e99890406b389eec1841ebd53ffd89a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Thu, 9 Jun 2016 00:15:01 -0300 Subject: [PATCH 52/73] Improve install_os_dependencies.sh (#605) * rename requirements.apt -> requirements-trusty.apt and requirements.apt.xenial -> requirements-xenial.apt * improve install_os_dependencies.sh * remove unused non-python requirements * rename "install" function to "install_packages" and "upgrade" function to "upgrade_packages" to solve shellcheck lint errors --- .../utility/install_os_dependencies.sh | 29 ++++++------ ...quirements.apt => requirements-trusty.apt} | 3 +- .../utility/requirements-xenial.apt | 28 ++++++++++++ .../utility/requirements.apt.xenial | 44 ------------------- 4 files changed, 46 insertions(+), 58 deletions(-) rename {{cookiecutter.project_slug}}/utility/{requirements.apt => requirements-trusty.apt} (84%) create mode 100644 {{cookiecutter.project_slug}}/utility/requirements-xenial.apt delete mode 100644 {{cookiecutter.project_slug}}/utility/requirements.apt.xenial diff --git a/{{cookiecutter.project_slug}}/utility/install_os_dependencies.sh b/{{cookiecutter.project_slug}}/utility/install_os_dependencies.sh index cc1fb2f07..68ff079f1 100755 --- a/{{cookiecutter.project_slug}}/utility/install_os_dependencies.sh +++ b/{{cookiecutter.project_slug}}/utility/install_os_dependencies.sh @@ -1,14 +1,17 @@ #!/bin/bash WORK_DIR="$(dirname "$0")" -OS_REQUIREMENTS_FILENAME="$WORK_DIR/requirements.apt" +DISTRO_NAME=$(lsb_release -sc) -VER=$(lsb_release -sr) -if [ "$VER" == "16.04" ]; then - OS_REQUIREMENTS_FILENAME="requirements.apt.xenial" -else - OS_REQUIREMENTS_FILENAME="requirements.apt" +OS_REQUIREMENTS_FILENAME="$WORK_DIR/requirements-$DISTRO_NAME.apt" + + +if [ "$DISTRO_NAME" != "xenial" ] && [ "$DISTRO_NAME" != "trusty" ]; then + echo "Only the Ubuntu 14.04 (Trusty) and 16.04 (Xenial) is supported by this script"; + echo "You can see requirements-trusty.apt or requirements-xenial.apt file to help search the equivalent package in your system"; + exit 1; fi + # Handle call with wrong command function wrong_command() { @@ -31,15 +34,15 @@ function usage_message() # Read the requirements.apt file, and remove comments and blank lines function list_packages(){ - grep -v "#" ${OS_REQUIREMENTS_FILENAME} | grep -v "^$"; + grep -v "#" "${OS_REQUIREMENTS_FILENAME}" | grep -v "^$"; } -function install() +function install_packages() { list_packages | xargs apt-get --no-upgrade install -y; } -function upgrade() +function upgrade_packages() { list_packages | xargs apt-get install -y; } @@ -53,7 +56,7 @@ function install_or_upgrade() if [[ $EUID -ne 0 ]]; then echo -e "\nYou must run this with root privilege" 2>&1 echo -e "Please do:\n" 2>&1 - echo "sudo ./${0##*/} $PARAN" 2>&1 + echo "sudo ./$WORK_DIR/${0##*/} $PARAN" 2>&1 echo -e "\n" 2>&1 exit 1 @@ -63,9 +66,9 @@ function install_or_upgrade() # Install the basic compilation dependencies and other required libraries of this project if [ "$PARAN" == "install" ]; then - install; + install_packages; else - upgrade; + upgrade_packages; fi # cleaning downloaded packages from apt-get cache @@ -84,5 +87,5 @@ case "$1" in upgrade) install_or_upgrade "upgrade";; list) list_packages;; help) usage_message;; - *) wrong_command $1;; + *) wrong_command "$1";; esac diff --git a/{{cookiecutter.project_slug}}/utility/requirements.apt b/{{cookiecutter.project_slug}}/utility/requirements-trusty.apt similarity index 84% rename from {{cookiecutter.project_slug}}/utility/requirements.apt rename to {{cookiecutter.project_slug}}/utility/requirements-trusty.apt index 9a18d50d4..462af5729 100644 --- a/{{cookiecutter.project_slug}}/utility/requirements.apt +++ b/{{cookiecutter.project_slug}}/utility/requirements-trusty.apt @@ -1,4 +1,4 @@ -##basic build dependencies of various Django apps for Ubuntu 14.04 +##basic build dependencies of various Django apps for Ubuntu Trusty 14.04 #build-essential metapackage install: make, gcc, g++, build-essential #required to translate @@ -25,3 +25,4 @@ libwebp-dev ##django-extensions graphviz-dev + diff --git a/{{cookiecutter.project_slug}}/utility/requirements-xenial.apt b/{{cookiecutter.project_slug}}/utility/requirements-xenial.apt new file mode 100644 index 000000000..0688175be --- /dev/null +++ b/{{cookiecutter.project_slug}}/utility/requirements-xenial.apt @@ -0,0 +1,28 @@ +##basic build dependencies of various Django apps for Ubuntu Xenial 16.04 +#build-essential metapackage install: make, gcc, g++, +build-essential +#required to translate +gettext +{% if cookiecutter.use_python2 == 'n' -%} +python3-dev +{% else %} +python-dev +{%- endif %} + +##shared dependencies of: +##Pillow, pylibmc +zlib1g-dev + +##Postgresql and psycopg2 dependencies +libpq-dev + +##Pillow dependencies +libtiff5-dev +libjpeg8-dev +libfreetype6-dev +liblcms2-dev +libwebp-dev + +##django-extensions +graphviz-dev + diff --git a/{{cookiecutter.project_slug}}/utility/requirements.apt.xenial b/{{cookiecutter.project_slug}}/utility/requirements.apt.xenial deleted file mode 100644 index f29f6b400..000000000 --- a/{{cookiecutter.project_slug}}/utility/requirements.apt.xenial +++ /dev/null @@ -1,44 +0,0 @@ -##basic build dependencies of various Django apps for Ubuntu 14.04 -#build-essential metapackage install: make, gcc, g++, -build-essential -#required to translate -gettext -python-dev - -##shared dependencies of: -##Pillow, pylibmc -zlib1g-dev - -##Postgresql and psycopg2 dependencies -libpq-dev - -##Pillow dependencies -libtiff5-dev -libjpeg8-dev -libfreetype6-dev -liblcms2-dev -libwebp-dev - - -##django-extensions -graphviz-dev - -##hitch -python-setuptools -python3-dev -python-virtualenv -python-pip -firefox -automake -libtool -libreadline6 -libreadline6-dev -libreadline-dev -libsqlite3-dev -libxml2 -libxml2-dev -libssl-dev -libbz2-dev -wget -curl -llvm From 18963edc2e926a1f8bb1e0d9c77c8369c4d73b17 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Wed, 8 Jun 2016 22:53:21 -0700 Subject: [PATCH 53/73] More explicit naming --- {{cookiecutter.project_slug}}/env.example | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/{{cookiecutter.project_slug}}/env.example b/{{cookiecutter.project_slug}}/env.example index a982dc92f..3138a9df1 100644 --- a/{{cookiecutter.project_slug}}/env.example +++ b/{{cookiecutter.project_slug}}/env.example @@ -1,18 +1,29 @@ +# PostgreSQL POSTGRES_PASSWORD=mysecretpass POSTGRES_USER=postgresuser +# General settings DJANGO_ADMIN_URL= DJANGO_SETTINGS_MODULE=config.settings.production DJANGO_SECRET_KEY=CHANGEME!!! DJANGO_ALLOWED_HOSTS=.{{ cookiecutter.domain_name }} + +# AWS Settings DJANGO_AWS_ACCESS_KEY_ID= DJANGO_AWS_SECRET_ACCESS_KEY= DJANGO_AWS_STORAGE_BUCKET_NAME= + +# Used with email DJANGO_MAILGUN_API_KEY= DJANGO_SERVER_EMAIL= + +# Security! Better to use DNS for this task, but you can use redirect DJANGO_SECURE_SSL_REDIRECT=False + +# django-allauth DJANGO_ACCOUNT_ALLOW_REGISTRATION=True {% if cookiecutter.use_sentry_for_error_reporting == 'y' -%} +# Sentry DJANGO_SENTRY_DSN= {% endif %} {% if cookiecutter.use_opbeat == 'y' -%} From 29eb48efe8e039f0e0ef0ff6c77c71969d74d826 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Thu, 9 Jun 2016 08:23:02 -0700 Subject: [PATCH 54/73] Update README.rst --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index aacecba22..5c6613775 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,10 @@ Cookiecutter Django ======================= +.. image:: https://pyup.io/repos/github/pydanny/cookiecutter-django/shield.svg + :target: https://pyup.io/repos/github/pydanny/cookiecutter-django/ + :alt: Updates + .. image:: https://travis-ci.org/pydanny/cookiecutter-django.svg?branch=master :target: https://travis-ci.org/pydanny/cookiecutter-django?branch=master :alt: Build Status From b100f2a00d1879db16c3a6899a93c2934444569b Mon Sep 17 00:00:00 2001 From: Antonia Blair Date: Sat, 11 Jun 2016 23:50:25 -0400 Subject: [PATCH 55/73] Tweak env vars section of docs (#611) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks for the PR! 🍡 --- CONTRIBUTORS.rst | 2 ++ docs/developing-locally.rst | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index ee41b6b45..110d3db30 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -48,6 +48,7 @@ Listed in alphabetical order. Andrew Mikhnevich `@zcho`_ Andy Rose Anna Callahan `@jazztpt`_ + Antonia Blair `@antoniablair`_ @antoniablairart Areski Belaid `@areski`_ Ashley Camba Barclay Gauld `@yunti`_ @@ -128,6 +129,7 @@ Listed in alphabetical order. .. _@alb3rto: https://github.com/alb3rto .. _@amjith: https://github.com/amjith .. _@andor-pierdelacabeza: https://github.com/andor-pierdelacabeza +.. _@antoniablair: https://github.com/antoniablair .. _@areski: https://github.com/areski .. _@arruda: https://github.com/arruda .. _@bloodpet: https://github.com/bloodpet diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index a7f0269f3..02c9baf49 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -26,20 +26,22 @@ You can now run the usual Django ``migrate`` and ``runserver`` commands:: $ 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. +At this point you can take a break from setup and start getting to know the files in the project. -But if you want to go further with setup, read on. +But if you want to go further with setup, read on. (Note: the following sections still need to be revised) Setting Up Env Vars for Production ----------------------------------- - -`Cookiecutter Django` uses the excellent `django-environ`_ package with its ``DATABASE_URL`` environment variable to simplify database configuration in your Django settings. Now all you have to do is rename env.example to .env and then compose a definition for ``DATABASE_URL`` as shown below and add it to the .env file: + +`Cookiecutter Django` uses the excellent `django-environ`_ package, which includes a ``DATABASE_URL`` environment variable to simplify database configuration in your Django settings. + +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: .. parsed-literal:: - $ export DATABASE_URL="postgres://**:**\ @127.0.0.1:\ **/**" + DATABASE_URL="postgres://**:**\ @127.0.0.1:\ **/**" .. _django-environ: http://django-environ.readthedocs.io From 8445d957c5ed733d23c42b2d8864a607f48fdd65 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sat, 11 Jun 2016 21:20:24 -0700 Subject: [PATCH 56/73] History --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c41c8ceb..adbe9b049 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/). +##[2016-06-11] +### Changed +- Enhancements to the developing locally docs (@antoniablair) + ##[2016-06-06] ### Changed - Pin Bootstrap CSS and JS to v4.0.0-alpha.2, use minified versions From a6c803aaebebeb45a72271ac15c6ccab1b998ca9 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sat, 11 Jun 2016 21:22:35 -0700 Subject: [PATCH 57/73] Combine RUN commands --- .../compose/django/Dockerfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/django/Dockerfile index f2f662d5d..0123c58ad 100644 --- a/{{cookiecutter.project_slug}}/compose/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/django/Dockerfile @@ -8,18 +8,21 @@ ENV PYTHONUNBUFFERED 1 # Requirements have to be pulled and installed here, otherwise caching won't work COPY ./requirements /requirements -RUN pip install -r /requirements/production.txt +RUN pip install -r /requirements/production.txt \ + && groupadd -r django \ + && useradd -r -g django django -RUN groupadd -r django && useradd -r -g django django COPY . /app RUN chown -R django /app COPY ./compose/django/gunicorn.sh /gunicorn.sh COPY ./compose/django/entrypoint.sh /entrypoint.sh -RUN sed -i 's/\r//' /entrypoint.sh -RUN sed -i 's/\r//' /gunicorn.sh -RUN chmod +x /entrypoint.sh && chown django /entrypoint.sh -RUN chmod +x /gunicorn.sh && chown django /gunicorn.sh +RUN sed -i 's/\r//' /entrypoint.sh \ + && sed -i 's/\r//' /gunicorn.sh \ + && chmod +x /entrypoint.sh \ + && chown django /entrypoint.sh \ + && chmod +x /gunicorn.sh \ + && chown django /gunicorn.sh WORKDIR /app From 0b59df7af42515f3d913d1cbe91a78c795cbcd69 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Sun, 12 Jun 2016 23:11:50 -0700 Subject: [PATCH 58/73] Warn about scaling nginx --- docs/deployment-with-docker.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index e4545f770..c84daa1de 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -133,7 +133,7 @@ If you want to scale your application, run:: docker-compose scale django=4 docker-compose scale celeryworker=2 -.. warning:: Don't run the scale command on postgres, celerybeat, certbot. +.. warning:: Don't run the scale command on postgres, celerybeat, certbot, or nginx. If you have errors, you can always check your stack with `docker-compose`. Switch to your projects root directory and run:: From 8b8b13ed0d9ec86d9d22d727c720e67c67aaa9cc Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 13 Jun 2016 11:29:23 +0000 Subject: [PATCH 59/73] Fixes #603 --- docs/index.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 146c05572..9c83bcdea 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,8 +7,6 @@ A Cookiecutter_ template for Django. .. _cookiecutter: https://github.com/audreyr/cookiecutter -.. note:: This is an in-progress documentation reorganization. Locations of files may change dramatically over the course of the next few days. See https://github.com/pydanny/cookiecutter-django/issues/335 - Contents: .. toctree:: From 1e47efac8a00bb5a1b853248dfbed54308f5e629 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 13 Jun 2016 12:05:43 +0000 Subject: [PATCH 60/73] Fix reST issues --- docs/developing-locally.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 02c9baf49..6f5b282c1 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -51,15 +51,17 @@ Setup your email backend 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`_ .. _configure your email backend: http://docs.djangoproject.com/en/1.9/topics/email/#smtp-backend + {% if cookiecutter.use_docker == 'y' %} -In development you can (optionally) use MailHog_ for email testing. MailHog is added as docker-container. To use MailHog:: +In development you can (optionally) use MailHog_ for email testing. MailHog is added as 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`` .. _Mailhog: https://github.com/mailhog/MailHog/ + {% else %} -In development you can (optionally) use MailHog_ for email testing. MailHog is built with Go so there are no dependencies. To use MailHog:: +In development you can (optionally) use MailHog_ for email testing. MailHog is built with Go so there are no dependencies. To use MailHog: 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 @@ -69,6 +71,7 @@ In development you can (optionally) use MailHog_ for email testing. MailHog is b .. _Mailhog: https://github.com/mailhog/MailHog/ .. _Download the latest release: https://github.com/mailhog/MailHog/releases + {% endif %} Alternatively simply output emails to the console via: ``EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'`` From bfe72d52767ee04c4eadefdafdf1c7560e863f65 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 13 Jun 2016 12:12:32 +0000 Subject: [PATCH 61/73] Point to the docs instead of repeating everything --- docs/developing-locally.rst | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 6f5b282c1..196d03bfa 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -81,20 +81,6 @@ In production basic email configuration is setup to send emails with Mailgun_ **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 the included Grunt task. +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`_. -Make sure that nodejs_ is installed. Then in the project root run:: - - $ npm install - -.. _nodejs: http://nodejs.org/download/ - -Now you just need:: - - $ grunt serve - -The base app will now run as it would with the usual ``manage.py runserver`` but with live reloading and Sass compilation enabled. - -To get live reloading to work you'll probably need to install an `appropriate browser extension`_ - -.. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- +.. _prep work: https://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html From eeae4e8978d9c5eecce76edb55b924368612eea5 Mon Sep 17 00:00:00 2001 From: kappataumu Date: Mon, 13 Jun 2016 12:56:12 +0000 Subject: [PATCH 62/73] Move e-mail backend setup info for docker to the appropriate section --- docs/developing-locally-docker.rst | 8 ++++++++ docs/developing-locally.rst | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 7a11c7a4e..4c9ccac83 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -183,4 +183,12 @@ You may need to add the following to your css in order for the django-debug-tool } +Setup your email backend +~~~~~~~~~~~~~~~~~~~~~~~~ +In development you can (optionally) use MailHog_ for email testing. MailHog is added as 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`` + +.. _Mailhog: https://github.com/mailhog/MailHog/ diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 196d03bfa..6c84ca3c2 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -52,15 +52,6 @@ django-allauth sends an email to verify users (and superusers) after signup and .. _configure your email backend: http://docs.djangoproject.com/en/1.9/topics/email/#smtp-backend -{% if cookiecutter.use_docker == 'y' %} -In development you can (optionally) use MailHog_ for email testing. MailHog is added as 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`` - -.. _Mailhog: https://github.com/mailhog/MailHog/ - -{% else %} In development you can (optionally) use MailHog_ for email testing. MailHog is built with Go so there are no dependencies. To use MailHog: 1. `Download the latest release`_ for your operating system @@ -72,7 +63,6 @@ In development you can (optionally) use MailHog_ for email testing. MailHog is b .. _Mailhog: https://github.com/mailhog/MailHog/ .. _Download the latest release: https://github.com/mailhog/MailHog/releases -{% endif %} Alternatively simply output emails to the console via: ``EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'`` In production basic email configuration is setup to send emails with Mailgun_ From ad4082ceae89ea45df3eee6d0509eb580c3cb5fe Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Mon, 13 Jun 2016 08:40:48 -0700 Subject: [PATCH 63/73] Minor doc improvements --- docs/developing-locally-docker.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 4c9ccac83..0ef5510e9 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -1,5 +1,5 @@ -Getting Up and Running with Docker -================================== +Getting Up and Running Locally With Docker +========================================== .. index:: Docker @@ -9,7 +9,7 @@ All of these commands assume you are in the root of your generated project. Prerequisites ------------- -You'll need at least docker 1.10. +You'll need at least Docker 1.10. If you don't already have it installed, follow the instructions for your OS: @@ -183,10 +183,10 @@ You may need to add the following to your css in order for the django-debug-tool } -Setup your email backend -~~~~~~~~~~~~~~~~~~~~~~~~ +Using the Mailhog Docker Container +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In development you can (optionally) use MailHog_ for email testing. MailHog is added as docker-container. To use MailHog: +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`` From 36c58f1d2ce43ab985d102111e76539eea4cea3a Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Mon, 13 Jun 2016 14:10:23 -0700 Subject: [PATCH 64/73] Use latest redis docker image We use the latest Redis image because in Cookiecutter Django, Redis is only used to store ephemeral data. By ephemeral data I mean Celery tasks and various caching libraries. --- {{cookiecutter.project_slug}}/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/docker-compose.yml b/{{cookiecutter.project_slug}}/docker-compose.yml index f0c48406e..e4997f555 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.yml @@ -57,7 +57,7 @@ services: {% endif %} redis: - image: redis:3.0 + image: redis:latest {% if cookiecutter.use_celery == 'y' %} celeryworker: build: From 54feb6dd8c3a7e389bc37e60cd08545e82d0eab8 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 08:47:21 -0700 Subject: [PATCH 65/73] Pin opbeat to latest version 3.3.3 --- {{cookiecutter.project_slug}}/requirements/production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 2db9d2678..e73f4570c 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -35,5 +35,5 @@ raven {% if cookiecutter.use_opbeat == "y" -%} # Opbeat agent for performance monitoring # ----------------------------------------- -opbeat +opbeat==3.3.3 {%- endif %} From 3e9e8c3bae1a82d3fee388ace09d3f5f8cee61c6 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 08:47:24 -0700 Subject: [PATCH 66/73] Update flake8 from 2.5.4 to 2.5.5 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3d6afb30e..c44ab90e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ cookiecutter==1.4.0 -flake8==2.5.4 +flake8==2.5.5 sh==1.11 binaryornot==0.4.0 From fe07429a26a66a133ccab6220c964be634040623 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 08:47:25 -0700 Subject: [PATCH 67/73] Update flake8 from 2.5.4 to 2.5.5 --- {{cookiecutter.project_slug}}/requirements/test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/test.txt b/{{cookiecutter.project_slug}}/requirements/test.txt index b8531505a..215c93eaf 100644 --- a/{{cookiecutter.project_slug}}/requirements/test.txt +++ b/{{cookiecutter.project_slug}}/requirements/test.txt @@ -9,7 +9,7 @@ psycopg2==2.6.1 coverage==4.1 django-coverage-plugin==1.3.1 -flake8==2.5.4 +flake8==2.5.5 django-test-plus==1.0.13 factory_boy==2.7.0 From 7666e6941c69cedd166e6bc1d07a848db85614d5 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 08:47:27 -0700 Subject: [PATCH 68/73] Pin sphinx to latest version 1.4.4 --- {{cookiecutter.project_slug}}/requirements/local.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/local.txt b/{{cookiecutter.project_slug}}/requirements/local.txt index 0b43dde2d..4ebbfa462 100644 --- a/{{cookiecutter.project_slug}}/requirements/local.txt +++ b/{{cookiecutter.project_slug}}/requirements/local.txt @@ -2,7 +2,7 @@ -r base.txt coverage==4.1 django-coverage-plugin==1.3.1 -Sphinx +Sphinx==1.4.4 django-extensions==1.6.7 Werkzeug==0.11.10 django-test-plus==1.0.13 From 3d23787ce0fe8ec82ed4ec43c7ea0d62a61044f7 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 08:47:30 -0700 Subject: [PATCH 69/73] Pin raven to latest version 5.20.0 --- {{cookiecutter.project_slug}}/requirements/production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 2db9d2678..5bc678c75 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -29,7 +29,7 @@ django-anymail==0.3.1 {% if cookiecutter.use_sentry_for_error_reporting == "y" -%} # Raven is the Sentry client # -------------------------- -raven +raven==5.20.0 {%- endif %} {% if cookiecutter.use_opbeat == "y" -%} From 70c83be95155c03482a1cb2d73388876bb30109f Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 14 Jun 2016 14:11:20 -0700 Subject: [PATCH 70/73] Update ipdb from 0.10.0 to 0.10.1 --- {{cookiecutter.project_slug}}/requirements/local.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/local.txt b/{{cookiecutter.project_slug}}/requirements/local.txt index 4ebbfa462..d976e69e1 100644 --- a/{{cookiecutter.project_slug}}/requirements/local.txt +++ b/{{cookiecutter.project_slug}}/requirements/local.txt @@ -10,7 +10,7 @@ factory_boy==2.7.0 django-debug-toolbar==1.4 # improved REPL -ipdb==0.10.0 +ipdb==0.10.1 pytest-django==2.9.1 pytest-sugar==0.7.1 From 0a6b06ebe466393bc5f8702b3107d4e9793aa68b Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Tue, 14 Jun 2016 14:32:14 -0700 Subject: [PATCH 71/73] Breakup the backups section for docker into its own document --- docs/developing-locally-docker.rst | 29 ---------------------- docs/docker-postgres-backups.rst | 40 ++++++++++++++++++++++++++++++ docs/index.rst | 1 + 3 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 docs/docker-postgres-backups.rst diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 0ef5510e9..9fdd81ef7 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -91,35 +91,6 @@ Production Mode Instead of using `dev.yml`, you would use `docker-compose.yml`. -Database Backups -~~~~~~~~~~~~~~~~ - -The database has to be running to create/restore a backup. - -First, run the app with `docker-compose -f dev.yml up`. - -To create a backup, run:: - - docker-compose -f dev.yml run postgres backup - - -To list backups, run:: - - docker-compose -f dev.yml run postgres list-backups - - -To restore a backup, run:: - - docker-compose -f dev.yml run postgres restore filename.sql - -To copy the files from the running Postgres container to the host system:: - - docker cp :/backups /host/path/target - -Where is the ID of the Postgres container. To get it, run:: - - docker ps - Other Useful Tips ----------------- diff --git a/docs/docker-postgres-backups.rst b/docs/docker-postgres-backups.rst new file mode 100644 index 000000000..6f2a3cc5b --- /dev/null +++ b/docs/docker-postgres-backups.rst @@ -0,0 +1,40 @@ +============================ +Database 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 dev.yml`` from each example. + +Running Backups +================ + +Run the app with `docker-compose -f dev.yml up`. + +To create a backup, run:: + + docker-compose -f dev.yml run postgres backup + + +To list backups, run:: + + docker-compose -f dev.yml run postgres list-backups + + +To restore a backup, run:: + + docker-compose -f dev.yml run postgres restore filename.sql + +Where is the ID of the Postgres container. To get it, run:: + + docker ps + +To copy the files from the running Postgres container to the host system:: + + docker cp :/backups /host/path/target + +Restoring From Backups +====================== + +To restore the production database to a local PostgreSQL database:: + + createdb NAME_OF_DATABASE + psql NAME_OF_DATABASE < NAME_OF_BACKUP_FILE diff --git a/docs/index.rst b/docs/index.rst index 9c83bcdea..07cedc4ab 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -21,6 +21,7 @@ Contents: deployment-on-pythonanywhere deployment-on-heroku deployment-with-docker + docker-postgres-backups faq troubleshooting my-favorite-cookie From 30bfba71bc2e65c1ef21319eb5beef266e8f4665 Mon Sep 17 00:00:00 2001 From: "pyup.io bot" Date: Thu, 16 Jun 2016 02:57:04 +0200 Subject: [PATCH 72/73] Update flake8 to 2.6.0 (#625) * Update flake8 from 2.5.5 to 2.6.0 * Update flake8 from 2.5.5 to 2.6.0 --- requirements.txt | 2 +- {{cookiecutter.project_slug}}/requirements/test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index c44ab90e9..f0595bb1c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ cookiecutter==1.4.0 -flake8==2.5.5 +flake8==2.6.0 sh==1.11 binaryornot==0.4.0 diff --git a/{{cookiecutter.project_slug}}/requirements/test.txt b/{{cookiecutter.project_slug}}/requirements/test.txt index 215c93eaf..42b9ab967 100644 --- a/{{cookiecutter.project_slug}}/requirements/test.txt +++ b/{{cookiecutter.project_slug}}/requirements/test.txt @@ -9,7 +9,7 @@ psycopg2==2.6.1 coverage==4.1 django-coverage-plugin==1.3.1 -flake8==2.5.5 +flake8==2.6.0 django-test-plus==1.0.13 factory_boy==2.7.0 From e085b40ab5310814bc76c3a46cd9cc7fe9fb2fb0 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Thu, 16 Jun 2016 09:37:11 -0700 Subject: [PATCH 73/73] Update README.rst --- README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.rst b/README.rst index 5c6613775..8519f43de 100644 --- a/README.rst +++ b/README.rst @@ -227,6 +227,12 @@ Got a blog or online publication? Write about your cookiecutter-django tips and .. _`Introduction to Cookiecutter-Django`: http://krzysztofzuraw.com/blog/2016/django-cookiecutter.html .. _`Django and GitLab - Running Continuous Integration and tests with your FREE account`: http://dezoito.github.io/2016/05/11/django-gitlab-continuous-integration-phantomjs.html +Code of Conduct +--------------- + +Everyone interacting in the Cookiecutter project's codebases, issue trackers, chat +rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_. + Support This Project --------------------------- @@ -237,3 +243,5 @@ This project is maintained by volunteers. Support their efforts by spreading the :align: center :alt: Two Scoops Academy :target: http://www.twoscoops.academy/ + +.. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/