-
Notifications
You must be signed in to change notification settings - Fork 6
/
docker-start.sh
executable file
·89 lines (66 loc) · 2.73 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
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
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. ${DIR}/create-git-url.sh
runtimeEnv=$(uname)
echo "Running as $(whoami)."
if [ "$runtimeEnv" != "Linux" ] || [ ! -f /.dockerenv ]; then
echo "Do not use this script in non-dockerized environments."
echo "Detected non-Linux runtime $runtimeEnv, or /.dockerenv is not present."
echo "Use 'node bin/api' or 'npm start'.'"
exit 1
fi
if [ ! -z "$GIT_REPO" ]; then
tmpDir=$(mktemp -d)
echo "Cloning configuration repository from $GIT_REPO into $tmpDir..."
pushd $tmpDir
if [ ! -z "$GIT_BRANCH" ] && [ ! -z "$GIT_REVISION" ]; then
echo "===================================================================================="
echo "ERROR: GIT_REVISION and GIT_BRANCH are mutually exclusive (both are defined)!"
echo "===================================================================================="
exit 1
fi
# this will create and set the GIT_URL variable
create_git_url $GIT_REPO $GIT_CREDENTIALS
if [ -z "$GIT_BRANCH" ]; then
echo "Checking out branch 'master'..."
git clone ${GIT_URL} .
else
echo "Checking out branch '$GIT_BRANCH'..."
git clone ${GIT_URL} --branch ${GIT_BRANCH} .
fi
if [ ! -z "$GIT_REVISION" ]; then
echo "Checking out specific revision with SHA ${GIT_REVISION}..."
git checkout $GIT_REVISION
fi
if [ ! -d "$tmpDir/static" ]; then
echo "===================================================================================="
echo "ERROR: Could not find directory 'static' in $tmpDir, wrong repository?"
echo "===================================================================================="
exit 1
fi
echo Adding metadata to static directory...
git log -1 > static/last_commit
date -u "+%Y-%m-%d %H:%M:%S" > static/build_date
echo "Cleaning up old configuration (if applicable)"
rm -rf /var/portal-api/static
echo "Copying configuration to /var/portal-api/static"
cp -R static /var/portal-api
echo "Done."
popd
echo "Cleanining up temp dir."
rm -rf $tmpDir
else
echo "Assuming /var/portal-api/static is prepopulated, not cloning configuration repo."
fi
echo "Calculating config hash..."
pushd /var/portal-api/static
tempMd5Hash=$(find . -type f -exec md5sum {} \; | sort -k 2 | md5sum)
printf ${tempMd5Hash:0:32} > /var/portal-api/static/confighash
echo "Hash: $(cat /var/portal-api/static/confighash)"
popd
echo "Setting owner of /var/portal-api to wicked:wicked"
chown wicked:wicked $(find /var/portal-api | grep -v .snapshot)
echo "Starting API, running as user 'wicked'..."
# Use gosu to start node as the user "wicked"
gosu wicked node bin/api