Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Download stemcell from bosh.io task fixes #241

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions tasks/download-boshio-stemcells/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,43 @@ set -eu
# limitations under the License.

function main() {
if [ -z "$API_TOKEN" ]; then abort "The required env var API_TOKEN was not set for pivnet"; fi

local cwd=$PWD
local download_dir="${cwd}/stemcells"
local diag_report="${cwd}/diagnostic-report/exported-diagnostic-report.json"

cp ${cwd}/pivnet-stemcells/* ${download_dir}
cp -a "${cwd}/pivnet-stemcells/." "${download_dir}"

# get the deduplicated stemcell filename for each deployed release (skipping p-bosh)
local bosh_io_stemcells=($( (jq --raw-output '.added_products.deployed[] | select (.name | contains("p-bosh") | not) | select (.stemcell | contains("ubuntu") | not) |.stemcell' | \
sort -u) < "$diag_report"))
if [ ${#bosh_io_stemcells[@]} -eq 0 ]; then
echo "No installed products found that require a ubuntu stemcell"
echo "No installed products found that require a non-ubuntu stemcell"
exit 0
fi

mkdir -p "${download_dir}"

# extract the stemcell version from the filename, e.g. 3312.21, and download the file from pivnet
# extract the stemcell version and type from the filename and download the stemcell from bosh.io
for stemcell in "${bosh_io_stemcells[@]}"; do

local version=$(echo "$stemcell" | grep -Eo "[0-9]+\.[0-9]+")
local stemcell_type=bosh-$(ruby -e "puts '$stemcell'.split('$version-')[1].split('.')[0]")
echo "${stemcell}"

if [[ $stemcell =~ ([0-9]+\.[0-9]+) ]]; then
local version="${BASH_REMATCH[1]}"
else
abort "Couldn't find a stemcell version"
fi

if [[ $stemcell =~ $version-(.+).tgz ]]; then
local stemcell_type="bosh-${BASH_REMATCH[1]}"
else
abort "Couldn't find a stemcell type"
fi

echo "${stemcell_type}"
echo "${version}"

curl -L -J -o ${download_dir}/${stemcell} https://bosh.io/d/stemcells/${stemcell_type}?v=${version}
wget -O "${download_dir}/${stemcell}" "https://bosh.io/d/stemcells/${stemcell_type}?v=${version}"
done
}

Expand Down
3 changes: 0 additions & 3 deletions tasks/download-boshio-stemcells/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ inputs:
outputs:
- name: stemcells

params:
API_TOKEN:

run:
path: pcf-pipelines/tasks/download-boshio-stemcells/task.sh