forked from adamcooke/staytus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-start.sh
executable file
·31 lines (24 loc) · 1.21 KB
/
docker-start.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
#!/bin/bash
/etc/init.d/mysql start
cd /opt/staytus
# Configure DB with random password, if not already configured
if [ ! -f /opt/staytus/persisted/config/database.yml ]; then
export RANDOM_PASSWORD=`openssl rand -base64 32`
mysqladmin -u root -ptemp-password password $RANDOM_PASSWORD
echo "CREATE DATABASE staytus CHARSET utf8 COLLATE utf8_unicode_ci" | mysql -u root -p$RANDOM_PASSWORD
cp config/database.example.yml config/database.yml
sed -i "s/username:.*/username: root/" config/database.yml
sed -i "s|password:.*|password: $RANDOM_PASSWORD|" config/database.yml
# Copy the config to persist it, and later copy back on each start, to persist this config file
# without persisting all of /config (which is mostly app code)
mkdir /opt/staytus/persisted/config
cp config/database.yml /opt/staytus/persisted/config/database.yml
bundle exec rake staytus:build staytus:install
else
# Use the previously saved config from the persisted volume
cp /opt/staytus/persisted/config/database.yml config/database.yml
# TODO also copy themes back and forth too
# If already configured, check if there are any migrations to run
bundle exec rake staytus:build staytus:upgrade
fi
bundle exec foreman start