Add argument parsing and usage
[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
22 -s Dry run (simulate)
23 -h Help
24EOF
25 exit 1
26}
27
64e09ea0
SB
28declare -a deps=(gpg deb-s3)
29
30for dep in ${deps[*]}
31do
32 [[ ! -f `which $dep` ]] && {
33 die "You need to install: $dep"
34 }
35done
e9a368ec 36
1b0f1b1b
SB
37while getopts ":b:hs" opt; do
38 case ${opt} in
39 b ) BUCKET=${OPTARG}
40 ;;
41 h ) usage
42 ;;
43 s ) DRY_RUN="echo "
44 ;;
45 \?) echo "Invalid Option: -${OPTARG}" 1>&2; exit 1
46 ;;
47 esac
48done
49
d9b1e27d
SB
50COMMIT=`(cd docker-gc && git rev-parse --short HEAD)`
51VERSION="2:`cat ${PWD}/docker-gc/version.txt`~${COMMIT}"
e9a368ec
SB
52TAG="gonitro/docker-gc-build:${COMMIT}"
53AWS_REGION=us-west-2
1b0f1b1b
SB
54BUCKET=${BUCKET:-nitro-apt-repo}
55DRY_RUN=${DRY_RUN:-}
24f134a7 56NITRO_GPG_KEY=`gpg --batch --search-keys --with-colons infra-guild@gonitro.com 2>&1| sed -E -n 's/^pub:.*(........):.*:.*:.*::/\1/p'`
e9a368ec 57
d9b1e27d
SB
58printf "[+] Using GPG %s for package signature\n" ${NITRO_GPG_KEY}
59
e9a368ec
SB
60$DRY_RUN docker build \
61 -t ${TAG} \
62 --build-arg VERSION=${VERSION} \
63 --build-arg AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
64 --build-arg AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
65 -f ./Dockerfile .
66
67$DRY_RUN docker run -v /tmp/:/tmp ${TAG} /bin/bash -c 'cp /docker-gc*.deb /tmp'
68
d9b1e27d
SB
69package=`ls /tmp/*.deb || :`
70printf "[+] Debian Package generated into '%s'\n" ${package}
e9a368ec
SB
71
72$DRY_RUN deb-s3 upload \
73 --access-key-id=${AWS_ACCESS_KEY_ID} \
74 --secret-access-key=${AWS_SECRET_ACCESS_KEY} \
75 --s3-region=${AWS_REGION} \
76 --bucket=${BUCKET} \
77 --sign=${NITRO_GPG_KEY} ${package} || exit 1
d9b1e27d 78printf "[+] Successfully uploaded package into %s\n" ${BUCKET}
e9a368ec
SB
79
80exit 0