-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint-production.sh
63 lines (45 loc) · 1.67 KB
/
docker-entrypoint-production.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
#!/bin/sh
# set -x
echo "=========================================================================="
echo "Starting $0, $(date)"
echo "=========================================================================="
# Generate passphrase if missing
if [ ! -f /var/lib/stack/stack-admin-passphrase ]
then
if [ -z "$STACK_ADMIN_PASSPHRASE" ]
then
echo "Using default admin passphrase !!!"
STACK_ADMIN_PASSPHRASE="stack"
fi
echo "Generating /var/lib/stack/stack-admin-passphrase..."
echo $STACK_ADMIN_PASSPHRASE | stack config passwd /var/lib/stack/stack-admin-passphrase
fi
# Prepare stepping down from root to applicative user with chosen UID/GID
USER_ID=${LOCAL_USER_ID:-35000}
GROUP_ID=${LOCAL_GROUP_ID:-35000}
groupadd -g $GROUP_ID -o stack
useradd --shell /bin/bash -u $USER_ID -g stack -o -c "Stack user" -d /var/lib/stack -m stack
chown -R stack: /var/lib/stack
# Ensuring CouchDB is ready if running an applicative subcommand
if echo "$@" | grep -q "stack serve "
then
echo "Wait for CouchDB to be available..."
wait-for-it.sh -h $COUCHDB_HOST -p $COUCHDB_PORT -t 60
echo "Init CouchDB databases, nothing will happen if they already exists..."
for db in _global_changes _metadata _replicator _users
do
curl -s -X PUT "http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@${COUCHDB_HOST}:${COUCHDB_PORT}/$db"
done
# And also wait for Redis if defined
if [ ! -z "$REDIS_ADDRS" ]
then
echo "Wait for Redis to be available..."
wait-for-it.sh $REDIS_ADDRS -t 60
fi
# Then run the command itself as applicative user
echo "Now running CMD with UID $USER_ID and GID $GROUP_ID"
exec gosu stack "$@"
else
# Otherwise run the command as root
exec "$@"
fi