-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ckan-entrypoint.sh
78 lines (62 loc) · 1.94 KB
/
ckan-entrypoint.sh
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
#!/bin/sh
set -eu
# URL for the primary database, in the format expected by sqlalchemy (required
# unless linked to a container called 'db')
: ${DATABASE_URL:=}
# URL for solr (required unless linked to a container called 'solr')
: ${SOLR_URL:=}
# URL for redis (required unless linked to a container called 'redis')
: ${REDIS_URL:=}
CONFIG="${CKAN_CONFIG}/ckan.ini"
abort () {
echo "$@" >&2
exit 1
}
write_config () {
ckan-paster make-config ckan "$CONFIG"
ckan-paster --plugin=ckan config-tool "$CONFIG" -e \
"sqlalchemy.url = ${DATABASE_URL}" \
"solr_url = ${SOLR_URL}" \
"ckan.redis.url = ${REDIS_URL}" \
"ckan.storage_path = ${CKAN_DATA}" \
"ckan.site_url = ${SITE_URL}"
}
link_postgres_url () {
local user=$DB_ENV_POSTGRES_USER
local pass=$DB_ENV_POSTGRES_PASSWORD
local db=$DB_ENV_POSTGRES_DB
local host=$DB_PORT_5432_TCP_ADDR
local port=$DB_PORT_5432_TCP_PORT
echo "postgresql://${user}:${pass}@${host}:${port}/${db}"
}
link_solr_url () {
local host=$SOLR_PORT_8983_TCP_ADDR
local port=$SOLR_PORT_8983_TCP_PORT
echo "http://${host}:${port}/solr/ckan"
}
link_redis_url () {
local host=$REDIS_PORT_6379_TCP_ADDR
local port=$REDIS_PORT_6379_TCP_PORT
echo "redis://${host}:${port}/1"
}
# If we don't already have a config file, bootstrap
if [ ! -e "$CONFIG" ]; then
if [ -z "$DATABASE_URL" ]; then
if ! DATABASE_URL=$(link_postgres_url); then
abort "ERROR: no DATABASE_URL specified and linked container called 'db' was not found"
fi
fi
if [ -z "$SOLR_URL" ]; then
if ! SOLR_URL=$(link_solr_url); then
abort "ERROR: no SOLR_URL specified and linked container called 'solr' was not found"
fi
fi
if [ -z "$REDIS_URL" ]; then
if ! REDIS_URL=$(link_redis_url); then
abort "ERROR: no REDIS_URL specified and linked container called 'redis' was not found"
fi
fi
write_config
fi
ckan-paster --plugin=ckan db init -c "${CKAN_CONFIG}/ckan.ini"
exec "$@"