-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·133 lines (105 loc) · 3.51 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·133 lines (105 loc) · 3.51 KB
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
#!/usr/bin/env bash
set -e
dc="docker-compose --no-ansi"
# Generate a secret key that length of "$1"
function secret() {
dd if=/dev/urandom bs="$1" count=1 2>/dev/null | openssl enc -A -base64
}
function require() {
command -v "$1" > /dev/null 2>&1 || {
echo "Some of the required software is not installed:"
echo " please install $1" >&2;
exit 4;
}
}
require docker
require docker-compose
# Step 1: Check current system dependencies.
if [ ! -f .env ]; then cp -f .env.dist .env ; fi
# Step 2: Create persistent storage.
#
$dc down --rmi local --remove-orphans
echo ""
echo "Creating Docker volumes..."
echo "Created $(docker volume create --name=metamapper-postgres)."
echo "Created $(docker volume create --name=metamapper-msgbroker)."
# Step 3: Copy configurations and generate secret keys, if needed.
#
# You can update the configuration paths here if you want to rename the default files.
#
echo ""
echo "Checking if configuration files exist..."
echo ""
CELERY_CONFIG_PY='metamapper/conf/celery.py'
CELERY_TEMPLATE_PY='config_templates/celery.default.py'
if [ ! -f "$CELERY_CONFIG_PY" ]; then
echo "Copying default Celery configuration."
cp $CELERY_TEMPLATE_PY $CELERY_CONFIG_PY
else
echo "File already exists: $CELERY_CONFIG_PY"
fi
DJANGO_CONFIG_PY='metamapper/conf/settings.py'
DJANGO_TEMPLATE_PY='config_templates/settings.default.py'
if [ ! -f "$DJANGO_CONFIG_PY" ]; then
echo "Copying default Django override settings."
cp $DJANGO_TEMPLATE_PY $DJANGO_CONFIG_PY
else
echo "File already exists: $DJANGO_CONFIG_PY"
fi
GUNICORN_CONFIG_PY='metamapper/conf/gunicorn.py'
GUNICORN_TEMPLATE_PY='config_templates/gunicorn.default.py'
if [ ! -f "$GUNICORN_CONFIG_PY" ]; then
echo "Copying default Gunicorn configuration."
cp $GUNICORN_TEMPLATE_PY $GUNICORN_CONFIG_PY
else
echo "File already exists: $GUNICORN_CONFIG_PY"
fi
# Write out the secrets into the .env file. You can change these if you want.
if ! grep -q "METAMAPPER_SECRET_KEY" .env ; then
echo ""
echo "Generating secret key..."
echo "METAMAPPER_SECRET_KEY=$(secret 50)" >> .env
echo "Secret key written to the .env file"
fi
# Write out the secrets into the .env file. You can change these if you want.
if ! grep -q "METAMAPPER_FERNET_KEY" .env ; then
echo ""
echo "Generating encryption key..."
echo "METAMAPPER_FERNET_KEY=$(secret 32)" >> .env
echo "Encryption key written to the .env file"
fi
# Step 4: Fetch any Docker dependencies.
#
echo ""
echo "Fetching and updating Docker images..."
echo ""
MM_IMAGE=${METAMAPPER_IMAGE:-getmetamapper/metamapper}
MM_VERSION=${METAMAPPER_VERSION:-latest}
docker pull $MM_IMAGE:$MM_VERSION
# Step 5: Build the local Docker image using their Metamapper configuration.
#
echo ""
echo "Building and tagging on-premise Docker image..."
echo ""
$dc build --build-arg METAMAPPER_IMAGE=$MM_IMAGE --force-rm webserver
echo ""
echo "Docker image has been built."
# Step 6: Set up the database and run the migrations.
#
echo ""
echo "Creating database..."
$dc run -e DB_SETUP=1 --rm webserver manage initdb --close-sessions --noinput --verbosity 0
$dc run -e DB_SETUP=1 --rm webserver migrate
echo ""
echo "Database has been created and migrations have been run."
# Step 7: Clean up and exit the build process.
$dc stop &> /dev/null
echo ""
echo "----------------"
echo ""
echo "Setup is complete! Run the following command to spin up Metamapper:"
echo ""
echo " docker-compose up -d"
echo ""
echo "Access to the web UI defaults to: http://localhost:5050"
echo ""