-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·53 lines (42 loc) · 1.77 KB
/
deploy
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
#!/usr/bin/env sh
set -o nounset
set -o errexit
warn () { echo "$0:" "$@" >&2; }
die () { rc=$1; shift; echo "$0 ($rc):" "$@"; exit "$rc"; }
[ -z "$BEARER_TOKEN" ] && die 1 "Token \$BEARER_TOKEN undefined!";
[ -z "$SSH_DEPLOY_HOSTS" ] && die 1 "Deploy servers (\$SSH_DEPLOY_HOSTS) undefined!";
[ -z "$SSH_DEPLOY_USER" ] && die 1 "Deploy user (\$SSH_DEPLOY_USER) undefined!";
# absolute paths
workingDir=$(pwd)
targetDir="$workingDir/platforms/browser/www"
deployDir="$workingDir/deploy.d"
configDir="$workingDir/configs"
# Prepare different versions for different configs
# The following will create a directory structure like
# deploy/
# ├─ haus-X/
# └─ haus-Y/
# the content of which will then be deployed to the defined servers
mkdir "$deployDir"
for config in "$configDir"/*.config.dist.json; do
# set token in config
tempConfig="$(mktemp)"
jq ".api.authorization=\"Bearer $BEARER_TOKEN\"" "$config" > "$tempConfig" || die "Could not set \$BEARER_TOKEN in $config."
mv "$tempConfig" "$config"
# derive name of this deploy from config file name
deployName=$(echo "${config##*/}" | cut -d '.' -f 1) # haus-X.config.dist.json -> haus-X
# create subdirectory for this version and descend into it
deploySubDir="$deployDir/$deployName"
mkdir "$deploySubDir"
# copy files over
cp --recursive "$targetDir"/* "$deploySubDir"
# Change the base href of the index.html file
sed -i "s#<base href=\"/\" />#<base href=\"/$deployName/\"/>#g" "$deploySubDir/index.html" || die 1 "Could not change base href"
# finally copy corresponding config over
cp "$config" "$deploySubDir/assets/config.json"
done
# deploy to servers
cd "$deployDir"
for deployHost in $SSH_DEPLOY_HOSTS; do
tar cfz - ./* | ssh -i /root/.ssh/id_rsa "$SSH_DEPLOY_USER@$deployHost";
done