-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgcp_upload.sh
More file actions
executable file
·48 lines (39 loc) · 1.42 KB
/
gcp_upload.sh
File metadata and controls
executable file
·48 lines (39 loc) · 1.42 KB
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
#!/bin/bash
set -euo pipefail
set -x
service=$1
version=$2
bucket=$3
# accept an argument or use the default to "gcp raw"
build_types=(gcp raw)
gitsha=$(git rev-parse --short HEAD)
if [ -z "$service" ] || [ -z "$version" ]; then
echo "Remember to log into gcloud before running this script."
echo "Usage: ./gcp_upload.sh [DIBBS_SERVICE] [DIBBS_VERSION] [BUCKET_NAME]"
echo "Example: ./gcp_upload.sh dibbs-ecr-viewer 1.0.0 dibbs-vm-images"
echo "Example: ./gcp_upload.sh dibbs-query-connector 1.0.0 dibbs-vm-images"
exit 1
fi
# Create a loop for gcp and raw
for build_type in "${build_types[@]}"; do
if [ -d "$service/packer/build/$service-$build_type-$version-$gitsha" ]; then
cd $service/packer/build/$service-$build_type-$version-$gitsha || exit
echo "Build directory for that version exists, continuing with conversion."
else
echo "Build directory for that version does not exist."
exit 1
fi
rm disk.raw || true
rm ubuntu-2404-$service-$build_type-$version-$gitsha.tar.gz || true
# create raw
cp ubuntu-2404-$service-$build_type-$version-$gitsha.raw disk.raw
# compress raw
if [[ "$OSTYPE" == "darwin"* ]]; then
gtar -czvf ubuntu-2404-$service-$build_type-$version-$gitsha.tar.gz disk.raw
else
tar -czvf ubuntu-2404-$service-$build_type-$version-$gitsha.tar.gz disk.raw
fi
# upload to gcs
gsutil cp ubuntu-2404-$service-$build_type-$version-$gitsha.tar.gz gs://$bucket
cd - || exit
done