-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckan-entrypoint.sh
executable file
·85 lines (71 loc) · 2.52 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
79
80
81
82
83
84
85
#!/bin/sh
set -e
# URL for the primary database, in the format expected by sqlalchemy (required
# unless linked to a container called 'db')
: ${CKAN_SQLALCHEMY_URL:=}
# URL for solr (required unless linked to a container called 'solr')
: ${CKAN_SOLR_URL:=}
# URL for redis (required unless linked to a container called 'redis')
: ${CKAN_REDIS_URL:=}
# URL for datapusher (required unless linked to a container called 'datapusher')
: ${CKAN_DATAPUSHER_URL:=}
CONFIG="${CKAN_CONFIG}/production.ini"
abort () {
echo "$@" >&2
exit 1
}
set_environment () {
export CKAN_SITE_ID=${CKAN_SITE_ID}
export CKAN_SITE_URL=${CKAN_SITE_URL}
export CKAN_SQLALCHEMY_URL=${CKAN_SQLALCHEMY_URL}
export CKAN_SOLR_URL=${CKAN_SOLR_URL}
export CKAN_REDIS_URL=${CKAN_REDIS_URL}
export CKAN_STORAGE_PATH=/var/lib/ckan
export CKAN_DATAPUSHER_URL=${CKAN_DATAPUSHER_URL}
export CKAN_DATASTORE_WRITE_URL=${CKAN_DATASTORE_WRITE_URL}
export CKAN_DATASTORE_READ_URL=${CKAN_DATASTORE_READ_URL}
export CKAN_SMTP_SERVER=${CKAN_SMTP_SERVER}
export CKAN_SMTP_STARTTLS=${CKAN_SMTP_STARTTLS}
export CKAN_SMTP_USER=${CKAN_SMTP_USER}
export CKAN_SMTP_PASSWORD=${CKAN_SMTP_PASSWORD}
export CKAN_SMTP_MAIL_FROM=${CKAN_SMTP_MAIL_FROM}
export CKAN_MAX_UPLOAD_SIZE_MB=${CKAN_MAX_UPLOAD_SIZE_MB}
}
write_config () {
echo "Generating config at ${CONFIG}..."
ckan generate config "$CONFIG"
}
# Wait for PostgreSQL
if [ -z "$CKAN_SQLALCHEMY_URL" ]; then
abort "ERROR: no CKAN_SQLALCHEMY_URL specified in docker-compose.yml"
fi
while ! pg_isready -d "$CKAN_SQLALCHEMY_URL"; do
sleep 1;
done
# If we don't already have a config file, bootstrap
if [ ! -e "$CONFIG" ]; then
write_config
fi
if [ -z "$CKAN_SOLR_URL" ]; then
abort "ERROR: no CKAN_SOLR_URL specified in docker-compose.yml"
fi
if [ -z "$CKAN_REDIS_URL" ]; then
abort "ERROR: no CKAN_REDIS_URL specified in docker-compose.yml"
fi
if [ -z "$CKAN_DATAPUSHER_URL" ]; then
abort "ERROR: no CKAN_DATAPUSHER_URL specified in docker-compose.yml"
fi
set_environment
echo "Running db init: ..."
ckan --config "$CONFIG" db init
echo "Running short urls db init: ..."
ckan --config "$CONFIG" versions initdb
ckan --config "$CONFIG" short-urls initdb
# Setup Google Analytics if enabled
if [ "$CKAN_GOOGLEANALYTICS_ENABLED" = "True" ]; then
echo "Set up tables for Google analytics:"
ckan --config "$CONFIG" googleanalytics init
echo "Load analytics from Google into the local database:"
ckan --config "$CONFIG" googleanalytics load "${CKAN_CONFIG}/google_analytics_credentials.json"
fi
exec "$@"