Chapter 19: Deployment on Docker Containers (v0.19)

This commit is contained in:
Miguel Grinberg 2017-11-01 13:03:19 -07:00
parent ae62fc9251
commit 53f4d49cb9
No known key found for this signature in database
GPG Key ID: 36848B262DF5F06C
3 changed files with 30 additions and 2 deletions

16
Dockerfile Normal file
View File

@ -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"]

12
boot.sh Executable file
View File

@ -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

View File

@ -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