forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-s3.sh
executable file
·141 lines (120 loc) · 5.13 KB
/
release-s3.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
set -euo pipefail
# release-s3.sh
#
# SUMMARY
#
# Uploads archives and packages to S3
CHANNEL="${CHANNEL:-"$(scripts/release-channel.sh)"}"
VERSION="${VERSION:-"$(scripts/version.sh)"}"
DATE="${DATE:-"$(date -u +%Y-%m-%d)"}"
VERIFY_TIMEOUT="${VERIFY_TIMEOUT:-"30"}" # seconds
VERIFY_RETRIES="${VERIFY_RETRIES:-"2"}"
#
# Setup
#
td="$(mktemp -d)"
cp -av "target/artifacts/." "$td"
ls "$td"
td_nightly="$(mktemp -d)"
cp -av "target/artifacts/." "$td_nightly"
for f in "$td_nightly"/*; do
a="$(echo "$f" | sed -r -e "s/$VERSION/nightly/")"
mv "$f" "$a"
done
ls "$td_nightly"
td_latest="$(mktemp -d)"
cp -av "target/artifacts/." "$td_latest"
for f in "$td_latest"/*; do
a="$(echo "$f" | sed -r -e "s/$VERSION/latest/")"
mv "$f" "$a"
done
ls "$td_latest"
#
# A helper function for verifying a published artifact.
#
verify_artifact() {
local URL="$1"
local FILENAME="$2"
echo "Verifying $URL"
cmp <(wget -qO- --retry-on-http-error=404 --wait 10 --tries "$VERIFY_RETRIES" "$URL") "$FILENAME"
}
#
# Upload
#
if [[ "$CHANNEL" == "nightly" ]]; then
# Add nightly files with the $DATE for posterity
echo "Uploading all artifacts to s3://packages.timber.io/vector/nightly/$DATE"
aws s3 cp "$td_nightly" "s3://packages.timber.io/vector/nightly/$DATE" --recursive --sse --acl public-read
echo "Uploaded archives"
# Add "latest" nightly files
echo "Uploading all artifacts to s3://packages.timber.io/vector/nightly/latest"
aws s3 rm --recursive "s3://packages.timber.io/vector/nightly/latest"
aws s3 cp "$td_nightly" "s3://packages.timber.io/vector/nightly/latest" --recursive --sse --acl public-read
echo "Uploaded archives"
echo "Redirecting old artifact names"
find "$td_nightly" -maxdepth 1 -type f -print0 | while read -r -d $'\0' file ; do
file=$(basename "$file")
# vector-nightly-amd64.deb -> vector-amd64.deb
echo -n "" | aws s3 cp - "s3://packages.timber.io/vector/nightly/$DATE/${file/-nightly/}" --website-redirect "/vector/nightly/$DATE/$file" --acl public-read
echo -n "" | aws s3 cp - "s3://packages.timber.io/vector/nightly/latest/${file/-nightly/}" --website-redirect "/vector/nightly/latest/$file" --acl public-read
done
echo "Redirected old artifact names"
# Verify that the files exist and can be downloaded
echo "Waiting for $VERIFY_TIMEOUT seconds before running the verifications"
sleep "$VERIFY_TIMEOUT"
verify_artifact \
"https://packages.timber.io/vector/nightly/$DATE/vector-nightly-x86_64-unknown-linux-musl.tar.gz" \
"$td_nightly/vector-nightly-x86_64-unknown-linux-musl.tar.gz"
verify_artifact \
"https://packages.timber.io/vector/nightly/latest/vector-nightly-x86_64-unknown-linux-musl.tar.gz" \
"$td_nightly/vector-nightly-x86_64-unknown-linux-musl.tar.gz"
verify_artifact \
"https://packages.timber.io/vector/nightly/latest/vector-nightly-x86_64-unknown-linux-gnu.tar.gz" \
"$td_nightly/vector-nightly-x86_64-unknown-linux-gnu.tar.gz"
elif [[ "$CHANNEL" == "latest" ]]; then
VERSION_EXACT="$VERSION"
# shellcheck disable=SC2001
VERSION_MINOR_X="$(echo "$VERSION" | sed 's/\.[0-9]*$/.X/g')"
# shellcheck disable=SC2001
VERSION_MAJOR_X="$(echo "$VERSION" | sed 's/\.[0-9]*\.[0-9]*$/.X/g')"
for i in "$VERSION_EXACT" "$VERSION_MINOR_X" "$VERSION_MAJOR_X"; do
# Upload the specific version
echo "Uploading artifacts to s3://packages.timber.io/vector/$i/"
aws s3 cp "$td" "s3://packages.timber.io/vector/$i/" --recursive --sse --acl public-read
done
for i in "$VERSION_EXACT" "$VERSION_MINOR_X" "$VERSION_MAJOR_X"; do
# Delete anything that isn't the current version
echo "Deleting old artifacts from s3://packages.timber.io/vector/$i/"
aws s3 rm "s3://packages.timber.io/vector/$i/" --exclude "*$VERSION_EXACT*"
echo "Deleted old versioned artifacts"
done
echo "Uploading artifacts to s3://packages.timber.io/vector/latest/"
aws s3 cp "$td_latest" "s3://packages.timber.io/vector/latest/" --recursive --sse --acl public-read
echo "Uploaded latest archives"
echo "Redirecting old artifact names"
find "$td" -maxdepth 1 -type f -print0 | while read -r -d $'\0' file ; do
file=$(basename "$file")
# vector-$version-amd64.deb -> vector-amd64.deb
echo -n "" | aws s3 cp - "s3://packages.timber.io/vector/$i/${file/-$i/}" --website-redirect "/vector/$i/$file" --acl public-read
echo -n "" | aws s3 cp - "s3://packages.timber.io/vector/latest/${file/-$i/}" --website-redirect "/vector/latest/$file" --acl public-read
done
echo "Redirected old artifact names"
# Verify that the files exist and can be downloaded
sleep "$VERIFY_TIMEOUT"
echo "Waiting for $VERIFY_TIMEOUT seconds before running the verifications"
for i in "$VERSION_EXACT" "$VERSION_MINOR_X" "$VERSION_MAJOR_X"; do
verify_artifact \
"https://packages.timber.io/vector/$i/vector-$VERSION-x86_64-unknown-linux-musl.tar.gz" \
"$td/vector-$VERSION-x86_64-unknown-linux-musl.tar.gz"
done
verify_artifact \
"https://packages.timber.io/vector/latest/vector-latest-x86_64-unknown-linux-gnu.tar.gz" \
"$td_latest/vector-latest-x86_64-unknown-linux-gnu.tar.gz"
fi
#
# Cleanup
#
rm -rf "$td"
rm -rf "$td_nightly"
rm -rf "$td_latest"