Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug(install.sh): Install coder does not honor --version flag #12867

@michaelbrewer

Description

@michaelbrewer

When doing a standard install curl -L https://coder.com/install.sh | sh of coder, the api calls to get the latest version is often rate limited by github. This results in a [403](curl: (22) The requested URL returned error: 403), which should should prompt the script to fail, but instead returns a blank version. As the version can not be determined Installing v of the amd64 rpm package from GitHub. is printed and curl -#fL -o ~/.cache/coder/coder__linux_amd64.rpm.incomplete -C - https://github.com/coder/coder/releases/download/v/coder__linux_amd64.rpm is downloaded

See output:

curl -L https://coder.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 20209  100 20209    0     0  19137      0  0:00:01  0:00:01 --:--:--  101k
curl: (22) The requested URL returned error: 403
Red Hat Enterprise Linux 9.3 (Plow)
Installing v of the amd64 rpm package from GitHub.

+ mkdir -p ~/.cache/coder
+ curl -#fL -o ~/.cache/coder/coder__linux_amd64.rpm.incomplete -C - https://github.com/coder/coder/releases/download/v/coder__linux_amd64.rpm
curl: (22) The requested URL returned error: 404

A workaround would have been to pass in the version you want

curl -L https://coder.com/install.sh | sh -s -- --version 2.10.0

But this is not honored and the api call is still made.

Expected outcome

  1. When passing in the version number, we should honor it and ignore getting the latest version
  2. Not to rely on the github api to get the latest version of coder (or to check for being rate limited)

Possible Fix

Initial change to use VERSION when set

if [ -z "${VERSION}" ]; then
  if [ "${MAINLINE}" = 0 ]; then
	  VERSION=${STABLE_VERSION}
  else
	VERSION=$(echo_latest_mainline_version)
  fi
fi

also adding a check to echo_latest_mainline_version would help debugging this issue in the future

echo_latest_mainline_version() {
	# Fetch the releases from the GitHub API, sort by version number,
	# and take the first result. Note that we're sorting by space-
	# separated numbers and without utilizing the sort -V flag for the
	# best compatibility.
	version=$(curl -fsSL https://api.github.com/repos/coder/coder/releases |
		awk -F'"' '/"tag_name"/ {print $4}' |
		tr -d v |
		tr . ' ' |
		sort -k1,1nr -k2,2nr -k3,3nr |
		head -n1 |
		tr ' ' .)

	if [ -z "$version" ]; then
		echo "Failed to fetch the latest version from GitHub."
		exit 1
	fi

	echo "$version"
}

In general using the GitHub api comes with severe limits when anonymous and via a share NAT ("The primary rate limit for unauthenticated requests is 60 requests per hour."). Maybe an alternative could be used to get the latest stable and mainline releases (like a static file updated on release)


Workaround for stable

Stable installs won't be effected as it is using Github site and not the api.

curl -L https://coder.com/install.sh | sh -s -- --stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliArea: CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions