-
Notifications
You must be signed in to change notification settings - Fork 6
/
post-receive.sample
31 lines (20 loc) · 1.19 KB
/
post-receive.sample
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
ENV="-e USERDB_SALT=xxxsalt -e USERDB_GOOGLE_MAPS_KEY=xxxmapskey -e USERDB_DB_HOST=db.hkfree.org -e USERDB_DB_NAME=xxxdb -e USERDB_DB_USERNAME=xxxuser -e USERDB_DB_PASSWORD=xxxpwd -e USERDB_ENCRYPTION_PASSPHRASE=def000003f80fda926649189d52b4024641f8fa97d1be88638aa8f8c0bec00fdfd756e344f7547db517b17a5ea67085d9de8c88c806795bdec825f8df8b47e6dbb87ec03 -e USERDB_IDS_IPS_WHITELIST=10.107.99.188"
DEPLOYDIR=/opt/UserDB
# get the latest version in master branch
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
TAG=`git log -1 --format=%h`
# go to web app dir
cd "$DEPLOYDIR"
echo "Building Docker image..."
docker build -t userdb:$TAG .
set -e
echo "Upgrading DB schema..." # mandatory
docker run --rm $ENV userdb:$TAG php www/index.php migrations:continue --production
echo "Stopping container..." # optional (may fail if container was not running)
docker stop userdb || true
DATETIME=`date '+%Y%m%d-%H%M%S'`
echo "Renaming old userdb container to userdb-$DATETIME" # optional (may fail if old container does not exist)
docker rename userdb userdb-$DATETIME || true
echo "Starting a new userdb container..." # mandatory
docker run -d --restart=always $ENV --name userdb -p 127.0.0.1:8080:80 userdb:$TAG