Last active
July 6, 2022 15:23
-
-
Save duhaime/44783327ed102fa33bac597a16d5ad10 to your computer and use it in GitHub Desktop.
Minimal Heroku / Flask App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.pyc | |
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return 'Woohoo' | |
if __name__ == '__main__': | |
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.6 | |
ADD . /app | |
WORKDIR /app | |
RUN pip install flask gunicorn | |
CMD gunicorn --bind 0.0.0.0:$PORT app:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: gunicorn app:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==1.0.1 | |
gunicorn==19.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python-3.6.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment