-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·119 lines (94 loc) · 2.54 KB
/
release.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
#!/bin/bash
set -o nounset
set -o pipefail
die() {
echo "$1" >&2
exit 2
}
usage() {
cat <<EOF
${0##*/} [options] [arguments]
Arguments:
-b Set the S3 bucket name (default: nitro-apt-repo)
-r Set AWS region (default: us-west-2)
Options:
-h Help
-s Dry run (simulate)
-n Does not upload artifact (just build)
EOF
exit 1
}
do_prereq() {
declare -a deps=(gpg deb-s3)
for dep in ${deps[*]}
do
[[ ! -f $(command -v "$dep") ]] && {
die "You need to install: $dep"
}
done
}
parse_args() {
local OPTIND
while getopts ":b:hsnr:" opt; do
case ${opt} in
b) BUCKET=${OPTARG}
;;
h) usage
;;
s) DRY_RUN="echo "
;;
n) NO_UPLOAD=1
;;
r) AWS_REGION=${OPTARG}
;;
\?) echo "Invalid Option: -${OPTARG}" 1>&2; exit 1
;;
esac
done
}
do_build() {
$DRY_RUN docker build \
-t "${TAG}" \
--build-arg VERSION="${VERSION}" \
--build-arg AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
--build-arg AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
-f ./Dockerfile .
$DRY_RUN docker run -v /tmp/:/tmp "${TAG}" /bin/bash -c 'cp /docker-gc*.deb /tmp'
package=$(ls /tmp/*.deb || :)
printf "[+] Debian Package generated into '%s'\n" "${package}"
}
do_upload() {
printf "[+] Using GPG %s for package signature\n" "${NITRO_GPG_KEY}"
$DRY_RUN deb-s3 upload \
--access-key-id="${AWS_ACCESS_KEY_ID}" \
--secret-access-key="${AWS_SECRET_ACCESS_KEY}" \
--s3-region="${AWS_REGION}" \
--bucket="${BUCKET}" \
--sign="${NITRO_GPG_KEY}" "${package}" || exit 1
printf "[+] Successfully uploaded package into '%s'\n" "${BUCKET}"
}
main() {
COMMIT=$( (cd docker-gc && git rev-parse --short HEAD) )
VERSION="2:$(cat "${PWD}"/docker-gc/version.txt)~${COMMIT}"
TAG="gonitro/docker-gc-build:${COMMIT}"
AWS_REGION=${AWS_REGION:-us-west-2}
BUCKET=${BUCKET:-nitro-apt-repo}
DRY_RUN=${DRY_RUN:-}
NO_UPLOAD=${NO_UPLOAD:-}
KEYSERVER=${KEYSERVER:-pgpkeys.eu}
NITRO_GPG_KEY=$(gpg \
--keyserver "${KEYSERVER}" \
--batch \
--search-keys \
--with-colons [email protected] 2>&1| sed -E -n 's/^pub:.*(........):.*:.*:.*::/\1/p')
do_prereq
parse_args "$@"
do_build
if [[ -z ${NO_UPLOAD} ]]; then
do_upload
fi
exit 0
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi