From 2c7145939848f2425fa8d4f674cc4374e677b362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobiasz=20K=C4=99dzierski?= Date: Sun, 6 Oct 2019 09:27:17 +0200 Subject: [PATCH] fixup! Add heroku deployment feature --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 4 ++++ {{cookiecutter.app_name}}/Pipfile | 4 ++-- {{cookiecutter.app_name}}/README.rst | 12 +++++++----- {{cookiecutter.app_name}}/app.json | 2 +- {{cookiecutter.app_name}}/requirements/prod.txt | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 03cd028..075e5e5 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -8,5 +8,5 @@ "use_pipenv": ["no", "yes"], "python_version": ["3.7", "3.6"], "node_version": ["12", "10", "8"], - "deployment_on_heroku": ["no", "yes"] + "use_heroku": ["no", "yes"] } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 1bd084e..08be14f 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -10,6 +10,7 @@ import sys def clean_extra_package_management_files(): """Removes either requirements files and folder or the Pipfile.""" use_pipenv = "{{cookiecutter.use_pipenv}}" + use_heroku = "{{cookiecutter.use_heroku}}" to_delete = [] if use_pipenv == "yes": @@ -17,6 +18,9 @@ def clean_extra_package_management_files(): else: to_delete.append("Pipfile") + if use_heroku == "no": + to_delete = to_delete + ["Procfile", "app.json"] + try: for file_or_dir in to_delete: if os.path.isfile(file_or_dir): diff --git a/{{cookiecutter.app_name}}/Pipfile b/{{cookiecutter.app_name}}/Pipfile index 033e214..f276acb 100644 --- a/{{cookiecutter.app_name}}/Pipfile +++ b/{{cookiecutter.app_name}}/Pipfile @@ -12,8 +12,8 @@ click = ">=5.0" # Database Flask-SQLAlchemy = "==2.4.1" SQLAlchemy = "==1.3.9" -{%- if cookiecutter.deployment_on_heroku == "yes" %} -psycopg2 = "==2.8.3" +{%- if cookiecutter.use_heroku == "yes" %} +psycopg2-binary = "==2.8.3" {%- endif %} # Migrations diff --git a/{{cookiecutter.app_name}}/README.rst b/{{cookiecutter.app_name}}/README.rst index 08a6514..9002070 100644 --- a/{{cookiecutter.app_name}}/README.rst +++ b/{{cookiecutter.app_name}}/README.rst @@ -136,8 +136,8 @@ in your ``settings.py``:: SEND_FILE_MAX_AGE_DEFAULT = 31556926 # one year +{%- if cookiecutter.use_heroku == "yes" %} -{%- if cookiecutter.deployment_on_heroku == "yes" %} Deployment on Heroku -------------------- @@ -174,13 +174,15 @@ If you want deploy by using Heroku CLI: heroku buildpacks:add --index=1 heroku/nodejs heroku buildpacks:add --index=1 heroku/python -* add Postgres database addon (it also sets `DATABASE_URL` environmental variable to created database):: +* add database addon which sets Postgres in version 11 in free `hobby-dev` plan (https://elements.heroku.com/addons/heroku-postgresql#hobby-dev) (it also sets `DATABASE_URL` environmental variable to created database):: - heroku addons:create heroku-postgresql:hobby-dev + heroku addons:create heroku-postgresql:hobby-dev --version=11 -* set environmental variables (change secret key):: +* set environmental variables: change secret key. + `DATABASE_URL` environmental variable is set by database addon in previous step. + Please check `.env.example` to get overview which environmental variables are used in project.:: - heroku config:set SECRET_KEY= + heroku config:set SECRET_KEY=not-so-secret heroku config:set FLASK_APP=autoapp.py * deploy on Heroku:: diff --git a/{{cookiecutter.app_name}}/app.json b/{{cookiecutter.app_name}}/app.json index b13ea76..71081d8 100644 --- a/{{cookiecutter.app_name}}/app.json +++ b/{{cookiecutter.app_name}}/app.json @@ -21,7 +21,7 @@ ], "addons": [ { - "plan": "heroku-postgresql", + "plan": "heroku-postgresql:hobby-dev", "options": { "version": "11" } diff --git a/{{cookiecutter.app_name}}/requirements/prod.txt b/{{cookiecutter.app_name}}/requirements/prod.txt index 4d6b143..ba2b665 100644 --- a/{{cookiecutter.app_name}}/requirements/prod.txt +++ b/{{cookiecutter.app_name}}/requirements/prod.txt @@ -8,8 +8,8 @@ click>=7.0 # Database Flask-SQLAlchemy==2.4.1 SQLAlchemy==1.3.9 -{%- if cookiecutter.deployment_on_heroku == "yes" %} -psycopg2==2.8.3 +{%- if cookiecutter.use_heroku == "yes" %} +psycopg2-binary==2.8.3 {%- endif %} # Migrations