Handle dependencies using a loop
[docker-gc-build/.git] / release.sh
1 #!/bin/bash
2
3 set -o errexit
4 set -o nounset
5 set -o pipefail
6
7 die() {
8     echo "$1" >&2
9     exit 2
10 }
11
12 declare -a deps=(gpg deb-s3)
13
14 for dep in ${deps[*]}
15 do
16     [[ ! -f `which $dep` ]] && {
17         die "You need to install: $dep"
18     }
19 done
20
21 COMMIT=`(cd docker-gc && git rev-parse --short HEAD)`
22 VERSION="2:`cat ${PWD}/docker-gc/version.txt`~${COMMIT}"
23 TAG="gonitro/docker-gc-build:${COMMIT}"
24 AWS_REGION=us-west-2
25 BUCKET=nitro-apt-repo
26 NITRO_GPG_KEY=`gpg --batch --search-keys  --with-colons infra-guild@gonitro.com 2>&1| sed -E -n 's/^pub:.*(........):.*:.*:.*::/\1/p'`
27
28 printf  "[+] Using GPG %s for package signature\n" ${NITRO_GPG_KEY}
29
30 $DRY_RUN docker build \
31     -t ${TAG} \
32     --build-arg VERSION=${VERSION} \
33     --build-arg AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
34     --build-arg AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
35     -f ./Dockerfile .
36
37 $DRY_RUN docker run -v /tmp/:/tmp ${TAG} /bin/bash -c 'cp /docker-gc*.deb /tmp'
38
39 package=`ls /tmp/*.deb || :`
40 printf "[+] Debian Package generated into '%s'\n" ${package}
41
42 $DRY_RUN deb-s3 upload \
43     --access-key-id=${AWS_ACCESS_KEY_ID} \
44     --secret-access-key=${AWS_SECRET_ACCESS_KEY} \
45     --s3-region=${AWS_REGION} \
46     --bucket=${BUCKET} \
47     --sign=${NITRO_GPG_KEY} ${package} || exit 1
48 printf "[+] Successfully uploaded package into %s\n" ${BUCKET}
49
50 exit 0