Allow to just build the artifact without upload using -n
[docker-gc-build/.git] / release.sh
CommitLineData
e9a368ec
SB
1#!/bin/bash
2
64e09ea0
SB
3set -o errexit
4set -o nounset
5set -o pipefail
e9a368ec 6
64e09ea0
SB
7die() {
8 echo "$1" >&2
e9a368ec
SB
9 exit 2
10}
11
1b0f1b1b
SB
12usage() {
13 cat <<EOF
14 ${0} [options] [arguments]
15
16 Arguments:
17
18 -b Set the S3 bucket name
19
20 Options:
21
1b0f1b1b 22 -h Help
8931bb2d
SB
23 -s Dry run (simulate)
24 -n Does not upload artifact (just build)
1b0f1b1b
SB
25EOF
26 exit 1
27}
28
64e09ea0
SB
29declare -a deps=(gpg deb-s3)
30
31for dep in ${deps[*]}
32do
da6d1381 33 [[ ! -f $(command -v "$dep") ]] && {
64e09ea0
SB
34 die "You need to install: $dep"
35 }
36done
e9a368ec 37
8931bb2d 38while getopts ":b:hsu" opt; do
1b0f1b1b
SB
39 case ${opt} in
40 b ) BUCKET=${OPTARG}
41 ;;
42 h ) usage
43 ;;
44 s ) DRY_RUN="echo "
45 ;;
8931bb2d
SB
46 u ) NO_UPLOAD=1
47 ;;
1b0f1b1b
SB
48 \?) echo "Invalid Option: -${OPTARG}" 1>&2; exit 1
49 ;;
50 esac
51done
52
da6d1381
SB
53COMMIT=$( (cd docker-gc && git rev-parse --short HEAD) )
54VERSION="2:$(cat "${PWD}"/docker-gc/version.txt)~${COMMIT}"
e9a368ec
SB
55TAG="gonitro/docker-gc-build:${COMMIT}"
56AWS_REGION=us-west-2
1b0f1b1b
SB
57BUCKET=${BUCKET:-nitro-apt-repo}
58DRY_RUN=${DRY_RUN:-}
8931bb2d 59NO_UPLOAD=${NO_UPLOAD:-}
da6d1381
SB
60KEYSERVER=${KEYSERVER:-pgpkeys.eu}
61NITRO_GPG_KEY=$(gpg \
62 --keyserver "${KEYSERVER}" \
63 --batch \
64 --search-keys \
65 --with-colons infra-guild@gonitro.com 2>&1| sed -E -n 's/^pub:.*(........):.*:.*:.*::/\1/p')
e9a368ec 66
da6d1381 67printf "[+] Using GPG %s for package signature\n" "${NITRO_GPG_KEY}"
d9b1e27d 68
e9a368ec 69$DRY_RUN docker build \
da6d1381
SB
70 -t "${TAG}" \
71 --build-arg VERSION="${VERSION}" \
72 --build-arg AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
73 --build-arg AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
e9a368ec
SB
74 -f ./Dockerfile .
75
da6d1381 76$DRY_RUN docker run -v /tmp/:/tmp "${TAG}" /bin/bash -c 'cp /docker-gc*.deb /tmp'
e9a368ec 77
da6d1381
SB
78package=$(ls /tmp/*.deb || :)
79printf "[+] Debian Package generated into '%s'\n" "${package}"
e9a368ec 80
8931bb2d 81if [[ -z ${NO_UPLOAD} ]]; then
e9a368ec 82$DRY_RUN deb-s3 upload \
8931bb2d
SB
83 --access-key-id="${AWS_ACCESS_KEY_ID}" \
84 --secret-access-key="${AWS_SECRET_ACCESS_KEY}" \
85 --s3-region="${AWS_REGION}" \
86 --bucket="${BUCKET}" \
87 --sign="${NITRO_GPG_KEY}" "${package}" || exit 1
88printf "[+] Successfully uploaded package into '%s'\n" "${BUCKET}"
89fi
e9a368ec
SB
90
91exit 0