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

Add edge rad CLI install #6899

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
94 changes: 57 additions & 37 deletions deploy/install.ps1
sylvainsf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ $ErrorActionPreference = 'stop'
# Constants
$RadiusCliFileName = "rad.exe"
$RadiusCliFilePath = "${RadiusRoot}\${RadiusCliFileName}"
$OsArch = "windows-x64"
$OS = "windows"
$Arch = "amd64"
$GitHubOrg = "radius-project"
$GitHubRepo = "radius"
$GitHubReleaseJsonUrl = "https://api.github.com/repos/${GitHubOrg}/${GitHubRepo}/releases"
Expand All @@ -50,7 +51,7 @@ function GetWindowsAsset {
param (
$Release
)
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows_amd64.exe" }
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*${OS}_${Arch}.exe" }
if (!$windowsAsset) {
throw "Cannot find the Windows rad CLI binary"
}
Expand Down Expand Up @@ -109,47 +110,66 @@ if (-Not (Test-Path $RadiusRoot -PathType Container)) {
}
}

# Get the list of releases from GitHub
$releases = Invoke-RestMethod -Headers $githubHeader -Uri $GitHubReleaseJsonUrl -Method Get
if ($releases.Count -eq 0) {
throw "No releases from github.com/${GitHubOrg}/${GitHubRepo}"
}
if ($Version -eq "edge") {
# Check if oras CLI is installed
$orasExists = Get-Command oras -ErrorAction SilentlyContinue
if (-Not $orasExists) {
Write-Output "Error: oras CLI is not installed or not found in PATH."
Write-Output "Please visit https://edge.docs.radapp.io/installation for edge build installation instructions."
Exit 1
}

$release = GetVersionInfo -Version $Version -Releases $releases
if (!$release) {
throw "Cannot find the specified rad CLI binary version"
$downloadURL = "ghcr.io/radius-project/rad/${OS}-${Arch}:latest"
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
Write-Output "Downloading edge CLI from ${downloadURL}"
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
oras pull $downloadURL -o $RadiusRoot
}
$asset = GetWindowsAsset -Release $release
$assetName = $asset.name
$exeFileUrl = $asset.url
$exeFilePath = $RadiusRoot + "\" + $assetName
else {
# Get the list of releases from GitHub
$releases = Invoke-RestMethod -Headers $githubHeader -Uri $GitHubReleaseJsonUrl -Method Get
if ($releases.Count -eq 0) {
throw "No releases from github.com/${GitHubOrg}/${GitHubRepo}"
}

# Download rad CLI
try {
Write-Output "Downloading $exeFileUrl..."
$githubHeader.Accept = "application/octet-stream"
$oldProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue" # Do not show progress bar
Invoke-WebRequest -Headers $githubHeader -Uri $exeFileUrl -OutFile $exeFilePath
}
catch [Net.WebException] {
throw "ERROR: The specified release version: $Version does not exist."
}
finally {
$ProgressPreference = $oldProgressPreference;
}
$release = GetVersionInfo -Version $Version -Releases $releases
if (!$release) {
throw "Cannot find the specified rad CLI binary version"
}
$asset = GetWindowsAsset -Release $release
$assetName = $asset.name
$exeFileUrl = $asset.url
$exeFilePath = $RadiusRoot + "\" + $assetName

if (!(Test-Path $exeFilePath -PathType Leaf)) {
throw "Failed to download rad Cli binary - $exeFilePath"
}
# Download rad CLI
try {
Write-Output "Downloading $exeFileUrl..."
$githubHeader.Accept = "application/octet-stream"
$oldProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue" # Do not show progress bar
Invoke-WebRequest -Headers $githubHeader -Uri $exeFileUrl -OutFile $exeFilePath
}
catch [Net.WebException] {
throw "ERROR: The specified release version: $Version does not exist."
}
finally {
$ProgressPreference = $oldProgressPreference;
}

# Remove old rad CLI if exists
if (Test-Path $RadiusCliFilePath -PathType Leaf) {
Remove-Item -Recurse -Force $RadiusCliFilePath
if (!(Test-Path $exeFilePath -PathType Leaf)) {
throw "Failed to download rad CLI binary - $exeFilePath"
}

# Remove old rad CLI if exists
if (Test-Path $RadiusCliFilePath -PathType Leaf) {
Remove-Item -Recurse -Force $RadiusCliFilePath
}

# Rename the downloaded rad CLI binary
Rename-Item -Path $exeFilePath -NewName $RadiusCliFileName -Force
}

# Rename the downloaded rad CLI binary
Rename-Item -Path $exeFilePath -NewName $RadiusCliFileName -Force
if (!(Test-Path $RadiusCliFilePath -PathType Leaf)) {
throw "Failed to download rad CLI binary - $exeFilePath"
}

# Print the version string of the installed CLI
Write-Output "rad CLI version: $(&$RadiusCliFilePath version -o json | ConvertFrom-JSON | Select-Object -ExpandProperty version)"
Expand Down Expand Up @@ -186,4 +206,4 @@ else {
Write-Output "Bicep has been successfully installed"
}

Write-Output "`r`nTo get started with Radius, please visit https://docs.radapp.io/getting-started/"
Write-Output "`r`nTo get started with Radius, please visit https://docs.radapp.io/getting-started/"
52 changes: 23 additions & 29 deletions deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,35 @@ getLatestRelease() {
}

downloadFile() {
LATEST_RELEASE_TAG=$1
RELEASE_TAG=$1

RADIUS_CLI_ARTIFACT="${RADIUS_CLI_FILENAME}_${OS}_${ARCH}"
DOWNLOAD_BASE="https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${LATEST_RELEASE_TAG}/${RADIUS_CLI_ARTIFACT}"

# Create the temp directory
RADIUS_TMP_ROOT=$(mktemp -dt radius-install-XXXXXX)
ARTIFACT_TMP_FILE="$RADIUS_TMP_ROOT/$RADIUS_CLI_ARTIFACT"

echo "Downloading ${DOWNLOAD_URL}..."
if [ "$RADIUS_HTTP_REQUEST_CLI" == "curl" ]; then
curl -SsL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE"
if [ "$RELEASE_TAG" == "edge" ]; then
if ! command -v oras &> /dev/null; then
echo "Error: oras CLI is not installed or not found in PATH."
echo "Please visit https://edge.docs.radapp.io/installation for edge CLI installation instructions."
exit 1
fi

DOWNLOAD_URL="ghcr.io/radius-project/rad/${OS}-${ARCH}:latest"
echo "Downloading edge CLI from ${DOWNLOAD_URL}..."
oras pull $DOWNLOAD_URL -o $RADIUS_TMP_ROOT
mv $RADIUS_TMP_ROOT/rad $ARTIFACT_TMP_FILE
else
wget -q -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL"
DOWNLOAD_BASE="https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${RELEASE_TAG}/${RADIUS_CLI_ARTIFACT}"

echo "Downloading ${DOWNLOAD_URL}..."
if [ "$RADIUS_HTTP_REQUEST_CLI" == "curl" ]; then
curl -SsL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE"
else
wget -q -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL"
fi
fi

if [ ! -f "$ARTIFACT_TMP_FILE" ]; then
Expand All @@ -133,28 +147,6 @@ downloadFile() {
fi
}

isReleaseAvailable() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sk593 do you know if we needed this somewhere? looks unused to me

LATEST_RELEASE_TAG=$1

RADIUS_CLI_ARTIFACT="${RADIUS_CLI_FILENAME}_${OS}_${ARCH}"
DOWNLOAD_BASE="https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${LATEST_RELEASE_TAG}/${RADIUS_CLI_ARTIFACT}"

if [ "$RADIUS_HTTP_REQUEST_CLI" == "curl" ]; then
httpstatus=$(curl -sSLI -o /dev/null -w "%{http_code}" "$DOWNLOAD_URL")
if [ "$httpstatus" == "200" ]; then
return 0
fi
else
wget -q --spider "$DOWNLOAD_URL"
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
return 0
fi
fi
return 1
}

installFile() {
RADIUS_CLI_ARTIFACT="${RADIUS_CLI_FILENAME}_${OS}_${ARCH}"
local tmp_root_radius_cli="$RADIUS_TMP_ROOT/$RADIUS_CLI_ARTIFACT"
Expand Down Expand Up @@ -223,6 +215,8 @@ checkHttpRequestCLI
if [ -z "$1" ]; then
echo "Getting the latest Radius CLI..."
getLatestRelease
elif [ "$1" == "edge" ]; then
ret_val="edge"
else
ret_val=v$1
fi
Expand Down
Loading