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

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

23
Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM python:slim
RUN useradd microblog
WORKDIR /home/microblog
COPY requirements.txt requirements.txt
RUN python -m venv venv
RUN venv/bin/pip install -r requirements.txt
RUN venv/bin/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 chown -R microblog:microblog ./
USER microblog
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]

13
boot.sh Executable file
View File

@ -0,0 +1,13 @@
#!/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
flask translate compile
exec gunicorn -b :5000 --access-logfile - --error-logfile - microblog:app

View File

@ -38,5 +38,5 @@ Werkzeug==2.0.1
WTForms==2.3.3
# requirements for Heroku
psycopg2==2.9.1
gunicorn==20.1.0
#psycopg2==2.9.1
#gunicorn==20.1.0