Browse Source

Add docker-compose for production environment

pull/341/head
Hironsan 5 years ago
parent
commit
95c01b2a1f
7 changed files with 149 additions and 0 deletions
  1. 10
      app/.dockerignore
  2. 20
      app/Dockerfile
  3. 40
      app/requirements.txt
  4. 20
      app/tools/run.sh
  5. 42
      docker-compose.prod.yml
  6. 4
      nginx/Dockerfile
  7. 13
      nginx/nginx.conf

10
app/.dockerignore

@ -0,0 +1,10 @@
**/bundle/
**/node_modules/
**/webpack-stats.json
**/*.sqlite3
**/.env
**/junitxml/
**/staticfiles/
**/venv/
**/__pycache__/

20
app/Dockerfile

@ -0,0 +1,20 @@
FROM python:3.6
# set work directory
WORKDIR /app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apt-get update \
&& apt-get install --no-install-recommends -y python3-dev libpq-dev unixodbc-dev
# install dependencies
RUN pip install --upgrade pip setuptools
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# copy project
COPY . /app/

40
app/requirements.txt

@ -0,0 +1,40 @@
apache-libcloud==2.4.0
applicationinsights==0.11.7
coverage==4.5.3
dj-database-url==0.5.0
Django==2.1.7
django-cloud-browser==0.5.0
django-filter==2.0.0
django-heroku==0.3.1
django-webpack-loader==0.6.0
django-widget-tweaks==1.4.2
django-polymorphic==2.0.3
django-pyodbc-azure==2.1.0.0
django-rest-polymorphic==0.1.8
djangorestframework==3.8.2
djangorestframework-csv==2.1.0
djangorestframework-filters==0.10.2
environs==4.1.0
djangorestframework-xml==1.4.0
Faker==0.9.1
flake8==3.6.0
furl==2.0.0
gunicorn==19.9.0
lockfile==0.12.2
mixer==6.1.3
model-mommy==1.6.0
psycopg2-binary==2.7.7
python-dateutil==2.7.3
pytz==2018.4
requests==2.21.0
six==1.11.0
seqeval==0.0.6
social-auth-app-django==3.1.0
social-auth-core[azuread]==3.0.0
text-unidecode==1.2
tornado==5.0.2
unittest-xml-reporting==2.5.1
vcrpy==2.0.1
vcrpy-unittest==0.1.7
whitenoise[brotli]==4.1.2
conllu==1.3.2

20
app/tools/run.sh

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -o errexit
echo "Initializing database"
python manage.py wait_for_db
python manage.py migrate
# python manage.py create_roles
if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMIN_EMAIL}" ]]; then
python manage.py create_admin \
--username "${ADMIN_USERNAME}" \
--password "${ADMIN_PASSWORD}" \
--email "${ADMIN_EMAIL}" \
--noinput \
|| true
fi
echo "Starting django"
gunicorn --bind 0.0.0.0:8000 app.wsgi --timeout 300

42
docker-compose.prod.yml

@ -0,0 +1,42 @@
version: "3"
services:
backend:
build: ./app
command: ["/app/tools/run.sh", "0.0.0.0:8000"]
volumes:
- ./app/:/app/
environment:
ADMIN_USERNAME: "admin"
ADMIN_PASSWORD: "password"
ADMIN_EMAIL: "admin@example.com"
DATABASE_URL: "postgres://doccano:doccano@postgres:5432/doccano?sslmode=disable"
ALLOW_SIGNUP: "False"
ports:
- 8000:8000
depends_on:
- postgres
nginx:
build: ./nginx
volumes:
- static_volume:/home/app/web/staticfiles
ports:
- 1337:80
depends_on:
- backend
postgres:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_USER: "doccano"
POSTGRES_PASSWORD: "doccano"
POSTGRES_DB: "doccano"
ports:
- 5432:5432
volumes:
postgres_data:
static_volume:

4
nginx/Dockerfile

@ -0,0 +1,4 @@
FROM nginx:1.17.4-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

13
nginx/nginx.conf

@ -0,0 +1,13 @@
server {
listen 80;
charset utf-8;
location /v1/ {
proxy_pass http://backend:8000/v1/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
server_tokens off;
Loading…
Cancel
Save