forked from orange-cloudfoundry/k3s-boshrelease
-
Notifications
You must be signed in to change notification settings - Fork 1
/
addblob.sh
executable file
·60 lines (48 loc) · 1.76 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
#!/bin/bash
set -x
set -e # exit on non-zero status
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
}
addBlobOnChecksumChange src/github.com/k3s-io/k3s/k3s k3s/k3s
addBlobOnChecksumChange src/github.com/k3s-io/k3s/k3s-airgap-images-amd64.tar.gz k3s-images/k3s-airgap-images-amd64.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 [ "${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