-
Notifications
You must be signed in to change notification settings - Fork 1
/
addblob.sh
executable file
·69 lines (56 loc) · 2.1 KB
/
addblob.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
#!/bin/bash
set -x
set -e # exit on non-zero status
DEV_MODE="false"
if [ "$1" = "dev-mode" ];then
DEV_MODE="true"
fi
echo "Current blobs"
bosh blobs
NEW_BLOBS_WERE_ADDED="false"
# params
# $1: src
# $2: target
function addBlobOnChecksumChange() {
src="$1"
target="$2"
blob_checksum=$(cat config/blobs.yml | yq .'"'${target}'"'.sha)
blob_object_id=$(cat config/blobs.yml | yq .'"'${target}'"'.object_id) # With dev release, blobs are not publish yet, so we need to add it again
src_checksum=$(cat "${src}" | sha256sum | cut -d " " -f1)
if [ "${blob_checksum}" != "sha256:${src_checksum}" ] || [ "$blob_object_id" = "null" ]; then
bosh add-blob ${src} ${target}
NEW_BLOBS_WERE_ADDED="true"
else
echo "skipping blob creation for ${target} with existing checksum: ${src_checksum}"
fi
}
source ./set_version.sh
addBlobOnChecksumChange set_version.sh set_version.sh
addBlobOnChecksumChange src/github.com/helm/helm/linux-amd64/helm helm/helm
addBlobOnChecksumChange src/github.com/jqlang/jq/jq-linux64 jq/jq-linux64
addBlobOnChecksumChange src/github.com/kubernetes/kubectl/kubectl kubectl/kubectl
addBlobOnChecksumChange src/github.com/kubernetes-sigs/kustomize/kustomize_*_linux_amd64.tar.gz kustomize/kustomize.tar.gz
# Inspired by https://github.com/orange-cloudfoundry/bosh-release-action/blob/8732ff085712d9980fc66e50892cb9c3d7a3f884/entrypoint.sh#L48-L58
function configureS3BlobStore() {
if [ ! -z "${AWS_BOSH_ACCES_KEY_ID}" ]; then
cat - > config/private.yml <<EOS
---
blobstore:
options:
access_key_id: ${AWS_BOSH_ACCES_KEY_ID}
secret_access_key: ${AWS_BOSH_SECRET_ACCES_KEY}
EOS
else
echo "::warning::AWS_BOSH_ACCES_KEY_ID not set, skipping config/private.yml"
fi
}
echo "Configuring S3 blobstore systematically: S3 credential are required during the bosh create-release to download the blobs"
configureS3BlobStore
if [[ "$DEV_MODE" == "false" && "${NEW_BLOBS_WERE_ADDED}" == "true" ]] ; then
echo "Current blobs before upload"
bosh blobs
# See https://bosh.io/docs/release-blobs/#saving-blobs
bosh upload-blobs
echo "Current blobs after upload"
bosh blobs
fi