From 1c0be0c5531030a1e5cd836fce10650c10f2c69a Mon Sep 17 00:00:00 2001 From: Bas Steins <592313+sebst@users.noreply.github.com> Date: Tue, 23 Dec 2025 15:03:28 +0000 Subject: [PATCH] feat: aws-cli --- .github/workflows/test.yaml | 1 + src/aws-cli/NOTES.md | 7 + src/aws-cli/devcontainer-feature.json | 20 +++ src/aws-cli/install.sh | 137 ++++++++++++++++++ .../scripts/fetch-latest-completer-scripts.sh | 20 +++ src/aws-cli/scripts/vendor/README.md | 12 ++ src/aws-cli/scripts/vendor/aws_bash_completer | 6 + .../scripts/vendor/aws_zsh_completer.sh | 60 ++++++++ test/aws-cli/test.sh | 19 +++ 9 files changed, 282 insertions(+) create mode 100644 src/aws-cli/NOTES.md create mode 100644 src/aws-cli/devcontainer-feature.json create mode 100755 src/aws-cli/install.sh create mode 100755 src/aws-cli/scripts/fetch-latest-completer-scripts.sh create mode 100644 src/aws-cli/scripts/vendor/README.md create mode 100755 src/aws-cli/scripts/vendor/aws_bash_completer create mode 100755 src/aws-cli/scripts/vendor/aws_zsh_completer.sh create mode 100644 test/aws-cli/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c81befe..d1fba94 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,7 @@ jobs: - asdf-vm.com - astral.sh-uv - atuin.sh + - aws-cli - btop - bun.sh - charmbracelet-gum diff --git a/src/aws-cli/NOTES.md b/src/aws-cli/NOTES.md new file mode 100644 index 0000000..0cc56cc --- /dev/null +++ b/src/aws-cli/NOTES.md @@ -0,0 +1,7 @@ +Available versions of the AWS CLI can be found here: https://github.com/aws/aws-cli/blob/v2/CHANGELOG.rst. + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. + +`bash` is required to execute the `install.sh` script. \ No newline at end of file diff --git a/src/aws-cli/devcontainer-feature.json b/src/aws-cli/devcontainer-feature.json new file mode 100644 index 0000000..18e296c --- /dev/null +++ b/src/aws-cli/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "id": "aws-cli", + "version": "1.1.2", + "name": "AWS CLI", + "documentationURL": "https://github.com/devcontainers/features/tree/main/src/aws-cli", + "description": "Installs the AWS CLI along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest" + ], + "default": "latest", + "description": "Select or enter an AWS CLI version." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} \ No newline at end of file diff --git a/src/aws-cli/install.sh b/src/aws-cli/install.sh new file mode 100755 index 0000000..861a6e4 --- /dev/null +++ b/src/aws-cli/install.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/awscli.md +# Maintainer: The VS Code and Codespaces Teams + +set -e + +# Clean up +rm -rf /var/lib/apt/lists/* + +VERSION=${VERSION:-"latest"} + +AWSCLI_GPG_KEY=FB5DB77FD5C118B80511ADA8A6310ACC4672475C +AWSCLI_GPG_KEY_MATERIAL="-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG +ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx +PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G +TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz +gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1u05CinE7k2qZ7KgKAUIcT/cR/grk +C6VwsnDU0OUCideXcQ8WeH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AqgBItODMB +rsal1y/q+bPzpsnWjzHV8+1/EtZmSc8ZUGSJOPkfC7hObnfkl18h+1QtKTjZme4d +H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe +YLZATHZKTJyiqA== +=vYOk +-----END PGP PUBLIC KEY BLOCK-----" + +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 +fi + +apt_get_update() +{ + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +check_packages curl ca-certificates gpg dirmngr unzip bash-completion less + +verify_aws_cli_gpg_signature() { + local filePath=$1 + local sigFilePath=$2 + local awsGpgKeyring=aws-cli-public-key.gpg + + echo "${AWSCLI_GPG_KEY_MATERIAL}" | gpg --dearmor > "./${awsGpgKeyring}" + gpg --batch --quiet --no-default-keyring --keyring "./${awsGpgKeyring}" --verify "${sigFilePath}" "${filePath}" + local status=$? + + rm "./${awsGpgKeyring}" + + return ${status} +} + +install() { + local scriptZipFile=awscli.zip + local scriptSigFile=awscli.sig + + # See Linux install docs at https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html + if [ "${VERSION}" != "latest" ]; then + local versionStr=-${VERSION} + fi + architecture=$(dpkg --print-architecture) + case "${architecture}" in + amd64) architectureStr=x86_64 ;; + arm64) architectureStr=aarch64 ;; + *) + echo "AWS CLI does not support machine architecture '$architecture'. Please use an x86-64 or ARM64 machine." + exit 1 + esac + local scriptUrl=https://awscli.amazonaws.com/awscli-exe-linux-${architectureStr}${versionStr}.zip + curl "${scriptUrl}" -o "${scriptZipFile}" + curl "${scriptUrl}.sig" -o "${scriptSigFile}" + + verify_aws_cli_gpg_signature "$scriptZipFile" "$scriptSigFile" + if (( $? > 0 )); then + echo "Could not verify GPG signature of AWS CLI install script. Make sure you provided a valid version." + exit 1 + fi + + unzip "${scriptZipFile}" + ./aws/install + + # kubectl bash completion + mkdir -p /etc/bash_completion.d + cp ./scripts/vendor/aws_bash_completer /etc/bash_completion.d/aws + + # kubectl zsh completion + if [ -e "${USERHOME}/.oh-my-zsh" ]; then + mkdir -p "${USERHOME}/.oh-my-zsh/completions" + cp ./scripts/vendor/aws_zsh_completer.sh "${USERHOME}/.oh-my-zsh/completions/_aws" + chown -R "${USERNAME}" "${USERHOME}/.oh-my-zsh" + fi + + rm -rf ./aws +} + +echo "(*) Installing AWS CLI..." + +install + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" \ No newline at end of file diff --git a/src/aws-cli/scripts/fetch-latest-completer-scripts.sh b/src/aws-cli/scripts/fetch-latest-completer-scripts.sh new file mode 100755 index 0000000..47dc6ee --- /dev/null +++ b/src/aws-cli/scripts/fetch-latest-completer-scripts.sh @@ -0,0 +1,20 @@ +#!/bin/bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/devcontainers/features/tree/main/src/aws-cli +# Maintainer: The Dev Container spec maintainers +# +# Run this script to replace aws_bash_completer and aws_zsh_completer.sh with the latest and greatest available version +# +COMPLETER_SCRIPTS=$(dirname "${BASH_SOURCE[0]}") +BASH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_bash_completer" +ZSH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_zsh_completer.sh" + +wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_bash_completer -O "$BASH_COMPLETER_SCRIPT" +chmod +x "$BASH_COMPLETER_SCRIPT" + +wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_zsh_completer.sh -O "$ZSH_COMPLETER_SCRIPT" +chmod +x "$ZSH_COMPLETER_SCRIPT" diff --git a/src/aws-cli/scripts/vendor/README.md b/src/aws-cli/scripts/vendor/README.md new file mode 100644 index 0000000..1f3838d --- /dev/null +++ b/src/aws-cli/scripts/vendor/README.md @@ -0,0 +1,12 @@ +### **IMPORTANT NOTE** + +Scripts in this directory are sourced externally and not maintained by the Dev Container spec maintainers. Do not make changes directly as they might be overwritten at any moment. + +## aws_bash_completer + +`aws_bash_completer` is a copy of . + +## aws_zsh_completer.sh + +`aws_zsh_completer.sh` is a copy of . + diff --git a/src/aws-cli/scripts/vendor/aws_bash_completer b/src/aws-cli/scripts/vendor/aws_bash_completer new file mode 100755 index 0000000..32cd1dd --- /dev/null +++ b/src/aws-cli/scripts/vendor/aws_bash_completer @@ -0,0 +1,6 @@ +# Typically that would be added under one of the following paths: +# - /etc/bash_completion.d +# - /usr/local/etc/bash_completion.d +# - /usr/share/bash-completion/completions + +complete -C aws_completer aws diff --git a/src/aws-cli/scripts/vendor/aws_zsh_completer.sh b/src/aws-cli/scripts/vendor/aws_zsh_completer.sh new file mode 100755 index 0000000..c1b2c12 --- /dev/null +++ b/src/aws-cli/scripts/vendor/aws_zsh_completer.sh @@ -0,0 +1,60 @@ +# Source this file to activate auto completion for zsh using the bash +# compatibility helper. Make sure to run `compinit` before, which should be +# given usually. +# +# % source /path/to/zsh_complete.sh +# +# Typically that would be called somewhere in your .zshrc. +# +# Note, the overwrite of _bash_complete() is to export COMP_LINE and COMP_POINT +# That is only required for zsh <= edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 +# +# https://github.com/zsh-users/zsh/commit/edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 +# +# zsh releases prior to that version do not export the required env variables! + +autoload -Uz bashcompinit +bashcompinit -i + +_bash_complete() { + local ret=1 + local -a suf matches + local -x COMP_POINT COMP_CWORD + local -a COMP_WORDS COMPREPLY BASH_VERSINFO + local -x COMP_LINE="$words" + local -A savejobstates savejobtexts + + (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX )) + (( COMP_CWORD = CURRENT - 1)) + COMP_WORDS=( $words ) + BASH_VERSINFO=( 2 05b 0 1 release ) + + savejobstates=( ${(kv)jobstates} ) + savejobtexts=( ${(kv)jobtexts} ) + + [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' ) + + matches=( ${(f)"$(compgen $@ -- ${words[CURRENT]})"} ) + + if [[ -n $matches ]]; then + if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then + compset -P '*/' && matches=( ${matches##*/} ) + compset -S '/*' && matches=( ${matches%%/*} ) + compadd -Q -f "${suf[@]}" -a matches && ret=0 + else + compadd -Q "${suf[@]}" -a matches && ret=0 + fi + fi + + if (( ret )); then + if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then + _default "${suf[@]}" && ret=0 + elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then + _directories "${suf[@]}" && ret=0 + fi + fi + + return ret +} + +complete -C aws_completer aws diff --git a/test/aws-cli/test.sh b/test/aws-cli/test.sh new file mode 100644 index 0000000..28b606d --- /dev/null +++ b/test/aws-cli/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check