Repository: cookiecutter/cookiecutter-django

Issue:
Lets Encrypt
Lets Encrypt is in public beta since a couple of weeks and it would be nice if we could document a way for people to use it
- [x] on docker
- [ ] on heroku
- [ ] on ubuntu

Personally, I don't like the official client because it does too much. [simp_le](https://github.com/kuba/simp_le) looks promising.

Any thoughts? Is someone already using Lets Encrypt on a side project?



Discussion:
:+1: 

Docker support is already available; since all it does is export the paths with the certs and keys; as per the [docs](https://letsencrypt.readthedocs.org/en/latest/using.html#running-with-docker); so that part is done.

For heroku the process is a bit more involved; I am playing with this right now to see how it can be automated.

For Ubuntu (this is next on my list to try) - the process should be very similar to that of docker.  The key point being you have to manually extract the ACME key and create the end point for it - as typically you do not run the commands directly on your production servers.

I can cook up something for this.

Good idea! As a beginner I also already managed to set this up on a private project, promising technique! As a docker beginner I haven't tried it on my cookiecutter-django project yet, we should also describe how to setup some sort of auto renewal function since the certificates are only valid for (3 months?) a short period of time.

I have this setup with Docker (changes to docker-compose and nginx config) and think it would be a great addition to the project.

I could submit a PR that offers automatic letsencrypt support as long as Docker is chosen. 

@jayfk What is the opinion of the core maintainers on adding support incrementally by development/ deployment method? 

@chrisdev was working on this today at the Cookiecutter sprints at PyCon. Perhaps @chrisdev and @mjsisley could collaborate together?

> @jayfk What is the opinion of the core maintainers on adding support incrementally by development/ deployment method?

I think that's the best way :). We won't find a solution for all kinds of deployment methods over night.

I've used Caddyserver in the past that has built in letsencrypt support. If someone is working on this, take a look at:
- Caddyfile https://github.com/pydanny/djangopackages/blob/dockerize/compose/caddy/Caddyfile
- Dockerfile https://github.com/pydanny/djangopackages/blob/dockerize/compose/caddy/Dockerfile

Lets Encrypt already launched their official client [certbot](https://certbot.eff.org) with automated as well as advanced installation doc for different web-server and operating system.

For Heroku I used https://github.com/dmathieu/sabayon and it worked great.

Resolving patch:
diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py
--- a/hooks/post_gen_project.py
+++ b/hooks/post_gen_project.py
@@ -167,14 +167,6 @@ def remove_packageJSON_file():
             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"]:
-        file_name = os.path.join(nginx_dir_location, filename)
-        remove_file(file_name)
 
 def remove_copying_files():
     """
@@ -229,26 +221,26 @@ def remove_open_source_files():
 #             dst = os.path.join(target_dir, name)
 #             shutil.copyfile(src, dst)
 
-# 1. Generates and saves random secret key
+# Generates and saves random secret key
 make_secret_key(PROJECT_DIRECTORY)
 
-# 2. Removes the taskapp if celery isn't going to be used
+# Removes the taskapp if celery isn't going to be used
 if '{{ cookiecutter.use_celery }}'.lower() == 'n':
     remove_task_app(PROJECT_DIRECTORY)
 
-# 3. Removes the .idea directory if PyCharm isn't going to be used
+# Removes the .idea directory if PyCharm isn't going to be used
 if '{{ cookiecutter.use_pycharm }}'.lower() != 'y':
     remove_pycharm_dir(PROJECT_DIRECTORY)
 
-# 4. Removes all heroku files if it isn't going to be used
+# Removes all heroku files if it isn't going to be used
 if '{{ cookiecutter.use_heroku }}'.lower() != 'y':
     remove_heroku_files()
 
-# 5. Removes all docker files if it isn't going to be used
+# Removes all docker files if it isn't going to be used
 if '{{ cookiecutter.use_docker }}'.lower() != 'y':
     remove_docker_files()
 
-# 6. Removes all JS task manager files if it isn't going to be used
+# 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':
@@ -258,11 +250,7 @@ def remove_open_source_files():
     remove_grunt_files()
     remove_packageJSON_file()
 
-# 7. Removes all certbot/letsencrypt files if it isn't going to be used
-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
+# Display a warning if use_docker and use_grunt are selected. Grunt isn't
 #   supported by our docker config atm.
 if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y':
     print(
@@ -271,29 +259,15 @@ def remove_open_source_files():
         "js task runner service to your docker configuration manually."
     )
 
-# 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 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 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."
-    )
 
-# 11. Removes files needed for the GPLv3 licence if it isn't going to be used.
+# Removes files needed for the GPLv3 licence if it isn't going to be used.
 if '{{ cookiecutter.open_source_license}}' != 'GPLv3':
     remove_copying_files()
 
-# 12. Remove Elastic Beanstalk files
+# Remove Elastic Beanstalk files
 if '{{ cookiecutter.use_elasticbeanstalk_experimental }}'.lower() != 'y':
     remove_elasticbeanstalk()
 
-# 13. Remove files conventional to opensource projects only.
+# Remove files conventional to opensource projects only.
 if '{{ cookiecutter.open_source_license }}' == 'Not open source':
     remove_open_source_files()


Test patch: