forked from karrot-dev/karrot-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·111 lines (76 loc) · 2.61 KB
/
deploy.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -e
HOST=yuca.yunity.org
REF=$1
DIR=$2
if [ -z "$REF" ] || [ -z "$DIR" ]; then
echo "Usage: <ref> <dir>"
exit 1
fi
REPO_URL="https://github.com/yunity/karrot-frontend"
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)
if [ "$DIR" == "release" ]; then
# release
DEPLOY_ENV="production"
DEPLOY_EMOJI=":rocket:"
URL="https://karrot.world"
elif [ "$REF" == "master" ]; then
# dev
DEPLOY_ENV="development"
DEPLOY_EMOJI=":beer:"
URL="https://dev.karrot.world"
STORYBOOK_URL="https://storybook.karrot.world"
DEPLOY_DOCS="true"
else
# nothing
exit 0
fi
REF_URL="$REPO_URL/tree/$REF"
COMMIT_URL="$REPO_URL/tree/$COMMIT_SHA"
mkdir -p ~/.ssh
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts
echo "deploying frontend branch [$REF] to [$HOST] in [$DIR] dir"
about_json=$(printf '{
"commitSHA": "%s",
"commitSHAShort": "%s",
"ref": "%s",
"env": "%s"
}' "$COMMIT_SHA" "$COMMIT_SHA_SHORT" "$REF" "$DEPLOY_ENV")
echo "$about_json" > dist/about.json
echo "$about_json" > storybook-static/about.json
# send it all to the host
rsync -avz --delete dist/ "deploy@$HOST:karrot-frontend/$DIR/"
rsync -avz --delete storybook-static/ "deploy@$HOST:karrot-frontend-storybook/$DIR/"
if [ "$DEPLOY_DOCS" == "true" ] && [ -d docs-dist/gitbook ]; then
rsync -avz --delete docs-dist/ "deploy@$HOST:karrot-docs/$DIR/"
fi
if [ ! -z "$SLACK_WEBHOOK_URL" ]; then
WEBPACK_URL="$URL/bundlesize.html"
CIRCLE_WORKFLOW_URL="https://circleci.com/gh/yunity/workflows/karrot-frontend/tree/$REF"
COMMIT_MESSAGE=$(git log -1 --pretty="%s - %an")
ATTACHMENT_TEXT=""
ATTACHMENT_TEXT+=":karrot: <$URL|Visit the site>"
if [ ! -z "$STORYBOOK_URL" ]; then
ATTACHMENT_TEXT+="\n:books: <$STORYBOOK_URL|Visit the storybook>"
fi
ATTACHMENT_TEXT+="\n:webpack: <$WEBPACK_URL|Visit the webpack bundle analyzer>"
ATTACHMENT_TEXT+="\n:circleci: <$CIRCLE_WORKFLOW_URL|Visit CircleCI>"
if [ "$DEPLOY_DOCS" == "true" ] && [ -d docs-dist ]; then
DOCBOOK_URL="https://docs.karrot.world"
ATTACHMENT_TEXT+="\n:page_facing_up: <$DOCBOOK_URL|View docs>"
fi
ATTACHMENT_FOOTER="Using git ref <$REF_URL|$REF>, commit <$COMMIT_URL|$COMMIT_SHA_SHORT> - $COMMIT_MESSAGE"
payload=$(printf '{
"channel": "#karrot-git",
"username": "deploy",
"text": ":sparkles: Successful deployment of :karrot: *karrot* to _%s_ %s",
"attachments": [
{
"text": "%s",
"footer": "%s"
}
]
}' "$DEPLOY_ENV" "$DEPLOY_EMOJI" "$ATTACHMENT_TEXT" "$ATTACHMENT_FOOTER")
curl -X POST --data-urlencode "payload=$payload" "$SLACK_WEBHOOK_URL"
fi