From 347e3383fdab857f462fc3593c3c4df7c1f107f8 Mon Sep 17 00:00:00 2001 From: Tony Schneider Date: Thu, 23 Apr 2026 11:08:29 -0400 Subject: [PATCH] Remove base image assumptions from aws/install-cli --- aws/install-cli/README.md | 21 ++++- aws/install-cli/mint-utils.sh | 111 ----------------------- aws/install-cli/rwx-package.yml | 58 ++++++------ aws/install-cli/rwx-test-base.json | 5 ++ aws/install-cli/rwx-test.yml | 17 ++++ aws/install-cli/rwx-utils.sh | 137 +++++++++++++++++++++++++++++ 6 files changed, 206 insertions(+), 143 deletions(-) delete mode 100755 aws/install-cli/mint-utils.sh create mode 100755 aws/install-cli/rwx-utils.sh diff --git a/aws/install-cli/README.md b/aws/install-cli/README.md index 41cb92ce..91fb2c15 100644 --- a/aws/install-cli/README.md +++ b/aws/install-cli/README.md @@ -5,7 +5,7 @@ To install the latest version of the AWS CLI: ```yaml tasks: - key: aws-cli - call: aws/install-cli 1.0.11 + call: aws/install-cli 2.0.0 ``` To install a specific version of the AWS CLI (only v2 of the AWS CLI is supported): @@ -13,7 +13,7 @@ To install a specific version of the AWS CLI (only v2 of the AWS CLI is supporte ```yaml tasks: - key: aws-cli - call: aws/install-cli 1.0.11 + call: aws/install-cli 2.0.0 with: cli-version: "2.15.13" ``` @@ -21,3 +21,20 @@ tasks: For the list of available versions, see the AWS CLI changelog on GitHub: https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst + +## Upgrading to 2.0.0 + +Version 2.0.0 no longer automatically installs `unzip` and `gpg` if they are missing. If your base image does not include these tools, you will need to install them yourself and specify that task as a `use` dependency. + +```yaml +tasks: + - key: install-deps + run: | + apt-get update + apt-get install -y unzip gnupg + apt-get clean + + - key: aws-cli + use: install-deps + call: aws/install-cli 2.0.0 +``` diff --git a/aws/install-cli/mint-utils.sh b/aws/install-cli/mint-utils.sh deleted file mode 100755 index 725ee83a..00000000 --- a/aws/install-cli/mint-utils.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env bash -# mint-utils version 1.0.3 - -detected_os="" -detected_os_version="" -detected_os_codename="" -detected_arch="" -detected_package_manager="" - -function mint__detect_os_arch { - if [ -f /etc/os-release ]; then - . /etc/os-release - - detected_os="$ID" - detected_os_version="$VERSION_ID" - detected_os_codename="$VERSION_CODENAME" - - case "$ID" in - ubuntu|debian) - detected_package_manager="apt" - ;; - esac - fi - - detected_arch=$(uname -m) -} - -function mint_os_name { - if [ -z "$detected_os" ]; then - mint__detect_os_arch - fi - echo "$detected_os" -} - -function mint_os_version { - if [ -z "$detected_os_version" ]; then - mint__detect_os_arch - fi - echo "$detected_os_version" -} - -# Output the name and version of the operating system as expected by Mint's `base.os` field. -function mint_os_name_version { - echo "$(mint_os_name) $(mint_os_version)" -} - -function mint_os_codename { - if [ -z "$detected_os_codename" ]; then - mint__detect_os_arch - fi - echo "$detected_os_codename" -} - -function mint_arch { - if [ -z "$detected_arch" ]; then - mint__detect_os_arch - fi - echo "$detected_arch" -} - -function mint_arch_amd { - local arch - arch="$(mint_arch)" - if [ "$arch" = "x86_64" ]; then - echo "amd64" - else - echo "$arch" - fi -} - -function mint_os_package_manager { - if [ -z "$detected_package_manager" ]; then - mint__detect_os_arch - fi - echo "$detected_package_manager" -} - -function mint_os_version_gte { - local compare_version="$1" - printf '%s\n' "$compare_version" "$(mint_os_version)" | sort -Vsc >/dev/null 2>&1 -} - -function mint_os_version_lte { - local compare_version="$1" - printf '%s\n' "$compare_version" "$(mint_os_version)" | sort -Vsc -r >/dev/null 2>&1 -} - -# Convert a string something usable as a Mint key. -# -# Replaces all non-alphanumeric characters with hyphens, compressing multiple hyphens into one. -function mint_keyify { - echo -n "$*" | tr -c -s '[:alnum:]' '-' -} - -# Check if an array contains a given element. -# -# Usage: mint_contains two one two three -function mint_contains { - local needle="$1" - local elements=("${@:2}") - for item in "${elements[@]}"; do - if [ "$item" = "$needle" ]; then - return 0 - fi - done - return 1 -} - -function mint_os_package_manager_in { - mint_contains "$(mint_os_package_manager)" "$@" -} diff --git a/aws/install-cli/rwx-package.yml b/aws/install-cli/rwx-package.yml index b28cf2f7..44212ca7 100644 --- a/aws/install-cli/rwx-package.yml +++ b/aws/install-cli/rwx-package.yml @@ -1,5 +1,5 @@ name: aws/install-cli -version: 1.0.11 +version: 2.0.0 description: Install the AWS CLI source_code_url: https://github.com/rwx-cloud/packages/tree/main/aws/install-cli issue_tracker_url: https://github.com/rwx-cloud/packages/issues @@ -10,51 +10,49 @@ parameters: required: false tasks: - - key: install-unzip-if-necessary + - key: setup run: | - if ! command -v unzip &> /dev/null; then - source "$RWX_PACKAGE_PATH/mint-utils.sh" - if ! mint_os_package_manager_in apt; then - echo "Unsupported operating system or package manager \`$(mint_os_package_manager)\`" > "$(mktemp "$RWX_ERRORS/error-XXXX")" - exit 1 - fi - - sudo apt-get update - sudo apt-get install unzip - sudo apt-get clean + needed="" + + if ! command -v curl >/dev/null 2>&1; then + needed="$needed curl" fi - filter: [] - - key: install-gpg-if-necessary - run: | - if ! command -v gpg &> /dev/null; then - source "$RWX_PACKAGE_PATH/mint-utils.sh" - if ! mint_os_package_manager_in apt; then - echo "Unsupported operating system or package manager \`$(mint_os_package_manager)\`" > "$(mktemp "$RWX_ERRORS/error-XXXX")" - exit 1 - fi - - sudo apt-get update - sudo apt-get install gnupg - sudo apt-get clean + + if ! command -v unzip >/dev/null 2>&1; then + needed="$needed unzip" + fi + + if ! command -v gpg >/dev/null 2>&1; then + needed="$needed gpg" + fi + + if [ -n "$needed" ]; then + cat << EOF > "${RWX_ERRORS}/missing-packages" + The \`aws/install-cli\` package requires system packages that were missing:$needed + + Define a task which installs those packages, and specify it as a \`use\` dependency of the \`aws/install-cli\` task + EOF + exit 1 fi filter: [] - key: install-cli - use: [install-gpg-if-necessary, install-unzip-if-necessary] + use: [setup] run: | - set -ueo pipefail + set -ue + . "$RWX_PACKAGE_PATH/rwx-utils.sh" tmp="$(mktemp -d)" cd "$tmp" # installer zip - if [[ -n "$CLI_VERSION" ]]; then + if [ -n "$CLI_VERSION" ]; then curl -o "awscliv2.zip" -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m)-$CLI_VERSION.zip" else curl -o "awscliv2.zip" -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" fi # signature - if [[ -n "$CLI_VERSION" ]]; then + if [ -n "$CLI_VERSION" ]; then curl -o "awscliv2.sig" -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m)-$CLI_VERSION.zip.sig" else curl -o "awscliv2.sig" -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip.sig" @@ -130,7 +128,7 @@ tasks: gpg --verify awscliv2.sig awscliv2.zip unzip awscliv2.zip - sudo ./aws/install + rwx_maybe_sudo ./aws/install rm -rf "$tmp" aws --version filter: [] diff --git a/aws/install-cli/rwx-test-base.json b/aws/install-cli/rwx-test-base.json index 093a55cc..8e98b67c 100644 --- a/aws/install-cli/rwx-test-base.json +++ b/aws/install-cli/rwx-test-base.json @@ -18,5 +18,10 @@ "image": "ubuntu:24.04", "config": "rwx/base 1.0.0", "arch": "arm64" + }, + { + "image": "alpine:latest", + "config": "6e590fe8cb5122675c1998821470722bc58dab3f53cc992c18d3b3382f03a31e", + "arch": "x86_64" } ] diff --git a/aws/install-cli/rwx-test.yml b/aws/install-cli/rwx-test.yml index cf544575..44b4ed30 100644 --- a/aws/install-cli/rwx-test.yml +++ b/aws/install-cli/rwx-test.yml @@ -4,8 +4,24 @@ base: arch: ${{ init.base-arch }} tasks: + - key: system-packages + run: | + if ! command -v curl >/dev/null 2>&1 || ! command -v unzip >/dev/null 2>&1 || ! command -v gpg >/dev/null 2>&1; then + if command -v apk >/dev/null 2>&1; then + apk add --no-cache curl unzip gnupg + elif command -v apt-get >/dev/null 2>&1; then + apt-get -y update + apt-get -y install curl unzip gnupg + apt-get clean + else + echo "Unsupported package manager; need curl, unzip, and gpg installed" >&2 + exit 1 + fi + fi + - key: test-default call: ${{ init.package-digest }} + use: system-packages - key: test-default--assert use: test-default @@ -13,6 +29,7 @@ tasks: - key: test-specified call: ${{ init.package-digest }} + use: system-packages with: cli-version: "2.0.30" diff --git a/aws/install-cli/rwx-utils.sh b/aws/install-cli/rwx-utils.sh new file mode 100755 index 00000000..1d1e0cf9 --- /dev/null +++ b/aws/install-cli/rwx-utils.sh @@ -0,0 +1,137 @@ +#!/bin/sh +# rwx-utils version 2.0.0 + +detected_os="" +detected_os_version="" +detected_os_codename="" +detected_arch="" +detected_package_manager="" + +rwx__detect_os_arch() { + if [ -f /etc/os-release ]; then + . /etc/os-release + + detected_os="$ID" + detected_os_version="$VERSION_ID" + detected_os_codename="$VERSION_CODENAME" + + case "$ID" in + ubuntu|debian) + detected_package_manager="apt" + ;; + alpine) + detected_package_manager="apk" + ;; + esac + fi + + detected_arch=$(uname -m) +} + +rwx_os_name() { + if [ -z "$detected_os" ]; then + rwx__detect_os_arch + fi + printf '%s\n' "$detected_os" +} + +rwx_os_version() { + if [ -z "$detected_os_version" ]; then + rwx__detect_os_arch + fi + printf '%s\n' "$detected_os_version" +} + +# Output the name and version of the operating system as expected by RWX's `base.os` field. +rwx_os_name_version() { + printf '%s %s\n' "$(rwx_os_name)" "$(rwx_os_version)" +} + +rwx_os_codename() { + if [ -z "$detected_os_codename" ]; then + rwx__detect_os_arch + fi + printf '%s\n' "$detected_os_codename" +} + +rwx_arch() { + if [ -z "$detected_arch" ]; then + rwx__detect_os_arch + fi + printf '%s\n' "$detected_arch" +} + +rwx_arch_amd() { + arch="$(rwx_arch)" + if [ "$arch" = "x86_64" ]; then + printf '%s\n' "amd64" + else + printf '%s\n' "$arch" + fi +} + +rwx_os_package_manager() { + if [ -z "$detected_package_manager" ]; then + rwx__detect_os_arch + fi + printf '%s\n' "$detected_package_manager" +} + +rwx_os_version_gte() { + compare_version="$1" + printf '%s\n' "$compare_version" "$(rwx_os_version)" | sed 's/\([0-9.]*\).*/\1/' | sort -c -t. -k1,1n -k2,2n -k3,3n >/dev/null 2>&1 +} + +rwx_os_version_lte() { + compare_version="$1" + printf '%s\n' "$compare_version" "$(rwx_os_version)" | sed 's/\([0-9.]*\).*/\1/' | sort -c -t. -k1,1n -k2,2n -k3,3n -r >/dev/null 2>&1 +} + +# Convert a string something usable as a RWX key. +# +# Replaces all non-alphanumeric characters with hyphens, compressing multiple hyphens into one. +rwx_keyify() { + printf '%s' "$*" | tr -c -s '[:alnum:]' '-' +} + +# Check if the provided list contains a given element. +# +# Usage: rwx_contains two one two three +rwx_contains() { + if [ "$#" -eq 0 ]; then + return 1 + fi + + needle=$1 + shift + + for item do + if [ "$item" = "$needle" ]; then + return 0 + fi + done + + return 1 +} + +rwx_os_name_in() { + rwx_contains "$(rwx_os_name)" "$@" +} + +rwx_os_package_manager_in() { + rwx_contains "$(rwx_os_package_manager)" "$@" +} + +rwx_maybe_sudo() { + if [ "$(id -u)" -eq 0 ]; then + "$@" + else + # If sudo is available, use it + if command -v sudo >/dev/null 2>&1; then + sudo "$@" + else + echo "Error: need root privileges but 'sudo' not found" >&2 + return 1 + fi + fi +}