Add heroku deployment feature

master
Tobiasz Kędzierski 5 years ago committed by James Curtin
parent baf7140c76
commit 6264b22311
  1. 3
      cookiecutter.json
  2. 3
      {{cookiecutter.app_name}}/Pipfile
  3. 1
      {{cookiecutter.app_name}}/Procfile
  4. 53
      {{cookiecutter.app_name}}/README.rst
  5. 30
      {{cookiecutter.app_name}}/app.json
  6. 3
      {{cookiecutter.app_name}}/package.json
  7. 3
      {{cookiecutter.app_name}}/requirements/prod.txt

@ -7,5 +7,6 @@
"project_short_description": "A flasky app.", "project_short_description": "A flasky app.",
"use_pipenv": ["no", "yes"], "use_pipenv": ["no", "yes"],
"python_version": ["3.7", "3.6"], "python_version": ["3.7", "3.6"],
"node_version": ["12", "10", "8"] "node_version": ["12", "10", "8"],
"deployment_on_heroku": ["no", "yes"]
} }

@ -12,6 +12,9 @@ click = ">=5.0"
# Database # Database
Flask-SQLAlchemy = "==2.4.1" Flask-SQLAlchemy = "==2.4.1"
SQLAlchemy = "==1.3.9" SQLAlchemy = "==1.3.9"
{%- if cookiecutter.deployment_on_heroku == "yes" %}
psycopg2 = "==2.8.3"
{%- endif %}
# Migrations # Migrations
Flask-Migrate = "==2.5.2" Flask-Migrate = "==2.5.2"

@ -1 +1,2 @@
release: flask db upgrade
web: gunicorn {{cookiecutter.app_name}}.app:create_app\(\) -b 0.0.0.0:$PORT -w 3 web: gunicorn {{cookiecutter.app_name}}.app:create_app\(\) -b 0.0.0.0:$PORT -w 3

@ -135,3 +135,56 @@ should cache all your assets forever by including the following line
in your ``settings.py``:: in your ``settings.py``::
SEND_FILE_MAX_AGE_DEFAULT = 31556926 # one year SEND_FILE_MAX_AGE_DEFAULT = 31556926 # one year
{%- if cookiecutter.deployment_on_heroku == "yes" %}
Deployment on Heroku
--------------------
Before using automatic deployment on Heroku you have to add migrations to your repository.
You can do it by using following commands ::
flask db init
flask db migrate
git add migrations/
git commit -m "Add migrations"
git commit push
Make sure folder `migrations/versions` is not empty.
Deploy to Heroku button
^^^^^^^^^^^^^^^^^^^^^^^
.. raw:: html
<a href="https://heroku.com/deploy"><img src="https://www.herokucdn.com/deploy/button.svg" title="Deploy" alt="Deploy"></a>
Heroku CLI
^^^^^^^^^^
If you want deploy by using Heroku CLI:
* create Heroku App. You can leave your app name, change it or leave it blank (random name will be generated)::
heroku create {{cookiecutter.app_name}}
* add buildpacks::
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)::
heroku addons:create heroku-postgresql:hobby-dev
* set environmental variables (change secret key)::
heroku config:set SECRET_KEY=<secret-key>
heroku config:set FLASK_APP=autoapp.py
* deploy on Heroku::
git push heroku master
{%- endif %}

@ -0,0 +1,30 @@
{
"name": "{{cookiecutter.app_name}}",
"repository": "https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.app_name}}",
"env": {
"SECRET_KEY": {
"description": "SECRET_KEY.",
"generator": "secret"
},
"FLASK_APP": {
"description": "FLASK_APP.",
"value": "autoapp.py"
}
},
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "heroku/python"
}
],
"addons": [
{
"plan": "heroku-postgresql",
"options": {
"version": "11"
}
}
]
}

@ -7,7 +7,8 @@
"start": "concurrently -n \"WEBPACK,FLASK\" -c \"bgBlue.bold,bgMagenta.bold\" \"npm run webpack-dev-server\" \"npm run flask-server\"", "start": "concurrently -n \"WEBPACK,FLASK\" -c \"bgBlue.bold,bgMagenta.bold\" \"npm run webpack-dev-server\" \"npm run flask-server\"",
"webpack-dev-server": "NODE_ENV=debug webpack-dev-server --host=0.0.0.0 --port 2992 --hot --inline", "webpack-dev-server": "NODE_ENV=debug webpack-dev-server --host=0.0.0.0 --port 2992 --hot --inline",
"flask-server": "{% if cookiecutter.use_pipenv == 'yes' %}pipenv run {% endif %}flask run --host=0.0.0.0", "flask-server": "{% if cookiecutter.use_pipenv == 'yes' %}pipenv run {% endif %}flask run --host=0.0.0.0",
"lint": "eslint \"assets/js/*.js\"" "lint": "eslint \"assets/js/*.js\"",
"postinstall": "npm run build"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

@ -8,6 +8,9 @@ click>=7.0
# Database # Database
Flask-SQLAlchemy==2.4.1 Flask-SQLAlchemy==2.4.1
SQLAlchemy==1.3.9 SQLAlchemy==1.3.9
{%- if cookiecutter.deployment_on_heroku == "yes" %}
psycopg2==2.8.3
{%- endif %}
# Migrations # Migrations
Flask-Migrate==2.5.2 Flask-Migrate==2.5.2

Loading…
Cancel
Save