diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6604175 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/boot.sh b/boot.sh new file mode 100755 index 0000000..28add13 --- /dev/null +++ b/boot.sh @@ -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 diff --git a/requirements.txt b/requirements.txt index 07f5bdb..d1233ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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