Skip to content

Commit 92da1bb

Browse files
author
Miguel Leon
authored
Merge pull request #120 from lsetiawan/docker_test
Some changes to Fix URL Resolving and also added docker stuff
2 parents 038ea4a + 29bd628 commit 92da1bb

File tree

11 files changed

+214
-59
lines changed

11 files changed

+214
-59
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ lib64
2525
__pycache__
2626

2727
templatesAndSettings/settings.py
28+
templatesAndSettings/settings
29+
.gitignore
2830
odm2djangoadmin.git
2931
omit
3032
migrations

docker/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM miniconda:latest
2+
3+
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
4+
5+
LABEL description='Django admin app for Observation Data Model 2 (ODM2)' \
6+
url='https://github.com/miguelcleon/ODM2-Admin' \
7+
author='Miguel Leon' \
8+
author_email='[email protected]' \
9+
development_status='5 - Production/Stable' \
10+
environment='Console' \
11+
intended_audience='Science/Research, Developers, Education' \
12+
license='MIT License' \
13+
operating_system='OS Independent' \
14+
programming_language='Python' \
15+
topic='Scientific/Engineering, Education'
16+
17+
EXPOSE 8010
18+
EXPOSE 5432
19+
20+
VOLUME /db
21+
22+
# Setting up postgresql database
23+
RUN apt-get update --fix-missing && apt-get install -y postgresql postgresql-client postgresql-contrib postgis
24+
25+
RUN git clone "https://github.com/lsetiawan/ODM2-Admin"
26+
27+
RUN cd ODM2-Admin && latest=$(git describe --tags) && git checkout ${latest}
28+
29+
RUN service postgresql start && su - postgres -c 'psql -U postgres -c "create database odm2_db"'
30+
31+
# RUN service postgresql start && su - postgres -c 'psql -U postgres -c "create database odm2_db"' && \
32+
# su - postgres -c 'pg_restore -d odm2_db -1 -v "/ODM2-Admin/ODM2AdminExamplePostgresqlDB"' && \
33+
# su - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'test';\""
34+
35+
# creates an env with the depepencies
36+
RUN conda create --yes -n odm2adminenv -c conda-forge python=2.7 --file /ODM2-Admin/requirements.txt
37+
RUN update-rc.d postgresql enable
38+
39+
COPY development.py /ODM2-Admin/templatesAndSettings/settings/
40+
COPY entrypoint.sh /
41+
COPY startup.sh /
42+
43+
RUN chmod 755 /entrypoint.sh
44+
RUN chmod 755 /startup.sh
45+
46+
CMD ["/bin/bash", "entrypoint.sh", "startup.sh"]

docker/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ODM2Admin Docker Image Creation
2+
3+
Requirements to run [docker image](https://hub.docker.com/r/lsetiawan/odm2admin/):
4+
5+
1. ODM2 Database backup sql for PostgreSQL called odm2admindb.backup.
6+
2. Docker installed on Linux or MacOS, currently not working on windows.
7+
To run:
8+
$ docker run -d -p 8010:8010 -v path/to/local/db/backup/folder/:/db/ lsetiawan/odm2admin:latest

docker/development.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Development settings and globals.
3+
"""
4+
5+
from base import *
6+
7+
""" DEBUG CONFIGURATION """
8+
# Disable debugging by default.
9+
DEBUG = True
10+
""" END DEBUG CONFIGURATION """
11+
12+
""" ALLOWED HOSTS CONFIGURATION """
13+
ALLOWED_HOSTS = ['127.0.0.1',]
14+
""" END ALLOWED HOSTS CONFIGURATION """
15+
16+
17+
""" EMAIL CONFIGURATION """
18+
EMAIL_HOST = 'smtp.host'
19+
EMAIL_HOST_USER = 'user'
20+
EMAIL_HOST_PASSWORD = 'password'
21+
EMAIL_FROM_ADDRESS = '[email protected]'
22+
RECAPTCHA_PUBLIC_KEY = 'googlerecaptchakey'
23+
RECAPTCHA_PRIVATE_KEY = 'googlerecaptchaprivatekey'
24+
EMAIL_USE_TLS = True
25+
EMAIL_PORT = 123
26+
""" EMAIL CONFIGURATION """
27+
28+
29+
""" DATABASE CONFIGURATION """
30+
DATABASES = {
31+
'default': {
32+
'ENGINE': 'django.contrib.gis.db.backends.postgis',
33+
'NAME': 'odm2_db',
34+
'USER': 'postgres',
35+
'PASSWORD': 'test',
36+
'HOST': 'localhost',
37+
'PORT': '5432',
38+
'OPTIONS': {
39+
'options': '-c search_path=public,admin,odm2,odm2extra'
40+
}
41+
}
42+
}
43+
""" END DATABASE CONFIGURATION """
44+
45+
46+
""" MAP CONFIGURATION """
47+
MAP_CONFIG = {
48+
"lat": 0,
49+
"lon": 0,
50+
"zoom": 2,
51+
"cluster_sites": False,
52+
"time_series_months": 3,
53+
"MapBox": {
54+
"access_token": 'mapboxAccessToken'
55+
},
56+
"result_value_processing_levels_to_display": [1, 2, 3],
57+
"feature_types": ['Excavation', 'Field area', 'Weather station',
58+
'Ecological land classification', 'Observation well', 'Site','Stream gage','Transect', 'Profile','Specimen']
59+
}
60+
""" END MAP CONFIGURATION """
61+
62+
63+
""" DATA DISCLAIMER CONFIGURATION """
64+
DATA_DISCLAIMER = {
65+
"text" : "Add a link discribing where your data come from",
66+
"linktext" : "The name of my site",
67+
"link" : "http://mysiteswegpage.page/"
68+
69+
}
70+
""" END DATA DISCLAIMER CONFIGURATION """

docker/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
4+
cmd="$1"
5+
6+
service postgresql start
7+
8+
until su - postgres -c "psql -U postgres -w -c '\l'"; do
9+
>&2 echo "Postgres is unavailable - sleeping"
10+
sleep 10
11+
done
12+
13+
>&2 echo "Postgres is up - executing command"
14+
exec bash $cmd

docker/startup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
echo "Activating environment..."
4+
source activate odm2adminenv
5+
6+
echo "Building database..."
7+
su - postgres -c 'pg_restore -d odm2_db -1 -v "/db/odm2admindb.backup"'
8+
su - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'test';\""
9+
10+
echo "Running server..."
11+
python /ODM2-Admin/manage.py runserver 0.0.0.0:8010
538 KB
Binary file not shown.

odm2admin/static/js/Map.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ createMarker = function (latlng, markerIcon, color, sfname,style_class,icon_str)
104104
if(this.display_titles){
105105
var iconDiv = new L.DivIcon({
106106
className: style_class + ' awesome-marker leaflet-zoom-animated leaflet-interactive',
107-
html: '<i class="fa '+ icon_str +' icon-white" aria-hidden="true"></i><p style="margin-top:20px;font-weight:bold;">'+sfname + '</p>',
107+
html: '<i class="fa '+ icon_str +' icon-white" aria-hidden="true"></i><p ' +
108+
'style="background-color:rgba(255,255,255,0.8);margin-top:25px;font-weight:bold;">'+sfname + '</p>'
108109
});
109110
marker = L.marker([latlng[0],latlng[1]], {
110-
icon: iconDiv,
111-
markerColor: color,
112-
prefix: 'fa'
111+
icon: iconDiv,
112+
markerColor: color,
113+
prefix: 'fa',
114+
riseOnHover: true
113115
});
114116
return marker;
115117
}else{

odm2admin/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def web_map(request):
538538
'site_header': admin.site.site_header, 'short_title': 'Map Locations',
539539
'basemaps': base_maps, 'sf_types': sf_types, 'selectedterms': selected_type,
540540
'selectedds': json.dumps(ds_selections), 'selectedtype': json.dumps(sftype_selections),
541-
'urlpath': settings.URL_PATH
541+
'urlpath': settings.BASE_URL
542542
}
543543
return render(request, 'mapdata.html', context)
544544

templatesAndSettings/settings/base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
# SECRET_KEY.
2424
SECRET_KEY = 'myRanDom_Secret_Key'
2525
# Application definition
26-
CUSTOM_TEMPLATE_PATH = '/admin/{}/'.format(APP_NAME)
26+
BASE_URL = '' # Enter the base url in your APACHE SETTINGS. e.g. 'ODM2ADMIN/'
2727

28-
URL_PATH = 'admin/'
28+
CUSTOM_TEMPLATE_PATH = '/{}{}/'.format(BASE_URL, APP_NAME)
2929
""" END PATH CONFIGURATION """
3030

3131

@@ -112,7 +112,9 @@
112112
# Absolute path to the directory static files should be collected to. Don't put
113113
# anything in this directory yourself; store your static files in apps' static/
114114
# subdirectories and in STATICFILES_DIRS.
115-
STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
115+
# STATIC_ROOT = '{}/{}/static'.format(BASE_DIR, APP_NAME)
116+
STATIC_DIR = '{}/{}/static'.format(BASE_DIR, APP_NAME)
117+
STATICFILES_DIRS = [STATIC_DIR]
116118
# URL prefix for static files.
117119
STATIC_URL = '/static/'
118120
""" END STATIC FILE CONFIGURATION """
@@ -174,31 +176,31 @@
174176
'class': 'config',
175177
},
176178
{
177-
'url': '/' + URL_PATH + 'AddSensor.html',
179+
'url': '/' + BASE_URL + 'AddSensor.html',
178180
'app_name': '{}'.format(APP_NAME),
179181
'title': 'Add Sensor Data',
180182
'class': 'tool',
181183
},
182184
{
183-
'url': '/' + URL_PATH + 'AddProfile.html',
185+
'url': '/' + BASE_URL + 'AddProfile.html',
184186
'app_name': '{}'.format(APP_NAME),
185187
'title': 'Add Soil Profile Data',
186188
'class': 'flag',
187189
},
188190
{
189-
'url': '/' + URL_PATH + 'RecordAction.html',
191+
'url': '/' + BASE_URL + 'RecordAction.html',
190192
'app_name': '{}'.format(APP_NAME),
191193
'title': 'Record an Action',
192194
'class': 'notepad',
193195
},
194196
{
195-
'url': '/' + URL_PATH + 'ManageCitations.html',
197+
'url': '/' + BASE_URL + 'ManageCitations.html',
196198
'app_name': '{}'.format(APP_NAME),
197199
'title': 'Manage Citations',
198200
'class': 'pencil',
199201
},
200202
{
201-
'url': '/' + URL_PATH + 'chartIndex.html',
203+
'url': '/' + BASE_URL + 'chartIndex.html',
202204
'app_name': '{}'.format(APP_NAME),
203205
'title': 'Graph My Data',
204206
'class': 'monitor',

0 commit comments

Comments
 (0)