diff --git a/deployment/Makefile b/deployment/Makefile index 8a5b1ce..229a693 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -53,14 +53,6 @@ geoserver: @curl --user tomcat:tomcat http://0.0.0.0:33308/manager/text/stop?path=/geoserver @curl --user tomcat:tomcat http://0.0.0.0:33308/manager/text/start?path=/geoserver -django: - @echo - @echo "------------------------------------------------------------------" - @echo "Building django container" - @echo "------------------------------------------------------------------" - @docker-compose -p $(PROJECT_ID) build django-app - @docker-compose -p $(PROJECT_ID) up -d django-app - web: @echo @echo "------------------------------------------------------------------" diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index ba0881b..7dd4a0d 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -34,30 +34,6 @@ services: restart: on-failure network_mode: "bridge" - django-app: - build: docker-django - hostname: django - environment: - - DATABASE_URL=postgres://docker:docker@postgis:5432/gis - - DATABASE_NAME=gis - - DATABASE_USERNAME=docker - - DATABASE_PASSWORD=docker - - DATABASE_HOST=postgis - - RABBITMQ_HOST=rabbitmq - - DJANGO_SETTINGS_MODULE=core.settings.prod_docker - - VIRTUAL_HOST=haitidata.com - - VIRTUAL_PORT=8080 - # Ensure to change these based on server domain - - SITEURL=http://0.0.0.0:33300/ # change this to ip or domain location - - GEOSERVER_BASE_URL=http://0.0.0.0:33308/geoserver/ # change this to ip or domain geoserver - volumes: - - ./static:/home/web/static:rw - - ./media:/home/web/media:rw - - ./reports:/home/web/reports - - ./logs:/var/log/ - user: root - network_mode: "bridge" - uwsgi-base: # Note you cannot scale if you use conteiner_name build: ./docker diff --git a/deployment/docker-django/71-apt-cacher-ng.template b/deployment/docker-django/71-apt-cacher-ng.template deleted file mode 100644 index de5127d..0000000 --- a/deployment/docker-django/71-apt-cacher-ng.template +++ /dev/null @@ -1,4 +0,0 @@ -#Acquire::http { Proxy "http://192.168.0.106:3142"; }; -#Acquire::http { Proxy "http://192.168.2.9:3142"; }; -#Acquire::http { Proxy "http://192.168.0.131:3142"; }; -#Acquire::http { Proxy "http://192.168.1.13:3142"; }; diff --git a/deployment/production/docker/Makefile b/deployment/production/docker/Makefile new file mode 100644 index 0000000..7d7bef0 --- /dev/null +++ b/deployment/production/docker/Makefile @@ -0,0 +1,12 @@ +SHELL := /bin/bash + +build-nginx: + @cd nginx && ./build.sh + +build-django: + @cd django_haitidata && ./build.sh + +build-db: + @cd db && ./build.sh + +build-all: build-db build-nginx build-django diff --git a/deployment/production/docker/db/Dockerfile b/deployment/production/docker/db/Dockerfile new file mode 100644 index 0000000..66e878e --- /dev/null +++ b/deployment/production/docker/db/Dockerfile @@ -0,0 +1,13 @@ +FROM kartoza/geonode_db +MAINTAINER Kartoza + +ENV POSTGRES_USER=docker +ENV POSTGRES_PASS=docker + +RUN mkdir -p /fresh-backups/ +COPY fresh-database.dmp /fresh-backups/fresh-database.dmp +#RUN su - postgres -c "dropdb --if-exists gis" +#RUN su - postgres -c "dropdb --if-exists geonode_data" +#RUN su - postgres -c "createdb -O docker -T template_postgis gis" +#RUN su - postgres -c "createdb -O docker -T template_postgis geonode_data" +#RUN pg_restore /fresh-backups/fresh-database.dmp | su - postgres -c "psql gis" diff --git a/deployment/production/docker/db/build.sh b/deployment/production/docker/db/build.sh new file mode 100755 index 0000000..4cbd92e --- /dev/null +++ b/deployment/production/docker/db/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +IMAGE_NAME=haitidata_db +TAG_NAME=latest +docker build -t dimasciput/${IMAGE_NAME} . +docker tag dimasciput/${IMAGE_NAME}:latest dimasciput/${IMAGE_NAME}:${TAG_NAME} +docker push dimasciput/${IMAGE_NAME}:${TAG_NAME} \ No newline at end of file diff --git a/deployment/production/docker/db/fresh-database.dmp b/deployment/production/docker/db/fresh-database.dmp new file mode 100644 index 0000000..fd58289 Binary files /dev/null and b/deployment/production/docker/db/fresh-database.dmp differ diff --git a/deployment/docker-django/Dockerfile b/deployment/production/docker/django_haitidata/Dockerfile similarity index 100% rename from deployment/docker-django/Dockerfile rename to deployment/production/docker/django_haitidata/Dockerfile diff --git a/deployment/docker-django/REQUIREMENTS.txt b/deployment/production/docker/django_haitidata/REQUIREMENTS.txt similarity index 100% rename from deployment/docker-django/REQUIREMENTS.txt rename to deployment/production/docker/django_haitidata/REQUIREMENTS.txt diff --git a/deployment/production/docker/django_haitidata/build.sh b/deployment/production/docker/django_haitidata/build.sh new file mode 100755 index 0000000..e5b6428 --- /dev/null +++ b/deployment/production/docker/django_haitidata/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +IMAGE_NAME=haitidata_django +TAG_NAME=latest +docker build -t dimasciput/${IMAGE_NAME} . +docker tag dimasciput/${IMAGE_NAME}:latest dimasciput/${IMAGE_NAME}:${TAG_NAME} +docker push dimasciput/${IMAGE_NAME}:${TAG_NAME} \ No newline at end of file diff --git a/deployment/docker-django/uwsgi.conf b/deployment/production/docker/django_haitidata/uwsgi.conf similarity index 100% rename from deployment/docker-django/uwsgi.conf rename to deployment/production/docker/django_haitidata/uwsgi.conf diff --git a/deployment/production/docker/docker-compose.yml b/deployment/production/docker/docker-compose.yml new file mode 100644 index 0000000..b6f90e8 --- /dev/null +++ b/deployment/production/docker/docker-compose.yml @@ -0,0 +1,52 @@ +version: '2' +services: + geoserver: + image: dimasciput/haitidata_geoserver:2.10.x + stdin_open: true + external_links: + - postgis:postgis + tty: true + ports: + - 32208:8080/tcp + labels: + io.rancher.container.pull_image: always + django: + image: dimasciput/haitidata_django + environment: + DATABASE_HOST: postgis + DATABASE_NAME: gis + DJANGO_SETTINGS_MODULE: core.settings.prod_docker + GEOSERVER_PUBLIC_LOCATION: http://88.99.166.60/api/geoserver/ + LC_ALL: en_US.UTF-8 + RABBITMQ_HOST: rabbitmq + GEOSERVER_BASE_URL: http://88.99.166.60:32208/geoserver/ + SITEURL: http://88.99.166.60/ + stdin_open: true + volumes: + - django-static-data:/home/web/static:rw + - django-media-data:/home/web/media:rw + tty: true + links: + - postgis:postgis + - geoserver:geoserver + labels: + io.rancher.container.pull_image: always + nginx: + image: dimasciput/haitidata_nginx + stdin_open: true + volumes: + - django-static-data:/home/web/static:ro + - django-media-data:/home/web/media:ro + tty: true + links: + - django:django + - geoserver:geoserver + ports: + - 33303:8080/tcp + labels: + io.rancher.container.pull_image: always + postgis: + image: dimasciput/haitidata_db + environment: + POSTGRES_USER: docker + POSTGRES_PASS: docker diff --git a/deployment/production/docker/nginx/Dockerfile b/deployment/production/docker/nginx/Dockerfile new file mode 100644 index 0000000..358ac0b --- /dev/null +++ b/deployment/production/docker/nginx/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx + +ADD sites-enabled/default.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/deployment/production/docker/nginx/build.sh b/deployment/production/docker/nginx/build.sh new file mode 100755 index 0000000..b93cae4 --- /dev/null +++ b/deployment/production/docker/nginx/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +IMAGE_NAME=haitidata_nginx +TAG_NAME=latest +docker build -t dimasciput/${IMAGE_NAME} . +docker tag dimasciput/${IMAGE_NAME}:latest dimasciput/${IMAGE_NAME}:${TAG_NAME} +docker push dimasciput/${IMAGE_NAME}:${TAG_NAME} \ No newline at end of file diff --git a/deployment/production/docker/nginx/sites-enabled/default.conf b/deployment/production/docker/nginx/sites-enabled/default.conf new file mode 100644 index 0000000..7df1928 --- /dev/null +++ b/deployment/production/docker/nginx/sites-enabled/default.conf @@ -0,0 +1,69 @@ +# Define connection details for connecting to django running in +# a docker container. +upstream uwsgi { + server uwsgi:8080; +} + +upstream geoserver { + server geoserver:8080; +} + +server { + # OTF gzip compression + gzip on; + gzip_min_length 860; + gzip_comp_level 5; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain application/xml application/x-javascript text/xml text/css application/json; + gzip_disable “MSIE [1-6].(?!.*SV1)”; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + # the port your site will be served on + listen 8080; + # the domain name it will serve for + # server_name staging.foss4g-africa.org; + charset utf-8; + + # max upload size, adjust to taste + client_max_body_size 500M; + # Django media + location /media { + # your Django project's media files - amend as required + alias /home/web/media; + expires 21d; # cache for 71 days + } + location /static { + # your Django project's static files - amend as required + alias /home/web/static; + expires 21d; # cache for 21 days + } + + location /api/geoserver/ { + proxy_pass http://geoserver/geoserver/; + } + # Finally, send all non-media requests to the Django server. + location / { + uwsgi_pass uwsgi; + # the uwsgi_params file you installed needs to be passed with each + # request. + # the uwsgi_params need to be passed with each uwsgi request + uwsgi_param QUERY_STRING $query_string; + uwsgi_param REQUEST_METHOD $request_method; + uwsgi_param CONTENT_TYPE $content_type; + uwsgi_param CONTENT_LENGTH $content_length; + + uwsgi_param REQUEST_URI $request_uri; + uwsgi_param PATH_INFO $document_uri; + uwsgi_param DOCUMENT_ROOT $document_root; + uwsgi_param SERVER_PROTOCOL $server_protocol; + uwsgi_param HTTPS $https if_not_empty; + + uwsgi_param REMOTE_ADDR $remote_addr; + uwsgi_param REMOTE_PORT $remote_port; + uwsgi_param SERVER_PORT $server_port; + uwsgi_param SERVER_NAME $server_name; + } + +}