-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
86 lines (72 loc) · 2.16 KB
/
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
#!/usr/bin/env bash
cat >> $DEPLOY_USER_HOME/.profile <<EOS
export DEPLOY_USER=$DEPLOY_USER
export DEPLOY_USER_HOME=$DEPLOY_USER_HOME
export WORKDIR=$WORKDIR
export GIT_REMOTE=$GIT_REMOTE
export PORT=$PORT
cd $WORKDIR
EOS
if [ $NEWUID ]; then
echo "Setting $DEPLOY_USER uid to $NEWUID"
usermod --uid $NEWUID $DEPLOY_USER
fi
# Deploy the web app if the git remote was given
if [ $GIT_REMOTE ]; then
if [ -z "$(ls "$WORKDIR")" ]; then
echo "Deploying web app at $GIT_REMOTE to $WORKDIR"
if [ ! -d $DEPLOY_USER_HOME/.ssh ]; then
mkdir $DEPLOY_USER_HOME/.ssh \
&& chmod 700 $DEPLOY_USER_HOME/.ssh \
&& ENV_CREATED=1
if [ $ENV_CREATED ]; then
echo "Created .ssh for $DEPLOY_USER"
else
echo "Could NOT create environment for $DEPLOY_USER"
exit 1
fi
else
echo "Found .ssh for $DEPLOY_USER"
fi
if [ -e $SSHDIR/id_rsa ]; then
if ! [ -e $DEPLOY_USER_HOME/.ssh/id_rsa ]; then
echo "Copying SSH key files..."
cp $SSHDIR/id_rsa* $DEPLOY_USER_HOME/.ssh
chmod 600 $DEPLOY_USER_HOME/.ssh/*
chown -R $DEPLOY_USER: $DEPLOY_USER_HOME/.ssh
else
echo "Found $DEPLOY_USER_HOME/.ssh/id_rsa"
fi
else
echo "SSH key files not found"
exit 1
fi
echo "ssh-keyscan $GIT_DOMAIN >> ~/.ssh/known_hosts \
&& git clone $GIT_REMOTE $WORKDIR" | su - $DEPLOY_USER --shell=/bin/bash \
&& CODE_DEPLOYED=1
if ! [ $CODE_DEPLOYED ]; then
echo "Could NOT deploy code."
exit 1
fi
else
echo "$WORKDIR contains files"
fi
fi
# Run the web app's build command
cd "$WORKDIR"
echo "yarn install" | su - $DEPLOY_USER --shell=/bin/bash && APP_INSTALLED=1
if [ $APP_INSTALLED ]; then
echo "The project has been built!"
echo "IMPORTANT: Please press Ctrl-P+Q to send the server to the background in order to keep it running."
else
echo "The project was NOT built"
exit 1
fi
if [ $GIT_REMOTE ]; then
# Make and run the production build
echo "yarn build \
&& serve -s "$WORKDIR"/build -p $PORT" | su - $DEPLOY_USER --shell=/bin/bash
else
# Launch the dev server
echo "yarn start" | su - $DEPLOY_USER --shell=/bin/bash
fi