From aca042e405f8f5e71a96b773e8be59b373077df6 Mon Sep 17 00:00:00 2001 From: afabiani Date: Mon, 3 Jun 2019 13:25:46 +0200 Subject: [PATCH] - Improve docker build --- docker-compose.async.yaml | 144 +++++++++++++++++++++++ docker-compose.yml | 48 -------- entrypoint.sh | 28 ++--- scripts/docker/env/production/django.env | 2 +- uwsgi.ini | 19 ++- 5 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 docker-compose.async.yaml diff --git a/docker-compose.async.yaml b/docker-compose.async.yaml new file mode 100644 index 00000000000..cb2fb9f5261 --- /dev/null +++ b/docker-compose.async.yaml @@ -0,0 +1,144 @@ +version: '2.2' +services: + + db: + image: geonode/postgis:10 + restart: unless-stopped + container_name: db4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: db + org.geonode.instance.name: geonode + volumes: + - dbdata:/var/lib/postgresql/data + - dbbackups:/pg_backups + env_file: + - ./scripts/docker/env/production/db.env + + elasticsearch: + image: elasticsearch:2.4.1 + restart: unless-stopped + container_name: elasticsearch4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: elasticsearch + org.geonode.instance.name: geonode + + rabbitmq: + image: rabbitmq + restart: unless-stopped + container_name: rabbitmq4${COMPOSE_PROJECT_NAME} + stdin_open: true + tty: true + labels: + org.geonode.component: rabbitmq + org.geonode.instance.name: geonode + volumes: + - rabbitmq:/var/lib/rabbitmq + + celery: + restart: unless-stopped + image: geonode/geonode:latest + container_name: celery4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: celery + org.geonode.instance.name: geonode + depends_on: + - db + - elasticsearch + - rabbitmq + # command: celery worker --app=geonode.celery_app:app -B -l INFO + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - statics:/mnt/volumes/statics + - geoserver-data-dir:/geoserver_data/data + env_file: + - ./scripts/docker/env/production/celery.env + + geoserver: + image: geonode/geoserver:2.14.x + restart: unless-stopped + container_name: geoserver4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: geoserver + org.geonode.instance.name: geonode + depends_on: + - db + - elasticsearch + - rabbitmq + - data-dir-conf + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - geoserver-data-dir:/geoserver_data/data + env_file: + - ./scripts/docker/env/production/geoserver.env + + django: + restart: unless-stopped + image: geonode/geonode:latest + container_name: django4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: django + org.geonode.instance.name: geonode + depends_on: + - db + - elasticsearch + - rabbitmq + - data-dir-conf + # command: paver start_django -b 0.0.0.0:8000 + # command: uwsgi --ini uwsgi.ini + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - statics:/mnt/volumes/statics + - geoserver-data-dir:/geoserver_data/data + env_file: + - ./scripts/docker/env/production/django.env + + geonode: + image: geonode/nginx:geoserver + restart: unless-stopped + container_name: nginx4${COMPOSE_PROJECT_NAME} + stdin_open: true + # tty: true + labels: + org.geonode.component: nginx + org.geonode.instance.name: geonode + depends_on: + - django + - celery + - geoserver + ports: + - "80:80" + volumes: + - statics:/mnt/volumes/statics + + data-dir-conf: + image: geonode/geoserver_data:2.14.x + restart: on-failure + container_name: gsconf4${COMPOSE_PROJECT_NAME} + labels: + org.geonode.component: conf + org.geonode.instance.name: geonode + command: /bin/true + volumes: + - geoserver-data-dir:/geoserver_data/data + +volumes: + statics: + name: ${COMPOSE_PROJECT_NAME}-statics + geoserver-data-dir: + name: ${COMPOSE_PROJECT_NAME}-gsdatadir + dbdata: + name: ${COMPOSE_PROJECT_NAME}-dbdata + dbbackups: + name: ${COMPOSE_PROJECT_NAME}-dbbackups + rabbitmq: + name: ${COMPOSE_PROJECT_NAME}-rabbitmq diff --git a/docker-compose.yml b/docker-compose.yml index cb2fb9f5261..5a5a745c181 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,49 +16,6 @@ services: env_file: - ./scripts/docker/env/production/db.env - elasticsearch: - image: elasticsearch:2.4.1 - restart: unless-stopped - container_name: elasticsearch4${COMPOSE_PROJECT_NAME} - stdin_open: true - # tty: true - labels: - org.geonode.component: elasticsearch - org.geonode.instance.name: geonode - - rabbitmq: - image: rabbitmq - restart: unless-stopped - container_name: rabbitmq4${COMPOSE_PROJECT_NAME} - stdin_open: true - tty: true - labels: - org.geonode.component: rabbitmq - org.geonode.instance.name: geonode - volumes: - - rabbitmq:/var/lib/rabbitmq - - celery: - restart: unless-stopped - image: geonode/geonode:latest - container_name: celery4${COMPOSE_PROJECT_NAME} - stdin_open: true - # tty: true - labels: - org.geonode.component: celery - org.geonode.instance.name: geonode - depends_on: - - db - - elasticsearch - - rabbitmq - # command: celery worker --app=geonode.celery_app:app -B -l INFO - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - statics:/mnt/volumes/statics - - geoserver-data-dir:/geoserver_data/data - env_file: - - ./scripts/docker/env/production/celery.env - geoserver: image: geonode/geoserver:2.14.x restart: unless-stopped @@ -70,8 +27,6 @@ services: org.geonode.instance.name: geonode depends_on: - db - - elasticsearch - - rabbitmq - data-dir-conf volumes: - /var/run/docker.sock:/var/run/docker.sock @@ -90,8 +45,6 @@ services: org.geonode.instance.name: geonode depends_on: - db - - elasticsearch - - rabbitmq - data-dir-conf # command: paver start_django -b 0.0.0.0:8000 # command: uwsgi --ini uwsgi.ini @@ -113,7 +66,6 @@ services: org.geonode.instance.name: geonode depends_on: - django - - celery - geoserver ports: - "80:80" diff --git a/entrypoint.sh b/entrypoint.sh index 83555a76217..442fddec102 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,25 +14,10 @@ echo GEOSERVER_PUBLIC_LOCATION=$GEOSERVER_PUBLIC_LOCATION echo GEOSERVER_WEB_UI_LOCATION=$GEOSERVER_WEB_UI_LOCATION /usr/local/bin/invoke waitfordbs >> /usr/src/app/invoke.log - echo "waitfordbs task done" - /usr/local/bin/invoke migrations >> /usr/src/app/invoke.log echo "migrations task done" -if [ ! -e "/mnt/volumes/statics/geonode_init.lock" ]; then - /usr/local/bin/invoke prepare - echo "prepare task done" - /usr/local/bin/invoke fixtures - echo "fixture task done" -fi -/usr/local/bin/invoke initialized -echo "initialized" - -echo "refresh static data" -/usr/local/bin/invoke statics -echo "static data refreshed" - cmd="$@" echo DOCKER_ENV=$DOCKER_ENV @@ -52,6 +37,19 @@ else else + if [ ! -e "/mnt/volumes/statics/geonode_init.lock" ]; then + /usr/local/bin/invoke prepare + echo "prepare task done" + /usr/local/bin/invoke fixtures + echo "fixture task done" + fi + /usr/local/bin/invoke initialized + echo "initialized" + + echo "refresh static data" + /usr/local/bin/invoke statics + echo "static data refreshed" + cmd=$UWSGI_CMD echo "Executing UWSGI server $cmd for Production" diff --git a/scripts/docker/env/production/django.env b/scripts/docker/env/production/django.env index b0037ebd465..dd5e5bf44db 100644 --- a/scripts/docker/env/production/django.env +++ b/scripts/docker/env/production/django.env @@ -7,7 +7,7 @@ GEONODE_DATABASE=geonode GEONODE_DATABASE_PASSWORD=geonode GEONODE_GEODATABASE=geonode_data GEONODE_GEODATABASE_PASSWORD=geonode_data -ASYNC_SIGNALS=True +ASYNC_SIGNALS=False BROKER_URL=amqp://guest:guest@rabbitmq:5672 DOCKER_ENV=production UWSGI_CMD=uwsgi --ini /usr/src/app/uwsgi.ini diff --git a/uwsgi.ini b/uwsgi.ini index 58d57275884..7f7e33e0228 100644 --- a/uwsgi.ini +++ b/uwsgi.ini @@ -1,12 +1,23 @@ [uwsgi] uwsgi-socket = 0.0.0.0:8000 # http-socket = 0.0.0.0:8000 -chdir = /usr/src/app/ logto = /var/log/geonode.log pidfile = /tmp/geonode.pid -harakiri = 25 + +chdir = /usr/src/app/ module = geonode.wsgi:application -master = 1 + processes = 4 threads = 2 -buffer-size = 8192 +enable-threads = true +master = true + +buffer-size = 32768 +max-requests = 500 +harakiri = 300 # respawn processes taking more than 5 minutes (300 seconds) +max-requests = 500 # respawn processes after serving 5000 requests +# limit-as = 1024 # avoid Errno 12 cannot allocate memory +harakiri-verbose = true +# cron = -1 -1 -1 -1 -1 /usr/local/bin/python /usr/src/{{project_name}}/manage.py collect_metrics -n +vacuum = true +thunder-lock = true