From 0b1f464c7492c584543b849776625b2e20c2cd1c Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Thu, 24 Jan 2019 09:20:41 -0500 Subject: [PATCH] Ensure that server is started correctly in Docker Also: ignore files generated during application run which enables a better development experience in Docker with source mounts like `docker run -p 8080:80 -v $PWD:/doccano -it doccano`. --- .dockerignore | 2 ++ .gitignore | 5 ++++- Dockerfile | 6 +++++- tools/run.sh | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 tools/run.sh diff --git a/.dockerignore b/.dockerignore index 71ce7133..b693ba1b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ * !app/ +app/staticfiles/ +app/db.sqlite3 !data/ !tests/ !tools/ diff --git a/.gitignore b/.gitignore index 7cc1ae8b..1ca8a1c4 100644 --- a/.gitignore +++ b/.gitignore @@ -195,4 +195,7 @@ pip-selfcheck.json /data/sparql/* # ignore db to avoid merge conflicts -*.sqlite3 \ No newline at end of file +*.sqlite3 + +# ignore django generated static files +app/staticfiles/ diff --git a/Dockerfile b/Dockerfile index 15dfa061..313abd72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,5 +11,9 @@ WORKDIR /doccano ENV DEBUG="True" ENV SECRET_KEY="change-me-in-production" +ENV BIND="0.0.0.0:80" +ENV WORKERS="2" -CMD ["gunicorn", "--bind=0.0.0.0:80", "--workers=2", "--pythonpath=app", "app.wsgi"] +EXPOSE 80 + +CMD ["/doccano/tools/run.sh"] diff --git a/tools/run.sh b/tools/run.sh new file mode 100755 index 00000000..8c85df7c --- /dev/null +++ b/tools/run.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -o errexit + +if [[ ! -d "app/staticfiles" ]]; then python app/manage.py collectstatic --noinput; fi + +python app/manage.py migrate +gunicorn --bind="${BIND:-127.0.0.1:8000}" --workers="${WORKERS:-1}" --pythonpath=app app.wsgi