Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup_osie: Add --retry to curl, exit if it fails #533

Closed
wants to merge 3 commits into from
Closed
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
67 changes: 39 additions & 28 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,39 +247,50 @@ EOF
)

setup_osie() (
mkdir -p "$STATEDIR/webroot"

local osie_current=$STATEDIR/webroot/misc/osie/current
local tink_workflow=$STATEDIR/webroot/workflow/
if [ ! -d "$osie_current" ] || [ ! -d "$tink_workflow" ]; then
mkdir -p "$osie_current"
mkdir -p "$tink_workflow"
pushd "$SCRATCH"

if [ -z "${TB_OSIE_TAR:-}" ]; then
local OSIE_DOWNLOAD_LINK=${OSIE_DOWNLOAD_LINK:-"https://tinkerbell-oss.s3.amazonaws.com/osie-uploads/latest.tar.gz"} # If variable not set or null, use default.
curl -fsSL "${OSIE_DOWNLOAD_LINK}" -o ./osie.tar.gz
tar -zxf osie.tar.gz
else
if [ ! -f "$TB_OSIE_TAR" ]; then
echo "$ERR osie tar not found in the given location $TB_OSIE_TAR"
exit 1
fi
echo "$INFO extracting osie tar"
tar -zxf "$TB_OSIE_TAR"

if [ -d "$osie_current" ] && [ -d "$tink_workflow" ]; then
Copy link
Contributor

@mmlb mmlb Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably check for

Suggested change
if [ -d "$osie_current" ] && [ -d "$tink_workflow" ]; then
if [ -f "$osie_current/vmlinuz-x86_64" ] && [ -f "$tink_workflow/workflow-helper.sh" ]; then

instead. Otherwise if curl fails then a re-run will skip curl right? Because you've mkdir -p these dirs right after this branch

echo "$INFO found existing osie files in ${osie_current} and ${tink_workflow}: skipping osie setup."
return
fi

mkdir -p "$osie_current" "$tink_workflow"
pushd "$SCRATCH"

if [ -z "${TB_OSIE_TAR:-}" ]; then
local url=${OSIE_DOWNLOAD_LINK:-"https://tinkerbell-oss.s3.amazonaws.com/osie-uploads/latest.tar.gz"}
TB_OSIE_TAR="osie.tar.gz"

echo "$INFO Downloading ${url} (this may take 5-15 minutes) ..."

if ! curl --fail \
--location \
--retry 3 \
--show-error \
--silent \
"${url}" -o "${TB_OSIE_TAR}"; then
echo "$ERR Failed to download ${url} - Download it and set $TB_OSIE_TAR to continue"
exit 1
fi
fi

if pushd osie*/; then
if mv workflow-helper.sh workflow-helper-rc "$tink_workflow"; then
cp -r ./* "$osie_current"
else
echo "$ERR failed to move 'workflow-helper.sh' and 'workflow-helper-rc'"
exit 1
fi
popd
if [ ! -f "$TB_OSIE_TAR" ]; then
echo "$ERR osie tar not found in the given location $TB_OSIE_TAR"
exit 1
fi

echo "$INFO extracting osie tar at $TB_OSIE_TAR"
tar -zxf "$TB_OSIE_TAR"

if pushd osie*/; then
if mv workflow-helper.sh workflow-helper-rc "$tink_workflow"; then
cp -r ./* "$osie_current"
else
echo "$ERR failed to move 'workflow-helper.sh' and 'workflow-helper-rc'"
exit 1
fi
else
echo "$INFO found existing osie files, skipping osie setup"
popd
fi
Comment on lines +284 to 294
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should actually be:

Suggested change
tar -zxf "$TB_OSIE_TAR"
if pushd osie*/; then
if mv workflow-helper.sh workflow-helper-rc "$tink_workflow"; then
cp -r ./* "$osie_current"
else
echo "$ERR failed to move 'workflow-helper.sh' and 'workflow-helper-rc'"
exit 1
fi
else
echo "$INFO found existing osie files, skipping osie setup"
popd
fi
if ! tar -zxf "$TB_OSIE_TAR" -C "$osie_current"; then
echo "$ERR failed to extract osie tarball";
exit 1;
fi
if ! mv/cp "$osie_current/workflow-helper.sh" "$osie_current/workflow-helper-rc" "$tink_workflow"; then
echo "$ERR failed to move 'workflow-helper.sh' and 'workflow-helper-rc'";
exit 1;
fi

no need to change dir, ..., mv .* when tar can do what we want right? This way we don't have to deal with pushd errors (currently ignore, which tbf shouldn't ever really happen) but also doesn't keep 3 copies of osie around (the tarball, one in $cwd, and the one in $osie_current)... just 2 copies.

)

Expand Down