-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
52 lines (43 loc) · 1.46 KB
/
docker-entrypoint.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
#!/usr/bin/env sh
set -x
if [ -z "$NODE_ENV" ]; then
NODE_ENV=production
export NODE_ENV
fi
if [ ! -f "/usr/src/app/package.json" ]; then
if [ ! -z "$NPM_TOKEN" ]; then
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > /home/pptruser/.npmrc
fi
if [ ! -z "$REPO_KEY" ]; then
echo "Storing private key as /home/pptruser/.ssh/repo-key"
printf "${REPO_KEY}" > /home/pptruser/.ssh/repo-key
fi
if [ ! -z "$GIT_BRANCH" ]; then
GITBRANCHCMD="-b ${GIT_BRANCH}"
else
GITBRANCHCMD=""
fi
if [ ! -s "/home/pptruser/.ssh/repo-key" ]; then
echo "No private key provided - removing configuration"
rm -f /home/pptruser/.ssh/repo-key /home/pptruser/.ssh/config
fi
echo "Cloning ${REPO}"
git clone $GITBRANCHCMD $REPO /usr/src/app
if [ -d "/usr/src/app/.git" ]; then
cd /usr/src/app || exit
mkdir -pv /usr/src/app/.git/hooks
printf "#!/usr/bin/env sh\nif [ -f \"/usr/src/app/yarn.lock\" ]; then\n cd /usr/src/app || exit\n rm -Rf ./node_modules\n yarn install\nelif [ -f \"/usr/src/app/package.json\" ]; then\n cd /usr/src/app || exit\n rm -Rf ./node_modules\n npm install\nfi" > /usr/src/app/.git/hooks/post-merge
chmod 555 /usr/src/app/.git/hooks/post-merge
/usr/src/app/.git/hooks/post-merge
ls -al
else
echo "Failed to fetch repository"
fi
fi
if [ -d "/usr/src/app" ] && [ -f "/usr/src/app/$1" ]; then
cd /usr/src/app || exit
pm2-docker $@
else
echo "There is no NodeJS application installed"
$@
fi