forked from miguelgrinberg/microblog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 19: Deployment on Docker Containers (v0.19)
- Loading branch information
1 parent
1e44f0b
commit 0b94a5b
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM python:3.6-alpine | ||
|
||
RUN adduser -D 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 | ||
|
||
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"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
# 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 |
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