Skip to content

Commit

Permalink
Add edge rad CLI install (radius-project#6899)
Browse files Browse the repository at this point in the history
# Description

* Updated `install.sh` to support `edge` as a valid argument and install
using oras CLI if available
* Updated `install.ps1` to support `edge` as a valid argument and
install using oras CLI if available
* Removing isReleaseAvailable (unused)

## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).
- This pull request adds or changes features of Radius and has an
approved issue (issue link required).
- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->

Fixes: #issue_number

## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖[[deprecated]](https://githubnext.com/copilot-for-prs-sunset)
Generated by Copilot at 62a66c5</samp>

### Summary
📦🚀🌐

<!--
1. 📦 This emoji can be used to indicate that the install script was
updated to support different packaging or distribution options for the
`radius` CLI, such as stable or edge versions.
2. 🚀 This emoji can be used to indicate that the edge version of the
`radius` CLI is downloaded from the GitHub Container Registry, which is
a fast and reliable way to deliver container images and artifacts.
3. 🌐 This emoji can be used to indicate that the stable version of the
`radius` CLI is downloaded from the GitHub Releases page, which is a
web-based platform for hosting and managing software releases.
-->
Add support for installing edge version of `radius` CLI. Update
`deploy/install.sh` to use `oras` or `curl`/`wget` depending on the
version.

> _Sing, O Muse, of the skillful `radius` CLI_
> _That lets the heroes deploy their code with ease_
> _And how its install script was wisely enhanced_
> _To offer two choices of version in advance_

### Walkthrough
* Modify `downloadFile` function to accept `RELEASE_TAG` parameter and
download either stable or edge version of Radius CLI
([link](https://github.com/radius-project/radius/pull/6899/files?diff=unified&w=0#diff-ed1191c237ea4ba8f2011568f4ed0208c8d0ca36cbde1285828a61b4ff2128b4L113-R115),
[link](https://github.com/radius-project/radius/pull/6899/files?diff=unified&w=0#diff-ed1191c237ea4ba8f2011568f4ed0208c8d0ca36cbde1285828a61b4ff2128b4L123-R141))
* Delete `isReleaseAvailable` function as it is obsolete
([link](https://github.com/radius-project/radius/pull/6899/files?diff=unified&w=0#diff-ed1191c237ea4ba8f2011568f4ed0208c8d0ca36cbde1285828a61b4ff2128b4L136-L157))
* Update `getLatestReleaseTag` function to return "edge" when passed as
argument
([link](https://github.com/radius-project/radius/pull/6899/files?diff=unified&w=0#diff-ed1191c237ea4ba8f2011568f4ed0208c8d0ca36cbde1285828a61b4ff2128b4R218-R219))

---------

Signed-off-by: willdavsmith <willdavsmith@gmail.com>
Signed-off-by: Will Smith <willdavsmith@gmail.com>
Co-authored-by: Aaron Crawfis <Aaron.Crawfis@microsoft.com>
  • Loading branch information
willdavsmith and AaronCrawfis authored Dec 8, 2023
1 parent fb0fe3c commit 03ae959
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 66 deletions.
94 changes: 57 additions & 37 deletions deploy/install.ps1
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/${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)"
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() {
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

0 comments on commit 03ae959

Please sign in to comment.