Skip to content

Instantly share code, notes, and snippets.

@duhaime
Last active July 6, 2022 15:23
Show Gist options
  • Save duhaime/44783327ed102fa33bac597a16d5ad10 to your computer and use it in GitHub Desktop.
Save duhaime/44783327ed102fa33bac597a16d5ad10 to your computer and use it in GitHub Desktop.
Minimal Heroku / Flask App
*.pyc
__pycache__
## OG Deployment
```
# test the server locally
pip install -r requirements.txt
gunicorn app:app
# login to heroku
heroku login
# create an app
heroku create myapp-name-1
# set a git alias for heroku
git remote add heroku https://git.heroku.com/myapp-name-1.git
# commit everything
git add .
git commit -m 'initial commit'
# deploy
git push heroku master
# view the app
heroku open
```
## Docker Deployment
```
# log in to heroku cli
heroku login
heroku container:login
# create the app
heroku create myapp-name-2
# create the container with format:
# docker build -t registry.heroku.com/<app name>/<process type> .
docker build -t registry.heroku.com/myapp-name-2/web .
# push the image to the registry
docker push registry.heroku.com/myapp-name-2/web
# "release" the image
heroku container:release --app myapp-name-2 web
# open the app
heroku open --app myapp-name-2
```
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return 'Woohoo'
if __name__ == '__main__':
app.run(debug=True)
FROM python:3.6
ADD . /app
WORKDIR /app
RUN pip install flask gunicorn
CMD gunicorn --bind 0.0.0.0:$PORT app:app
web: gunicorn app:app
Flask==1.0.1
gunicorn==19.7.1
python-3.6.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment