-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdeploy.sh
executable file
·105 lines (100 loc) · 3.31 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
#!/bin/sh
echo "pwd: $(pwd)"
rm -rf dist
mkdir dist
ACTION="$1"
if [ -z "${ACTION}" ]
then
echo "Missing action name as first parameter to script, exiting"
exit 1
fi
if ! [[ "$ACTION" =~ ^(checker|lookup|setgithubcheck|signwebhook)$ ]]
then
echo "Action name must be one of 'checker', 'lookup', 'setgithubcheck' or 'signwebhook', exiting"
exit 2
fi
ENV="$2"
if [ -z "${ENV}" ]
then
ENV="stage"
fi
# make sure we have all our credentials sorted
if [ -e "${ACTION}/config.json" ]
then
echo "Using config.json from $ACTION/ dir"
cp "${ACTION}/config.json" dist/config.json
elif [ -e config.json ]
then
echo "Using config.json from root dir"
cp config.json dist/config.json
elif [ ! -z "${GITHUB_APP_ID}" ] && [ ! -z "${GITHUB_KEY}" ] && [ ! -z "${SIGN_CLIENT_ID}" ] && [ ! -z "${SIGN_CLIENT_SECRET}" ] && [ ! -z "${SIGN_REFRESH_TOKEN}" ]
then
echo "Using config from environment variables"
cat > dist/config.json <<EOF
{
"signRefreshToken": "$SIGN_REFRESH_TOKEN",
"signClientID": "$SIGN_CLIENT_ID",
"signClientSecret": "$SIGN_CLIENT_SECRET",
"githubKey": "$GITHUB_KEY",
"githubAppId": "$GITHUB_APP_ID"
}
EOF
else
echo "No config.json nor appropriate environment variables found, bombing 💥"
exit 1
fi
# if we are deploying to stage and staging github app creds are provided as env
# vars, overwrite creds in config
if [[ "$ENV" = "stage" ]] && [ ! -z "${GITHUB_STAGING_APP_ID}" ] && [ ! -z "${GITHUB_STAGING_KEY}" ]
then
echo "Overwriting GitHub App credentials to staging values provided to environment..."
node -e "cfg=require('./dist/config.json');cfg.githubKey='${GITHUB_STAGING_KEY}';cfg.githubAppId='${GITHUB_STAGING_APP_ID}';require('fs').writeFileSync('./dist/config.json',JSON.stringify(cfg, null, 2))"
fi
# set up action names based on environment
ACTION_NAME="cla-${ACTION}"
if [[ "$ENV" = "stage" ]]
then
ACTION_NAME="cla-${ACTION}-stage"
elif [[ "$ENV" = "production" ]]
then
ACTION_NAME="cla-${ACTION}"
fi
echo "Environment assumed to be ${ENV} and deployed action name will be ${ACTION_NAME}"
WSK="wsk"
if [ -e wsk ]
then
WSK="./wsk"
fi
echo "wsk binary used is ${WSK}"
# get files for deployed action ready
pushd $ACTION
npm install
popd
cp -r "${ACTION}/${ACTION}.js" "${ACTION}/node_modules" "${ACTION}/package.json" dist/.
# replace having the action load utils from the root of repo dir and instead use
# flat directory structure of the deployed action
sed -i.bak 's/\.\.\/utils\.js/\.\/utils\.js/' "dist/${ACTION}.js"
cp utils.js dist/.
# set the correct action name which may differ based on $ENV
if [[ $ENV = "stage" ]]
then
echo "Setting action names to -stage in utils.js..."
sed -i.bak "s/\(cla-[a-z]*\)/\1-stage/" dist/utils.js
fi
rm dist/*.bak
pushd dist
echo "dist/ content listing:"
ls -al
echo "Zipping dist/..."
zip -q -r "${ACTION}.zip" "${ACTION}.js" utils.js config.json package.json node_modules
popd
echo "Deploying ${ACTION_NAME}..."
if [ -e ~/.wskprops ]
then
$WSK action update "${ACTION_NAME}" --kind nodejs:10 "dist/${ACTION}.zip" --web true
else
echo "Setting runtime host and auth properties..."
$WSK property set --apihost adobeioruntime.net --auth "${ADOBE_RUNTIME_AUTH}"
$WSK action update "${ACTION_NAME}" --kind nodejs:10 "dist/${ACTION}.zip" --web true --apihost adobeioruntime.net --auth "${ADOBE_RUNTIME_AUTH}"
fi
echo "🌈✅"