-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
56 lines (51 loc) · 1.61 KB
/
deploy.sh
File metadata and controls
56 lines (51 loc) · 1.61 KB
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
#!/bin/bash
#
# Deploys a web application from an git repository by tag version
#
#### Variables
SLACK_URL=''
SLACK_CHANNEL='#deployments'
GIT_FQDN=''
WEB_DIR='/var/www' # No trailing forward slash
#### Do not edit below this line
FOLDER=$(date +"%Y%m%d%H%M%S")
NAMESPACE=$1
PROJECT=$2
TAG=$3
function postSlack () {
SLACK_MESSAGE="$1"
case "$2" in
INFO)
SLACK_ICON=':slack:'
;;
WARNING)
SLACK_ICON=':warning:'
;;
ERROR)
SLACK_ICON=':bangbang:'
;;
*)
SLACK_ICON=':slack:'
;;
esac
curl -X POST --data-urlencode "payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$(hostname)\", \"text\": \"$SLACK_MESSAGE\", \"icon_emoji\": \"$SLACK_ICON\"}" $SLACK_URL
}
if [ $# -lt 1 ]; then
echo Usage: deploy.sh namespace project tag
exit
fi
cd "$WEB_DIR" || { postSlack "$NAMESPACE/$PROJECT $TAG could not change to web directory." "ERROR"; exit 1; }
git clone git@"$GIT_FQDN":"$NAMESPACE"/"$PROJECT".git "$FOLDER" || { postSlack "$NAMESPACE/$PROJECT $TAG could clone from $GIT_FQDN." "ERROR"; exit 1; }
cd "$FOLDER" || exit 1;
git checkout "$TAG" || { postSlack "$NAMESPACE/$PROJECT $TAG tag not found." "ERROR"; exit 1;}
if [ -d "/etc/env/$NAMESPACE/$PROJECT" ]; then
cp /etc/env/"$NAMESPACE"/"$PROJECT"/.env /var/www/"$FOLDER"/.env
composer install --no-interaction
chmod 777 -R "$WEB_DIR"/"$FOLDER"/storage
php artisan optimize
php artisan key:generate # Comment this if we symlink to $FOLDER/storage
fi
rm -rf "${WEB_DIR:?}"/"$PROJECT"
ln -sf "$WEB_DIR"/"$FOLDER" "$WEB_DIR"/"$PROJECT"
postSlack "$NAMESPACE/$PROJECT $TAG deployed successfully." "INFO"
exit 0