From ddd71330a3d5902295429ab1f8096773089d874a Mon Sep 17 00:00:00 2001 From: stephenrjones Date: Tue, 24 Oct 2017 14:47:36 -0400 Subject: [PATCH 1/8] nginx config for container --- django_nginx.conf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 django_nginx.conf diff --git a/django_nginx.conf b/django_nginx.conf new file mode 100644 index 00000000..90569c53 --- /dev/null +++ b/django_nginx.conf @@ -0,0 +1,14 @@ +server { + listen 80; + server_name ~^(.+)$; + + location = /favicon.ico { access_log off; log_not_found off; } + location /static/ { + root /var/www; + } + + location / { + include proxy_params; + proxy_pass http://unix:/usr/src/geoq/django_app.sock; + } +} \ No newline at end of file From 7d0fbcd5a3fadc357537f6c0bc2fc893dc72cbb6 Mon Sep 17 00:00:00 2001 From: stephenrjones Date: Tue, 24 Oct 2017 14:48:09 -0400 Subject: [PATCH 2/8] production setup for GeoQ --- Dockerfile | 9 ++++++++- docker-compose.yml | 2 +- docker-entrypoint.sh | 22 +++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1792859d..1e12ceef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ ENV https_proxy http://gatekeeper.mitre.org:80/ RUN apt-get update && apt-get -y upgrade RUN apt-get -y install python-gdbm python-tk RUN apt-get -y install binutils libproj-dev gdal-bin nodejs nodejs-dev npm postgresql-client-common postgresql-client +RUN apt-get -y install nginx RUN npm install -g less RUN ln -s /usr/bin/nodejs /usr/bin/node @@ -14,8 +15,14 @@ WORKDIR /usr/src/geoq RUN pip install -r geoq/requirements.txt --proxy=http://gatekeeper.mitre.org:80/ -EXPOSE 8000 +EXPOSE 80 COPY ./docker-entrypoint.sh / +COPY ./django_nginx.conf /etc/nginx/sites-available/django_nginx.conf +RUN ln -s /etc/nginx/sites-available/django_nginx.conf /etc/nginx/sites-enabled +RUN echo "daemon off;" >> /etc/nginx/nginx.conf + +ENV http_proxy "" +ENV https_proxy "" ENTRYPOINT ["/docker-entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1acda326..22a7878e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: volumes: - /usr/local/src/geoq/geoq:/usr/src/geoq ports: - - "8000:8000" + - "8000:80" command: sh -c 'python app.py' depends_on: - db \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index e88e2e8a..c1bc80b6 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,5 +6,25 @@ export DJANGO_SETTINGS_MODULE=geoq.settings export PATH=$PATH:/usr/lib/postgresql/9.4/bin +python manage.py migrate +python manage.py collectstatic --noinput +paver install_dev_fixtures -python manage.py runserver 0.0.0.0:8000 \ No newline at end of file +# Prepare log files +touch /var/log/gunicorn.log +touch /var/log/access.log +tail -n 0 -f /var/log/gunicorn.log /var/log/access.log & + + +# Start Gunicorn +echo Starting Gunicorn +exec gunicorn geoq.wsgi:application \ + --name geoq \ + --bind unix:django_app.sock \ + --workers 3 \ + --log-level=info \ + --log-file=/var/log/gunicorn.log \ + --access-logfile=/var/log/access.log & + +echo Starting nginx +exec service nginx start \ No newline at end of file From bfc181e79e3e279adba3e4c98f2229d219130b07 Mon Sep 17 00:00:00 2001 From: stephenrjones Date: Wed, 25 Oct 2017 11:14:03 -0400 Subject: [PATCH 3/8] updated production settings --- docker-production.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-production.yml b/docker-production.yml index 88ce5b83..7650ebc7 100644 --- a/docker-production.yml +++ b/docker-production.yml @@ -9,9 +9,8 @@ services: POSTGRES_DB: geoq web: - image: stephenrjones/geoq-django10 + image: stephenrjones/geoq-django10:production ports: - - "80:80" - command: sh -c './wait-for db:5432 -- python app.py' + - "8000:80" depends_on: - db \ No newline at end of file From 5f27158285b15d5359156e8a7eb0ac243e359d57 Mon Sep 17 00:00:00 2001 From: stephenrjones Date: Wed, 8 Nov 2017 11:22:09 -0500 Subject: [PATCH 4/8] changes to run on AWS with dynamic ip --- geoq/settings.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/geoq/settings.py b/geoq/settings.py index 5e2fab2c..a92d83f4 100644 --- a/geoq/settings.py +++ b/geoq/settings.py @@ -19,7 +19,7 @@ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ADMINS = ( ('Admin User', 'admin@domain.com'), @@ -41,7 +41,19 @@ # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts -ALLOWED_HOSTS = ['192.168.5.132','localhost','centos7','web'] +ALLOWED_HOSTS = ['localhost','centos7','web'] + +# for AWS install, get public ip and add to list +import requests +PUBLIC_IP = None +try: + PUBLIC_IP = requests.get('http://169.254.169.254/latest/meta-data/public-ipv4', timeout=0.01).text +except requests.exceptions.RequestException: + pass + +if PUBLIC_IP and not DEBUG: + ALLOWED_HOSTS.append(PUBLIC_IP) + # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name From 2dcbaedf67d6ca5693a0eebdece0d39f06c8f383 Mon Sep 17 00:00:00 2001 From: stephenrjones Date: Wed, 8 Nov 2017 11:32:13 -0500 Subject: [PATCH 5/8] first pass at migrating changes over --- Dockerfile | 14 ++++++++++---- geoq/core/static/core/js/create-aois.js | 18 +++++++++--------- .../templates/core/job_batch_create_aois.html | 13 +++++++------ wait-for | 4 ++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e12ceef..2e4965fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,14 @@ FROM python:2.7.13 -ENV http_proxy http://gatekeeper.mitre.org:80/ -ENV https_proxy http://gatekeeper.mitre.org:80/ +# set appropriately if needed for your environment +ARG http_proxy +ARG https_proxy +ENV http_proxy $http_proxy +ENV https_proxy $https_proxy RUN apt-get update && apt-get -y upgrade RUN apt-get -y install python-gdbm python-tk -RUN apt-get -y install binutils libproj-dev gdal-bin nodejs nodejs-dev npm postgresql-client-common postgresql-client +RUN apt-get -y install binutils libproj-dev gdal-bin nodejs nodejs-dev npm postgresql-client-common postgresql-client netcat RUN apt-get -y install nginx RUN npm install -g less RUN ln -s /usr/bin/nodejs /usr/bin/node @@ -13,7 +16,10 @@ RUN ln -s /usr/bin/nodejs /usr/bin/node ADD . /usr/src/geoq WORKDIR /usr/src/geoq -RUN pip install -r geoq/requirements.txt --proxy=http://gatekeeper.mitre.org:80/ +RUN pip install -r geoq/requirements.txt --proxy=$http_proxy + +RUN dpkg -i ./geoq/tools/geographiclib_1.36-2_amd64.deb +RUN apt-get install -f EXPOSE 80 diff --git a/geoq/core/static/core/js/create-aois.js b/geoq/core/static/core/js/create-aois.js index c348c3ef..aebb1929 100644 --- a/geoq/core/static/core/js/create-aois.js +++ b/geoq/core/static/core/js/create-aois.js @@ -638,23 +638,23 @@ create_aois.mapWasZoomed = function (e) { var $mgrs = $("#option_mgrs"); var $poly = $("#option_polygon"); - var isCONUS = true; - if (typeof maptools != "undefined") { - var ll = e.target.getCenter(); - var pt = maptools.locationInfoString({lat: ll.lat, lng: ll.lng, separator: "
", boldTitles: true}); - - isCONUS = (pt.country && pt.state && pt.country.abbr == "USA" && pt.state.name != "Hawaii" && pt.state.name != "Alaska"); - } +// var isCONUS = true; +// if (typeof maptools != "undefined") { +// var ll = e.target.getCenter(); +// var pt = maptools.locationInfoString({lat: ll.lat, lng: ll.lng, separator: "
", boldTitles: true}); +// +// isCONUS = (pt.country && pt.state && pt.country.abbr == "USA" && pt.state.name != "Hawaii" && pt.state.name != "Alaska"); +// } if (zoom > 8) { //Hide USNG Menu if it's outside CONUS - $usng.attr('disabled', !isCONUS).text('USNG Cells (US only)'); +// $usng.attr('disabled', !isCONUS).text('USNG Cells (US only)'); $mgrs.attr('disabled', false).text('MGRS Cells'); } else { if ($usng.hasClass("active") || $mgrs.hasClass("active")) { $poly.click(); } - $usng.attr('disabled', true).text('Zoom in to use USNG/MGRS'); +// $usng.attr('disabled', true).text('Zoom in to use USNG/MGRS'); $mgrs.attr('disabled', true).text('>'); } }; diff --git a/geoq/core/templates/core/job_batch_create_aois.html b/geoq/core/templates/core/job_batch_create_aois.html index 5e1e5e47..3b089e7e 100644 --- a/geoq/core/templates/core/job_batch_create_aois.html +++ b/geoq/core/templates/core/job_batch_create_aois.html @@ -203,6 +203,7 @@ $('div.leaflet-right div.leaflet-draw.leaflet-control').find('a').popover({trigger: "hover", placement: "left"}); create_aois.map_updates(); + create_aois.mapWasZoomed(); } function highlightFeature(e) { @@ -277,13 +278,13 @@

Add workcells to Job #{{ object.id }} ({{ object.name }})

Name workcells:
-
- Draw using: - - - - +
+ + + +
+ Draw using: