diff --git a/features/src/gitlab-cli/devcontainer-feature.json b/features/src/gitlab-cli/devcontainer-feature.json index 4286d820..4b4a2b35 100644 --- a/features/src/gitlab-cli/devcontainer-feature.json +++ b/features/src/gitlab-cli/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "gitlab-cli", - "version": "24.12.0", + "version": "24.12.1", "name": "GitLab CLI", "documentationURL": "https://github.com/rapidsai/devcontainers/features/tree/main/src/gitlab-cli", "description": "Installs the GitLab CLI. Auto-detects latest version and installs needed dependencies.", @@ -8,8 +8,7 @@ "version": { "type": "string", "proposals": [ - "latest", - "none" + "latest" ], "default": "latest", "description": "Select version of the GitLab CLI, if not latest." diff --git a/features/src/gitlab-cli/install.sh b/features/src/gitlab-cli/install.sh index d5550483..e13122e4 100755 --- a/features/src/gitlab-cli/install.sh +++ b/features/src/gitlab-cli/install.sh @@ -13,48 +13,62 @@ cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; # install global/common scripts . ./common/install.sh; +gitlab_cli_file_name() { + local -; + set -euo pipefail; + + local os="$(uname -s)"; + local arch="${TARGETARCH:-}"; + + if [[ "${CLI_VERSION}" < "1.47.0" ]]; then + arch="${arch:-$(uname -m)}"; + else + arch="${arch:-$(dpkg --print-architecture | awk -F'-' '{print $NF}')}"; + os="${os,,}"; + fi + + echo "glab_${CLI_VERSION}_${os}_${arch}.deb"; +} + +download_gitlab_cli_deb() { + local -; + set -euo pipefail; + wget --no-hsts -q -O /tmp/gitlab-cli.deb \ + "https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/$(gitlab_cli_file_name)"; +} + # Fall back on direct download if no apt package exists # Fetches .deb file to be installed with dpkg install_deb_using_gitlab() { + local -; + set -euo pipefail; + check_packages wget; - arch="${TARGETARCH:-$(dpkg --print-architecture | awk -F'-' '{print $NF}')}"; - if [[ "$arch" == amd64 ]]; then - arch=x86_64; - fi - find_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli; - cli_filename="glab_${CLI_VERSION}_Linux_${arch}.deb"; - - mkdir -p /tmp/glabcli; - pushd /tmp/glabcli; - wget https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/${cli_filename}; - exit_code=$?; - set -e; - if [ "$exit_code" != "0" ]; then - # Handle situation where git tags are ahead of what was is available to actually download - echo "(!) gitlab-cli version ${CLI_VERSION} failed to download. Attempting to fall back one version to retry..."; - find_prev_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli; - wget https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/${cli_filename}; + # Soft version matching + if test "${CLI_VERSION}" = latest || test "${CLI_VERSION}" = stable || test "${CLI_VERSION}" = lts; then + find_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli; + while ! download_gitlab_cli_deb; do + # Handle situation where git tags are ahead of what was is available to actually download + echo "(!) gitlab-cli version ${CLI_VERSION} failed to download. Attempting to fall back one version to retry..."; + find_prev_version_from_git_tags CLI_VERSION https://gitlab.com/gitlab-org/cli; + done + else + download_gitlab_cli_deb; fi - dpkg -i /tmp/glabcli/${cli_filename}; - popd; - rm -rf /tmp/glabcli; + dpkg -i /tmp/gitlab-cli.deb; + rm /tmp/gitlab-cli.deb; } export DEBIAN_FRONTEND=noninteractive; -# Install curl, apt-transport-https, curl, or git if missing +# Install curl, ca-certificates, apt-transport-https, and git (if missing) check_packages curl ca-certificates apt-transport-https; if ! type git >/dev/null 2>&1; then check_packages git; fi -# Soft version matching -if [ "${CLI_VERSION}" != "latest" ] && [ "${CLI_VERSION}" != "lts" ] && [ "${CLI_VERSION}" != "stable" ]; then - find_version_from_git_tags CLI_VERSION "https://gitlab.com/gitlab-org/cli"; -fi - # Install the GitHub CLI echo "Downloading gitlab CLI...";