-
Notifications
You must be signed in to change notification settings - Fork 688
/
push_manifests.sh
executable file
·77 lines (64 loc) · 2.09 KB
/
push_manifests.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
#!/bin/bash
set -e -o pipefail
RED=$'\033[1;31m'
END=$'\033[0m'
BLOCK=$'\033[1;47m'
abort() {
log "${RED}FATAL: $1${END}"
exit 1
}
log() { >&2 printf '%s>>>%s %s\n' "$BLOCK" "$END" "$*"; }
errusage() {
printf >&2 'Usage: %s DIR\n' "$0"
if [[ $# -gt 0 ]]; then
local msg
# shellcheck disable=SC2059
printf -v msg "$@"
printf >&2 '%s: error: %s\n' "$0" "$msg"
fi
exit 2
}
[[ $# == 1 ]] || errusage 'wrong number of args: %d' $#
[[ -d "$1" ]] || errusage 'DIR is not a directory: %q' "$dir"
[[ -n "$AWS_ACCESS_KEY_ID" ]] || errusage "AWS_ACCESS_KEY_ID is not set"
[[ -n "$AWS_SECRET_ACCESS_KEY" ]] || errusage "AWS_SECRET_ACCESS_KEY is not set"
[[ "${VERSION:-}" == v3.* ]] || errusage "VERSION must be set to a 'v3.*' string"
dir=$1
while [[ "$dir" == */ ]]; do
dir=${dir%/}
done
version=${VERSION#v}
log "Publishing manifest version ${version}"
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-ea)?$ ]] ; then
# if this is a stable version, working directory must be clean
# otherwise this is an rc or test version and we don't care
if [ -n "$(git status --porcelain)" ] ; then
abort "working tree is dirty, aborting"
fi
elif [[ "${BUMP_STABLE}" ]] ; then
# if this isn't an X.Y.Z version, don't let allow bumping stable
abort "Cannot bump stable unless this is an X.Y.Z tag"
fi
if [ -z "$AWS_S3_BUCKET" ] ; then
AWS_S3_BUCKET=datawire-static-files
fi
echo "$version" > stable.txt
aws s3api put-object \
--bucket "$AWS_S3_BUCKET" \
--key "yaml/emissary/${version}"
find "$dir" -type f -name '*.yaml' -print0 | while read -r -d '' file; do
aws s3api put-object \
--bucket "$AWS_S3_BUCKET" \
--key "yaml/emissary/${version}/${file##*/}" \
--body "$file"
echo "... yaml/emissary/${version}/${file##*/} pushed"
done
if [[ "${BUMP_STABLE}" ]] ; then
log "Bumping stable version for yaml/emissary"
aws s3api put-object \
--bucket "$AWS_S3_BUCKET" \
--key "yaml/emissary/stable.txt" \
--body stable.txt
fi
rm stable.txt
exit 0