forked from GeoNode/geonode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
executable file
·194 lines (161 loc) · 6.24 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import json
import os
import re
import ast
from invoke import task
BOOTSTRAP_IMAGE_CHEIP = 'codenvy/che-ip:nightly'
@task
def waitfordbs(ctx):
print "**************************databases*******************************"
ctx.run("/usr/bin/wait-for-databases {0}".format('db'), pty=True)
@task
def update(ctx):
print "***************************initial*********************************"
ctx.run("env", pty=True)
pub_ip = _geonode_public_host_ip()
print "Public Hostname or IP is {0}".format(pub_ip)
pub_port = _geonode_public_port()
print "Public PORT is {0}".format(pub_port)
db_url = _update_db_connstring()
geodb_url = _update_geodb_connstring()
override_env = "$HOME/.override_env"
envs = {
"public_fqdn": "{0}:{1}".format(pub_ip, pub_port or 80),
"public_host": "{0}".format(pub_ip),
"dburl": db_url,
"geodburl": geodb_url,
"override_fn": override_env
}
if os.environ.get(
'GEONODE_LB_HOST_IP'
) and os.environ.get(
'GEONODE_LB_PORT'
):
ctx.run("echo export GEOSERVER_PUBLIC_LOCATION=\
http://{public_fqdn}/geoserver/ >> {override_fn}".format(**envs), pty=True)
ctx.run("echo export GEOSERVER_WEB_UI_LOCATION=\
http://{public_fqdn}/geoserver/ >> {override_fn}".format(**envs), pty=True)
ctx.run("echo export SITEURL=\
http://{public_fqdn}/ >> {override_fn}".format(**envs), pty=True)
try:
current_allowed = ast.literal_eval(
os.getenv('ALLOWED_HOSTS') or "[\
'{public_fqdn}', '{public_host}', 'localhost', 'django', 'geonode',\
]".format(**envs))
except ValueError:
current_allowed = []
current_allowed.extend(
['{}'.format(pub_ip), '{}:{}'.format(pub_ip, pub_port)]
)
allowed_hosts = ['"{}"'.format(c) for c in current_allowed]
for host in ['django', 'geonode']:
if host not in allowed_hosts:
allowed_hosts.extend(['{}'.format(host)])
ctx.run('echo export ALLOWED_HOSTS="\\"{}\\"" >> {}'.format(
allowed_hosts, override_env
), pty=True)
if not os.environ.get('DATABASE_URL'):
ctx.run("echo export DATABASE_URL=\
{dburl} >> {override_fn}".format(**envs), pty=True)
if not os.environ.get('GEODATABASE_URL'):
ctx.run("echo export GEODATABASE_URL=\
{geodburl} >> {override_fn}".format(**envs), pty=True)
ctx.run("source $HOME/.override_env", pty=True)
print "****************************final**********************************"
ctx.run("env", pty=True)
@task
def migrations(ctx):
print "**************************migrations*******************************"
ctx.run("django-admin.py migrate --noinput --settings={0}".format(
_localsettings()
), pty=True)
@task
def statics(ctx):
print "**************************migrations*******************************"
ctx.run('mkdir -p /mnt/volumes/statics/{static,uploads}')
ctx.run("python manage.py collectstatic --noinput --clear --settings={0}".format(
_localsettings()
), pty=True)
@task
def prepare(ctx):
print "**********************prepare fixture***************************"
ctx.run("rm -rf /tmp/default_oauth_apps_docker.json", pty=True)
_prepare_oauth_fixture()
@task
def fixtures(ctx):
print "**************************fixtures********************************"
ctx.run("django-admin.py loaddata sample_admin \
--settings={0}".format(_localsettings()), pty=True)
ctx.run("django-admin.py loaddata /tmp/default_oauth_apps_docker.json \
--settings={0}".format(_localsettings()), pty=True)
ctx.run("django-admin.py loaddata geonode/base/fixtures/initial_data.json \
--settings={0}".format(_localsettings()), pty=True)
@task
def initialized(ctx):
print "**************************init file********************************"
ctx.run('date > /mnt/volumes/statics/geonode_init.lock')
@task
def devrequirements(ctx):
print "*********************install dev requirements**********************"
ctx.run('pip install -r requirements_dev.txt --upgrade')
def _update_db_connstring():
user = os.getenv('GEONODE_DATABASE', 'geonode')
pwd = os.getenv('GEONODE_DATABASE_PASSWORD', 'geonode')
dbname = os.getenv('GEONODE_DATABASE', 'geonode')
connstr = 'postgres://{0}:{1}@db:5432/{2}'.format(
user,
pwd,
dbname
)
return connstr
def _update_geodb_connstring():
geouser = os.getenv('GEONODE_GEODATABASE', 'geonode_data')
geopwd = os.getenv('GEONODE_GEODATABASE_PASSWORD', 'geonode_data')
geodbname = os.getenv('GEONODE_GEODATABASE', 'geonode_data')
geoconnstr = 'postgis://{0}:{1}@db:5432/{2}'.format(
geouser,
geopwd,
geodbname
)
return geoconnstr
def _localsettings():
settings = os.getenv('DJANGO_SETTINGS_MODULE', 'geonode.settings')
return settings
def _geonode_public_host_ip():
gn_pub_hostip = os.getenv('GEONODE_LB_HOST_IP', 'localhost')
return gn_pub_hostip
def _geonode_public_port():
gn_pub_port = os.getenv('GEONODE_LB_PORT', '80')
return gn_pub_port
def _prepare_oauth_fixture():
pub_ip = _geonode_public_host_ip()
print "Public Hostname or IP is {0}".format(pub_ip)
pub_port = _geonode_public_port()
print "Public PORT is {0}".format(pub_port)
default_fixture = [
{
"model": "oauth2_provider.application",
"pk": 1001,
"fields": {
"skip_authorization": True,
"created": "2018-05-31T10:00:31.661Z",
"updated": "2018-05-31T11:30:31.245Z",
"algorithm": "RS256",
"redirect_uris": "http://{0}:{1}/geoserver/index.html".format(
pub_ip, pub_port
),
"name": "GeoServer",
"authorization_grant_type": "authorization-code",
"client_type": "confidential",
"client_id": "Jrchz2oPY3akmzndmgUTYrs9gczlgoV20YPSvqaV",
"client_secret": "\
rCnp5txobUo83EpQEblM8fVj3QT5zb5qRfxNsuPzCqZaiRyIoxM4jdgMiZKFfePBHYXCLd7B8NlkfDB\
Y9HKeIQPcy5Cp08KQNpRHQbjpLItDHv12GvkSeXp6OxaUETv3",
"user": [
"admin"
]
}
}
]
with open('/tmp/default_oauth_apps_docker.json', 'w') as fixturefile:
json.dump(default_fixture, fixturefile)