Skip to content

Commit

Permalink
Merge pull request #120 from lsetiawan/docker_test
Browse files Browse the repository at this point in the history
Some changes to Fix URL Resolving and also added docker stuff
  • Loading branch information
Miguel Leon authored Apr 7, 2017
2 parents 038ea4a + 29bd628 commit 92da1bb
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ lib64
__pycache__

templatesAndSettings/settings.py
templatesAndSettings/settings
.gitignore
odm2djangoadmin.git
omit
migrations
Expand Down
46 changes: 46 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM miniconda:latest

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

LABEL description='Django admin app for Observation Data Model 2 (ODM2)' \
url='https://github.com/miguelcleon/ODM2-Admin' \
author='Miguel Leon' \
author_email='leonmi@sas.upenn.edu' \
development_status='5 - Production/Stable' \
environment='Console' \
intended_audience='Science/Research, Developers, Education' \
license='MIT License' \
operating_system='OS Independent' \
programming_language='Python' \
topic='Scientific/Engineering, Education'

EXPOSE 8010
EXPOSE 5432

VOLUME /db

# Setting up postgresql database
RUN apt-get update --fix-missing && apt-get install -y postgresql postgresql-client postgresql-contrib postgis

RUN git clone "https://github.com/lsetiawan/ODM2-Admin"

RUN cd ODM2-Admin && latest=$(git describe --tags) && git checkout ${latest}

RUN service postgresql start && su - postgres -c 'psql -U postgres -c "create database odm2_db"'

# RUN service postgresql start && su - postgres -c 'psql -U postgres -c "create database odm2_db"' && \
# su - postgres -c 'pg_restore -d odm2_db -1 -v "/ODM2-Admin/ODM2AdminExamplePostgresqlDB"' && \
# su - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'test';\""

# creates an env with the depepencies
RUN conda create --yes -n odm2adminenv -c conda-forge python=2.7 --file /ODM2-Admin/requirements.txt
RUN update-rc.d postgresql enable

COPY development.py /ODM2-Admin/templatesAndSettings/settings/
COPY entrypoint.sh /
COPY startup.sh /

RUN chmod 755 /entrypoint.sh
RUN chmod 755 /startup.sh

CMD ["/bin/bash", "entrypoint.sh", "startup.sh"]
8 changes: 8 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ODM2Admin Docker Image Creation

Requirements to run [docker image](https://hub.docker.com/r/lsetiawan/odm2admin/):

1. ODM2 Database backup sql for PostgreSQL called odm2admindb.backup.
2. Docker installed on Linux or MacOS, currently not working on windows.
To run:
$ docker run -d -p 8010:8010 -v path/to/local/db/backup/folder/:/db/ lsetiawan/odm2admin:latest
70 changes: 70 additions & 0 deletions docker/development.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Development settings and globals.
"""

from base import *

""" DEBUG CONFIGURATION """
# Disable debugging by default.
DEBUG = True
""" END DEBUG CONFIGURATION """

""" ALLOWED HOSTS CONFIGURATION """
ALLOWED_HOSTS = ['127.0.0.1',]
""" END ALLOWED HOSTS CONFIGURATION """


""" EMAIL CONFIGURATION """
EMAIL_HOST = 'smtp.host'
EMAIL_HOST_USER = 'user'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_FROM_ADDRESS = 'do-not-reply-ODM2-Admin@cuahsi.org'
RECAPTCHA_PUBLIC_KEY = 'googlerecaptchakey'
RECAPTCHA_PRIVATE_KEY = 'googlerecaptchaprivatekey'
EMAIL_USE_TLS = True
EMAIL_PORT = 123
""" EMAIL CONFIGURATION """


""" DATABASE CONFIGURATION """
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'odm2_db',
'USER': 'postgres',
'PASSWORD': 'test',
'HOST': 'localhost',
'PORT': '5432',
'OPTIONS': {
'options': '-c search_path=public,admin,odm2,odm2extra'
}
}
}
""" END DATABASE CONFIGURATION """


""" MAP CONFIGURATION """
MAP_CONFIG = {
"lat": 0,
"lon": 0,
"zoom": 2,
"cluster_sites": False,
"time_series_months": 3,
"MapBox": {
"access_token": 'mapboxAccessToken'
},
"result_value_processing_levels_to_display": [1, 2, 3],
"feature_types": ['Excavation', 'Field area', 'Weather station',
'Ecological land classification', 'Observation well', 'Site','Stream gage','Transect', 'Profile','Specimen']
}
""" END MAP CONFIGURATION """


""" DATA DISCLAIMER CONFIGURATION """
DATA_DISCLAIMER = {
"text" : "Add a link discribing where your data come from",
"linktext" : "The name of my site",
"link" : "http://mysiteswegpage.page/"

}
""" END DATA DISCLAIMER CONFIGURATION """
14 changes: 14 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

cmd="$1"

service postgresql start

until su - postgres -c "psql -U postgres -w -c '\l'"; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 10
done

>&2 echo "Postgres is up - executing command"
exec bash $cmd
11 changes: 11 additions & 0 deletions docker/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo "Activating environment..."
source activate odm2adminenv

echo "Building database..."
su - postgres -c 'pg_restore -d odm2_db -1 -v "/db/odm2admindb.backup"'
su - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'test';\""

echo "Running server..."
python /ODM2-Admin/manage.py runserver 0.0.0.0:8010
Binary file added docker/test_db_folder/odm2admindb.backup
Binary file not shown.
10 changes: 6 additions & 4 deletions odm2admin/static/js/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ createMarker = function (latlng, markerIcon, color, sfname,style_class,icon_str)
if(this.display_titles){
var iconDiv = new L.DivIcon({
className: style_class + ' awesome-marker leaflet-zoom-animated leaflet-interactive',
html: '<i class="fa '+ icon_str +' icon-white" aria-hidden="true"></i><p style="margin-top:20px;font-weight:bold;">'+sfname + '</p>',
html: '<i class="fa '+ icon_str +' icon-white" aria-hidden="true"></i><p ' +
'style="background-color:rgba(255,255,255,0.8);margin-top:25px;font-weight:bold;">'+sfname + '</p>'
});
marker = L.marker([latlng[0],latlng[1]], {
icon: iconDiv,
markerColor: color,
prefix: 'fa'
icon: iconDiv,
markerColor: color,
prefix: 'fa',
riseOnHover: true
});
return marker;
}else{
Expand Down
2 changes: 1 addition & 1 deletion odm2admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def web_map(request):
'site_header': admin.site.site_header, 'short_title': 'Map Locations',
'basemaps': base_maps, 'sf_types': sf_types, 'selectedterms': selected_type,
'selectedds': json.dumps(ds_selections), 'selectedtype': json.dumps(sftype_selections),
'urlpath': settings.URL_PATH
'urlpath': settings.BASE_URL
}
return render(request, 'mapdata.html', context)

Expand Down
18 changes: 10 additions & 8 deletions templatesAndSettings/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# SECRET_KEY.
SECRET_KEY = 'myRanDom_Secret_Key'
# Application definition
CUSTOM_TEMPLATE_PATH = '/admin/{}/'.format(APP_NAME)
BASE_URL = '' # Enter the base url in your APACHE SETTINGS. e.g. 'ODM2ADMIN/'

URL_PATH = 'admin/'
CUSTOM_TEMPLATE_PATH = '/{}{}/'.format(BASE_URL, APP_NAME)
""" END PATH CONFIGURATION """


Expand Down Expand Up @@ -112,7 +112,9 @@
# Absolute path to the directory static files should be collected to. Don't put
# anything in this directory yourself; store your static files in apps' static/
# subdirectories and in STATICFILES_DIRS.
STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
# STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
STATIC_DIR = '{}/{}/static'.format(BASE_DIR, APP_NAME)
STATICFILES_DIRS = [STATIC_DIR]
# URL prefix for static files.
STATIC_URL = '/static/'
""" END STATIC FILE CONFIGURATION """
Expand Down Expand Up @@ -174,31 +176,31 @@
'class': 'config',
},
{
'url': '/' + URL_PATH + 'AddSensor.html',
'url': '/' + BASE_URL + 'AddSensor.html',
'app_name': '{}'.format(APP_NAME),
'title': 'Add Sensor Data',
'class': 'tool',
},
{
'url': '/' + URL_PATH + 'AddProfile.html',
'url': '/' + BASE_URL + 'AddProfile.html',
'app_name': '{}'.format(APP_NAME),
'title': 'Add Soil Profile Data',
'class': 'flag',
},
{
'url': '/' + URL_PATH + 'RecordAction.html',
'url': '/' + BASE_URL + 'RecordAction.html',
'app_name': '{}'.format(APP_NAME),
'title': 'Record an Action',
'class': 'notepad',
},
{
'url': '/' + URL_PATH + 'ManageCitations.html',
'url': '/' + BASE_URL + 'ManageCitations.html',
'app_name': '{}'.format(APP_NAME),
'title': 'Manage Citations',
'class': 'pencil',
},
{
'url': '/' + URL_PATH + 'chartIndex.html',
'url': '/' + BASE_URL + 'chartIndex.html',
'app_name': '{}'.format(APP_NAME),
'title': 'Graph My Data',
'class': 'monitor',
Expand Down
Loading

0 comments on commit 92da1bb

Please sign in to comment.