diff --git a/deploy/install.ps1 b/deploy/install.ps1 index 300bb66ee7..92586d6ecb 100755 --- a/deploy/install.ps1 +++ b/deploy/install.ps1 @@ -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" @@ -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" } @@ -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/${GitHubOrg}/rad/${OS}-${Arch}:latest" + Write-Output "Downloading edge CLI from ${downloadURL}..." + 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)" @@ -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/" \ No newline at end of file +Write-Output "`r`nTo get started with Radius, please visit https://docs.radapp.io/getting-started/" diff --git a/deploy/install.sh b/deploy/install.sh index 088df2b904..9134a5ca2f 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -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 @@ -133,28 +147,6 @@ downloadFile() { fi } -isReleaseAvailable() { - 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" @@ -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