forked from lucaperret/drone-now
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.sh
112 lines (95 loc) · 3.74 KB
/
script.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
112
#!/bin/sh
set -e
NOW_DEPLOY_OPTIONS=" --no-clipboard"
NOW_AUTH=""
# Get the token or error
if [ -z "$PLUGIN_NOW_TOKEN" ]; then
# No explicit token provided, check for secret
if [ -z "$NOW_TOKEN" ]; then
echo "> Error!! either the parameter now_token or the secret NOW_TOKEN is required!"
exit 1;
else
PLUGIN_NOW_TOKEN="$NOW_TOKEN"
fi
fi
if [ -n "$PLUGIN_TEAM" ]; then
echo "> adding custom team scope $PLUGIN_TEAM"
NOW_TEAM_OPTION="--team $PLUGIN_TEAM"
else
echo "> No custom team scope provided."
fi
NOW_AUTH="$NOW_AUTH --token $PLUGIN_NOW_TOKEN $NOW_TEAM_OPTION"
if [ -n "$PLUGIN_DIRECTORY" ]; then
echo "> Deploying $PLUGIN_DIRECTORY on now.sh…"
fi
if [ -n "$PLUGIN_LOCAL_CONFIG" ]; then
echo "> using local config called $PLUGIN_LOCAL_CONFIG"
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} -A ../$PLUGIN_LOCAL_CONFIG"
NOW_DEPLOYMENT_URL=$(now $NOW_AUTH $NOW_DEPLOY_OPTIONS $PLUGIN_DIRECTORY) &&
echo "> Success! Deployment complete to $NOW_DEPLOYMENT_URL";
if [ -n "$PLUGIN_ALIAS" ]; then
echo "> Assigning alias…" &&
ALIAS_SUCCESS_MESSAGE=$(now alias $NOW_AUTH $NOW_DEPLOYMENT_URL $PLUGIN_ALIAS) &&
echo "$ALIAS_SUCCESS_MESSAGE"
elif grep -q "alias" $PLUGIN_LOCAL_CONFIG; then
# Use alias in local config instead of set alias
echo "> Assigning alias…" &&
ALIAS_SUCCESS_MESSAGE=$(now alias $NOW_AUTH -A ./$PLUGIN_LOCAL_CONFIG) &&
echo "$ALIAS_SUCCESS_MESSAGE"
fi
if grep -q "scale" $PLUGIN_LOCAL_CONFIG; then
echo "> Scaling…" &&
SCALE_SUCCESS_MESSAGE=$(now scale $NOW_AUTH -A ./$PLUGIN_LOCAL_CONFIG $NOW_DEPLOYMENT_URL) &&
echo "$SCALE_SUCCESS_MESSAGE";
fi
else
echo "> No local config provided, now will not use a local config"
if [ -n "$PLUGIN_DEPLOY_NAME" ]; then
echo "> adding deploy_name $PLUGIN_DEPLOY_NAME"
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --name $PLUGIN_DEPLOY_NAME"
else
echo "> No deployment name provided. The directory will be used as the name"
fi
if [ -n "$PLUGIN_TYPE" ]; then
echo "> adding type $PLUGIN_TYPE"
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --$PLUGIN_TYPE"
else
echo "> No deployment type provided, now.sh will try to detect it..."
fi
NOW_DEPLOYMENT_URL=$(now $NOW_AUTH $NOW_DEPLOY_OPTIONS $PLUGIN_DIRECTORY) &&
echo "> Success! Deployment complete to $NOW_DEPLOYMENT_URL";
if [ -n "$PLUGIN_ALIAS" ]; then
echo "> Assigning alias…" &&
ALIAS_SUCCESS_MESSAGE=$(now alias $NOW_AUTH $NOW_DEPLOYMENT_URL $PLUGIN_ALIAS) &&
echo "$ALIAS_SUCCESS_MESSAGE" &&
NOW_DEPLOYMENT_URL="https://$PLUGIN_ALIAS";
fi
if [ -n "$PLUGIN_SCALE" ]; then
echo "> Scaling…" &&
SCALE_SUCCESS_MESSAGE=$(now scale $NOW_AUTH $NOW_DEPLOYMENT_URL $PLUGIN_SCALE) &&
echo "$SCALE_SUCCESS_MESSAGE";
fi
fi
if [ "$PLUGIN_CLEANUP" == "true" ]; then
if [ -n "$PLUGIN_ALIAS" ]; then
echo "> Cleaning up old deployments…" &&
ALIAS_SUCCESS_MESSAGE=$(now rm --safe --yes $NOW_AUTH $PLUGIN_ALIAS) &&
echo "$ALIAS_SUCCESS_MESSAGE"
else
echo "> Warning!! You must set the alias parameter when using the cleanup parameter so that now.sh knows which deployments to remove!"
fi
fi
if [ -n "$PLUGIN_RULES_DOMAIN" ] && [ -n "$PLUGIN_RULES_FILE" ]; then
echo "> Assigning domain rules…" &&
RULES_SUCCESS_MESSAGE=$(now alias $NOW_AUTH $PLUGIN_RULES_DOMAIN -r $PLUGIN_RULES_FILE) &&
echo "$RULES_SUCCESS_MESSAGE" &&
NOW_DEPLOYMENT_URL=$PLUGIN_ALIAS;
fi
## Check exit code
rc=$?;
if [[ $rc != 0 ]]; then
echo "> non-zero exit code $rc" &&
exit $rc
else
echo $'\n'"> Successfully deployed! $NOW_DEPLOYMENT_URL"$'\n'
fi