From 3487d7dc01db96621b01bb7e88fa549c07ea7299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Schro=CC=88der?= Date: Fri, 31 Jan 2025 15:17:02 +0100 Subject: [PATCH] Add version option for gitlab-cli feature --- src/gitlab-cli/devcontainer-feature.json | 12 ++++++++- src/gitlab-cli/install.sh | 32 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/gitlab-cli/devcontainer-feature.json b/src/gitlab-cli/devcontainer-feature.json index f28f912..2ebeb20 100644 --- a/src/gitlab-cli/devcontainer-feature.json +++ b/src/gitlab-cli/devcontainer-feature.json @@ -1,9 +1,19 @@ { "id": "gitlab-cli", - "version": "1.0.0", + "version": "1.1.0", "name": "GitLab CLI", "documentationURL": "https://github.com/skriptfabrik/devcontainer-features/tree/main/src/gitlab-cli", "description": "Installs GitLab CLI (glab).", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest" + ], + "default": "latest", + "description": "Select or enter a gitlab-cli version." + } + }, "installsAfter": [ "ghcr.io/devcontainers/features/common-utils" ] diff --git a/src/gitlab-cli/install.sh b/src/gitlab-cli/install.sh index e997061..8341cae 100644 --- a/src/gitlab-cli/install.sh +++ b/src/gitlab-cli/install.sh @@ -2,6 +2,8 @@ set -e +CLI_VERSION="${VERSION:-"latest"}" + if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' exit 1 @@ -18,14 +20,30 @@ fi # Install prerequisites apt-get -y update -apt-get -y install --no-install-recommends curl ca-certificates - -# Add WakeMeOps repository -curl -sSL "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash - -# Install glab -apt-get -y install --no-install-recommends glab +apt-get -y install --no-install-recommends curl ca-certificates jq git # Clean up apt-get -y clean rm -rf /var/lib/apt/lists/* + +# Fetch latest version if needed +if [ "${CLI_VERSION}" = "latest" ]; then + CLI_VERSION=$(curl -s curl -s https://gitlab.com/api/v4/projects/34675721/releases | jq -r '.[0].tag_name' | awk '{print substr($1, 2)}') +fi + +# Detect current machine architecture +if [ "$(uname -m)" = "aarch64" ]; then + ARCH="arm64" +else + ARCH="amd64" +fi + +# DEB package and download URL +DEB_PACKAGE="glab_${CLI_VERSION}_linux_${ARCH}.deb" +DOWNLOAD_URL="https://gitlab.com/gitlab-org/cli/-/releases/v${CLI_VERSION}/downloads/${DEB_PACKAGE}" + +# Download and install gitlab-cli +echo "Downloading gitlab-cli from ${DOWNLOAD_URL}" +curl -sSLO "${DOWNLOAD_URL}" +dpkg -i "${DEB_PACKAGE}" +rm -f "${DEB_PACKAGE}"