Skip to content

Commit dd77401

Browse files
Iryna Shustavapivotal
authored andcommitted
Enable uploading stemcells from ops files [#154735316]
1 parent 0d3c04c commit dd77401

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

bosh-upload-stemcell-from-cf-deployment/task

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,13 @@ check_upload_stemcell_params() {
2727
upload_stemcell() {
2828
# Read potentially variable stemcell paramaters out of cf-deployment with bosh
2929
local os
30-
os=$(bosh interpolate --path=/stemcells/alias=default/os cf-deployment/${MANIFEST_FILE})
30+
os=$1
3131
local version
32-
version=$(bosh interpolate --path=/stemcells/alias=default/version cf-deployment/${MANIFEST_FILE})
32+
version=$2
3333

3434
# Hardcode a couple of stable stemcell paramaters
3535
local stemcells_url
3636
stemcells_url="https://bosh.io/d/stemcells"
37-
local bosh_agent
38-
bosh_agent="go_agent"
39-
40-
# Ask bosh if it already has our OS / version stemcell combination
41-
# As of this writing, the new bosh cli doesn't have --skip-if-exists
42-
set +e
43-
local existing_stemcell
44-
existing_stemcell=$(bosh stemcells | grep "${os}" | awk '{print $2}' | tr -d "\*" | grep ^"${version}"$ )
45-
set -e
4637

4738
local stemcell_name
4839

@@ -60,7 +51,7 @@ upload_stemcell() {
6051
stemcell_name="bosh-azure-hyperv"
6152
fi
6253

63-
stemcell_name="${stemcell_name}-${os}-${bosh_agent}"
54+
stemcell_name="${stemcell_name}-${os}-go_agent"
6455
if [ "$version" = "latest" ]; then
6556
full_stemcell_url="${stemcells_url}/${stemcell_name}"
6657
else
@@ -87,13 +78,32 @@ upload_stemcell() {
8778
-n \
8879
upload-stemcell \
8980
"${full_stemcell_url}"
90-
set -x
81+
}
82+
83+
function upload_stemcells() {
84+
local arguments=''
85+
for op in ${OPS_FILES_WITH_STEMCELLS}
86+
do
87+
arguments="${arguments} -o cf-deployment/${op}"
88+
done
89+
90+
bosh interpolate ${arguments} cf-deployment/${MANIFEST_FILE} > /tmp/cf.yml
91+
92+
local stemcells_json=$(ruby -rjson -ryaml -e "puts YAML.load_file('/tmp/cf.yml').to_json" | jq .stemcells)
93+
local size=$(echo ${stemcells_json} | jq 'length')
94+
95+
for i in `seq 0 $((size - 1))`
96+
do
97+
local os=$(echo ${stemcells_json} | jq -r .[$i].os)
98+
local version=$(echo ${stemcells_json} | jq -r .[$i].version)
99+
upload_stemcell ${os} ${version}
100+
done
91101
}
92102

93103
main() {
94104
check_upload_stemcell_params
95-
setup_bosh_env_vars 'bbl-state'
96-
upload_stemcell
105+
setup_bosh_env_vars
106+
upload_stemcells
97107
}
98108

99109
main

bosh-upload-stemcell-from-cf-deployment/task.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ params:
3131
# - Required
3232
# - Filepath to the manifest file within the cf-deployment resource
3333
# - The path is relative to root of the `cf-deployment` input
34+
35+
OPS_FILES_WITH_STEMCELLS:
36+
# - Optional
37+
# - List of operations files that contain additional stemcells to be uploaded
38+
# - Quoted and space-separated
39+
# - Paths are relative to root of the `cf-deployment` input

0 commit comments

Comments
 (0)