forked from spinnaker/spin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·102 lines (78 loc) · 2.17 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
#!/usr/bin/env bash
set -e
set -x
PROD_SPIN_GCS_BUCKET_PATH="gs://spinnaker-artifacts/spin"
KEY_FILE=
SPIN_GCS_BUCKET_PATH=
VERSION=
function process_args() {
while [[ $# > 0 ]]
do
local key="$1"
shift
case $key in
--gcs_bucket_path)
SPIN_GCS_BUCKET_PATH="$1"
shift
;;
--key_file)
KEY_FILE="$1"
shift
;;
--version)
VERSION="$1"
shift
;;
--help|-help|-h)
print_usage
exit 0
;;
*)
echo "ERROR: Unknown argument '$key'"
exit -1
esac
done
}
function print_usage() {
cat <<EOF
usage: $0 --key_file <key file path> --version <version>
[--gcs_bucket_path <path>]
--gcs_bucket_path <arg> Path to the GCS bucket to write the `spin` binaries to.
--key_file <arg> Service account JSON key file to use to upload `spin`
binaries.
--version <arg> Version to tag the `spin` binaries with.
EOF
}
process_args "$@"
CURR_DIR=$(pwd)
# Google cloud sdk installation from
# https://cloud.google.com/sdk/docs/downloads-interactive.
if ! command -v gcloud > /dev/null; then
curl https://sdk.cloud.google.com | bash -s -- --disable-prompts --install-dir=$CURR_DIR
fi
export PATH=$PATH:$CURR_DIR/google-cloud-sdk/bin
if [ -z "$KEY_FILE" ]; then
echo "No key file specified with --key_file, exiting"
exit 1
fi
gcloud auth activate-service-account --key-file ${KEY_FILE}
gcloud components install gsutil -q
if [ -z "$VERSION" ]; then
echo -e "No version to release specified with --version, exiting"
exit 1
fi
if [ -z "$SPIN_GCS_BUCKET_PATH" ]; then
echo "No GCS bucket specified using ${PROD_SPIN_GCS_BUCKET_PATH}, using gs://spinnaker-artifacts/spin"
SPIN_GCS_BUCKET_PATH=$PROD_SPIN_GCS_BUCKET_PATH
fi
for elem in darwin,amd64 linux,amd64; do
IFS="," read os arch <<< "${elem}"
echo "Building for $os $arch"
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build .
path=${SPIN_GCS_BUCKET_PATH}/${VERSION}/${os}/${arch}/
echo "Copying to $path"
gsutil cp spin $path
rm spin
done
echo $VERSION > latest
gsutil cp latest ${SPIN_GCS_BUCKET_PATH}/