Skip to content

(CAT-2413) Defaults puppetcore agent version to newest if none given #798

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions tasks/install_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ if (($collection -like '*puppetcore*-nightly*') -And -Not ($PSBoundParameters.Co
$windows_source = 'https://nightlies.puppet.com/downloads'
} elseif (($collection -like '*puppetcore*') -And -Not ($PSBoundParameters.ContainsKey('windows_source'))) {
$windows_source = 'https://artifacts-puppetcore.puppet.com/v1/download'
# Puppetcore requires a version to be specified, so we will use the latest version if not specified.
# Or if the version is set to "latest".
if ($version -eq "" || !$version || $version -eq "latest") {
$response = Invoke-WebRequest -Uri "https://forgeapi.puppet.com/private/versions/puppet-agent" -UseBasicParsing
$jsonData = $response.Content | ConvertFrom-Json
$allVersions = $jsonData.PSObject.Properties.Name
$version8x = $allVersions | Where-Object { $_ -like "8.*" }
$version = $version8x | Sort-Object { [Version]$_ } | Select-Object -Last 1
}
}

if ($absolute_source) {
Expand Down
25 changes: 17 additions & 8 deletions tasks/install_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -830,24 +830,33 @@ case $platform in
"mac_os_x")
info "Mac platform! Lets get you a DMG..."
filetype="dmg"
if test "$version" = "latest"; then
filename="puppet-agent-latest.dmg"
else
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
fi

arch="x86_64"
if [[ $(uname -p) == "arm" ]]; then
arch="arm64"
fi
if [[ "$collection" =~ "puppetcore" ]]; then
# Puppetcore requires a version to be specified, so we will use the latest version if not specified.
# Or if the version is set to "latest".
if [[ -z "$version" || "$version" == "latest" ]]; then
version=$(curl -sL https://forgeapi.puppet.com/private/versions/puppet-agent | \
jq -r 'keys_unsorted |
map(select(startswith("8."))) |
max_by(split(".") | map(tonumber))')
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, there's no guarantee jq is installed on the system where we're trying to install the agent... Since this latest business is a hack for platforms without package managers, I'm thinking we should just fail if version is unset on Windows and macOS. That way the caller will know it needs to provide an explicit version. Then in CI, it should be easy to run curl | jq on an ubuntu worker and pass the version into the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is less of a priority on our end now that the nightly images are up for us to grab.
Was mainly continuing with this for the teams that don't want to use nightlies, but if they haven't commented about it yet then they either have their own solution or aren't running on Windows/Mac

Copy link
Member Author

Choose a reason for hiding this comment

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

Have opened a second PR which adds error messages: #801

dots=$(echo "${version}" | grep -o '\.' | wc -l)
if (( dots >= 3 )); then
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
else
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
Copy link
Contributor

Choose a reason for hiding this comment

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

when/why did type become required?

Copy link
Member Author

Choose a reason for hiding this comment

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

A while back, ever since the site started hosting the pdk I think..

Copy link
Member Author

Choose a reason for hiding this comment

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

With multiple products up, an identifier was needed

fi
else
if test "$version" = "latest"; then
filename="puppet-agent-latest.dmg"
else
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
fi

download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
fi
;;
Expand Down
Loading