From 53f4d49cb901912140e81b8e0c8e9055633feab1 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 1 Nov 2017 13:03:19 -0700 Subject: [PATCH] Chapter 19: Deployment on Docker Containers (v0.19) --- Dockerfile | 16 ++++++++++++++++ boot.sh | 12 ++++++++++++ requirements.txt | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100755 boot.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..972b18b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:slim + +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt +RUN pip install gunicorn pymysql cryptography + +COPY app app +COPY migrations migrations +COPY microblog.py config.py boot.sh ./ +RUN chmod a+x boot.sh + +ENV FLASK_APP microblog.py +RUN flask translate compile + +EXPOSE 5000 +ENTRYPOINT ["./boot.sh"] diff --git a/boot.sh b/boot.sh new file mode 100755 index 0000000..30dd9e6 --- /dev/null +++ b/boot.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# this script is used to boot a Docker container +source venv/bin/activate +while true; do + flask db upgrade + if [[ "$?" == "0" ]]; then + break + fi + echo Deploy command failed, retrying in 5 secs... + sleep 5 +done +exec gunicorn -b :5000 --access-logfile - --error-logfile - microblog:app diff --git a/requirements.txt b/requirements.txt index 83797f9..a2fcc38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,5 +39,5 @@ Werkzeug==2.3.3 WTForms==3.0.1 # requirements for Heroku -psycopg2-binary==2.9.6 -gunicorn==20.1.0 +#psycopg2-binary==2.9.6 +#gunicorn==20.1.0