Skip to content

Commit db77015

Browse files
authored
feat: aws-cli (#74)
1 parent 5c33f1b commit db77015

File tree

9 files changed

+282
-0
lines changed

9 files changed

+282
-0
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- asdf-vm.com
1717
- astral.sh-uv
1818
- atuin.sh
19+
- aws-cli
1920
- btop
2021
- bun.sh
2122
- charmbracelet-gum

src/aws-cli/NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Available versions of the AWS CLI can be found here: https://github.com/aws/aws-cli/blob/v2/CHANGELOG.rst.
2+
3+
## OS Support
4+
5+
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
6+
7+
`bash` is required to execute the `install.sh` script.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"id": "aws-cli",
3+
"version": "1.1.2",
4+
"name": "AWS CLI",
5+
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/aws-cli",
6+
"description": "Installs the AWS CLI along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"proposals": [
11+
"latest"
12+
],
13+
"default": "latest",
14+
"description": "Select or enter an AWS CLI version."
15+
}
16+
},
17+
"installsAfter": [
18+
"ghcr.io/devcontainers/features/common-utils"
19+
]
20+
}

src/aws-cli/install.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/awscli.md
8+
# Maintainer: The VS Code and Codespaces Teams
9+
10+
set -e
11+
12+
# Clean up
13+
rm -rf /var/lib/apt/lists/*
14+
15+
VERSION=${VERSION:-"latest"}
16+
17+
AWSCLI_GPG_KEY=FB5DB77FD5C118B80511ADA8A6310ACC4672475C
18+
AWSCLI_GPG_KEY_MATERIAL="-----BEGIN PGP PUBLIC KEY BLOCK-----
19+
20+
mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG
21+
ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx
22+
PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G
23+
TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz
24+
gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1u05CinE7k2qZ7KgKAUIcT/cR/grk
25+
C6VwsnDU0OUCideXcQ8WeHutqvgZH1JgKDbznoIzeQHJD238GEu+eKhRHcz8/jeG
26+
94zkcgJOz3KbZGYMiTh277Fvj9zzvZsbMBCedV1BTg3TqgvdX4bdkhf5cH+7NtWO
27+
lrFj6UwAsGukBTAOxC0l/dnSmZhJ7Z1KmEWilro/gOrjtOxqRQutlIqG22TaqoPG
28+
fYVN+en3Zwbt97kcgZDwqbuykNt64oZWc4XKCa3mprEGC3IbJTBFqglXmZ7l9ywG
29+
EEUJYOlb2XrSuPWml39beWdKM8kzr1OjnlOm6+lpTRCBfo0wa9F8YZRhHPAkwKkX
30+
XDeOGpWRj4ohOx0d2GWkyV5xyN14p2tQOCdOODmz80yUTgRpPVQUtOEhXQARAQAB
31+
tCFBV1MgQ0xJIFRlYW0gPGF3cy1jbGlAYW1hem9uLmNvbT6JAlQEEwEIAD4WIQT7
32+
Xbd/1cEYuAURraimMQrMRnJHXAUCXYKvtQIbAwUJB4TOAAULCQgHAgYVCgkICwIE
33+
FgIDAQIeAQIXgAAKCRCmMQrMRnJHXJIXEAChLUIkg80uPUkGjE3jejvQSA1aWuAM
34+
yzy6fdpdlRUz6M6nmsUhOExjVIvibEJpzK5mhuSZ4lb0vJ2ZUPgCv4zs2nBd7BGJ
35+
MxKiWgBReGvTdqZ0SzyYH4PYCJSE732x/Fw9hfnh1dMTXNcrQXzwOmmFNNegG0Ox
36+
au+VnpcR5Kz3smiTrIwZbRudo1ijhCYPQ7t5CMp9kjC6bObvy1hSIg2xNbMAN/Do
37+
ikebAl36uA6Y/Uczjj3GxZW4ZWeFirMidKbtqvUz2y0UFszobjiBSqZZHCreC34B
38+
hw9bFNpuWC/0SrXgohdsc6vK50pDGdV5kM2qo9tMQ/izsAwTh/d/GzZv8H4lV9eO
39+
tEis+EpR497PaxKKh9tJf0N6Q1YLRHof5xePZtOIlS3gfvsH5hXA3HJ9yIxb8T0H
40+
QYmVr3aIUes20i6meI3fuV36VFupwfrTKaL7VXnsrK2fq5cRvyJLNzXucg0WAjPF
41+
RrAGLzY7nP1xeg1a0aeP+pdsqjqlPJom8OCWc1+6DWbg0jsC74WoesAqgBItODMB
42+
rsal1y/q+bPzpsnWjzHV8+1/EtZmSc8ZUGSJOPkfC7hObnfkl18h+1QtKTjZme4d
43+
H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe
44+
YLZATHZKTJyiqA==
45+
=vYOk
46+
-----END PGP PUBLIC KEY BLOCK-----"
47+
48+
if [ "$(id -u)" -ne 0 ]; then
49+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
50+
exit 1
51+
fi
52+
53+
apt_get_update()
54+
{
55+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
56+
echo "Running apt-get update..."
57+
apt-get update -y
58+
fi
59+
}
60+
61+
# Checks if packages are installed and installs them if not
62+
check_packages() {
63+
if ! dpkg -s "$@" > /dev/null 2>&1; then
64+
apt_get_update
65+
apt-get -y install --no-install-recommends "$@"
66+
fi
67+
}
68+
69+
export DEBIAN_FRONTEND=noninteractive
70+
71+
check_packages curl ca-certificates gpg dirmngr unzip bash-completion less
72+
73+
verify_aws_cli_gpg_signature() {
74+
local filePath=$1
75+
local sigFilePath=$2
76+
local awsGpgKeyring=aws-cli-public-key.gpg
77+
78+
echo "${AWSCLI_GPG_KEY_MATERIAL}" | gpg --dearmor > "./${awsGpgKeyring}"
79+
gpg --batch --quiet --no-default-keyring --keyring "./${awsGpgKeyring}" --verify "${sigFilePath}" "${filePath}"
80+
local status=$?
81+
82+
rm "./${awsGpgKeyring}"
83+
84+
return ${status}
85+
}
86+
87+
install() {
88+
local scriptZipFile=awscli.zip
89+
local scriptSigFile=awscli.sig
90+
91+
# See Linux install docs at https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
92+
if [ "${VERSION}" != "latest" ]; then
93+
local versionStr=-${VERSION}
94+
fi
95+
architecture=$(dpkg --print-architecture)
96+
case "${architecture}" in
97+
amd64) architectureStr=x86_64 ;;
98+
arm64) architectureStr=aarch64 ;;
99+
*)
100+
echo "AWS CLI does not support machine architecture '$architecture'. Please use an x86-64 or ARM64 machine."
101+
exit 1
102+
esac
103+
local scriptUrl=https://awscli.amazonaws.com/awscli-exe-linux-${architectureStr}${versionStr}.zip
104+
curl "${scriptUrl}" -o "${scriptZipFile}"
105+
curl "${scriptUrl}.sig" -o "${scriptSigFile}"
106+
107+
verify_aws_cli_gpg_signature "$scriptZipFile" "$scriptSigFile"
108+
if (( $? > 0 )); then
109+
echo "Could not verify GPG signature of AWS CLI install script. Make sure you provided a valid version."
110+
exit 1
111+
fi
112+
113+
unzip "${scriptZipFile}"
114+
./aws/install
115+
116+
# kubectl bash completion
117+
mkdir -p /etc/bash_completion.d
118+
cp ./scripts/vendor/aws_bash_completer /etc/bash_completion.d/aws
119+
120+
# kubectl zsh completion
121+
if [ -e "${USERHOME}/.oh-my-zsh" ]; then
122+
mkdir -p "${USERHOME}/.oh-my-zsh/completions"
123+
cp ./scripts/vendor/aws_zsh_completer.sh "${USERHOME}/.oh-my-zsh/completions/_aws"
124+
chown -R "${USERNAME}" "${USERHOME}/.oh-my-zsh"
125+
fi
126+
127+
rm -rf ./aws
128+
}
129+
130+
echo "(*) Installing AWS CLI..."
131+
132+
install
133+
134+
# Clean up
135+
rm -rf /var/lib/apt/lists/*
136+
137+
echo "Done!"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/devcontainers/features/tree/main/src/aws-cli
8+
# Maintainer: The Dev Container spec maintainers
9+
#
10+
# Run this script to replace aws_bash_completer and aws_zsh_completer.sh with the latest and greatest available version
11+
#
12+
COMPLETER_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")
13+
BASH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_bash_completer"
14+
ZSH_COMPLETER_SCRIPT="$COMPLETER_SCRIPTS/vendor/aws_zsh_completer.sh"
15+
16+
wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_bash_completer -O "$BASH_COMPLETER_SCRIPT"
17+
chmod +x "$BASH_COMPLETER_SCRIPT"
18+
19+
wget https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_zsh_completer.sh -O "$ZSH_COMPLETER_SCRIPT"
20+
chmod +x "$ZSH_COMPLETER_SCRIPT"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### **IMPORTANT NOTE**
2+
3+
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.
4+
5+
## aws_bash_completer
6+
7+
`aws_bash_completer` is a copy of <https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_bash_completer>.
8+
9+
## aws_zsh_completer.sh
10+
11+
`aws_zsh_completer.sh` is a copy of <https://raw.githubusercontent.com/aws/aws-cli/v2/bin/aws_zsh_completer.sh>.
12+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Typically that would be added under one of the following paths:
2+
# - /etc/bash_completion.d
3+
# - /usr/local/etc/bash_completion.d
4+
# - /usr/share/bash-completion/completions
5+
6+
complete -C aws_completer aws
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Source this file to activate auto completion for zsh using the bash
2+
# compatibility helper. Make sure to run `compinit` before, which should be
3+
# given usually.
4+
#
5+
# % source /path/to/zsh_complete.sh
6+
#
7+
# Typically that would be called somewhere in your .zshrc.
8+
#
9+
# Note, the overwrite of _bash_complete() is to export COMP_LINE and COMP_POINT
10+
# That is only required for zsh <= edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570
11+
#
12+
# https://github.com/zsh-users/zsh/commit/edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570
13+
#
14+
# zsh releases prior to that version do not export the required env variables!
15+
16+
autoload -Uz bashcompinit
17+
bashcompinit -i
18+
19+
_bash_complete() {
20+
local ret=1
21+
local -a suf matches
22+
local -x COMP_POINT COMP_CWORD
23+
local -a COMP_WORDS COMPREPLY BASH_VERSINFO
24+
local -x COMP_LINE="$words"
25+
local -A savejobstates savejobtexts
26+
27+
(( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))
28+
(( COMP_CWORD = CURRENT - 1))
29+
COMP_WORDS=( $words )
30+
BASH_VERSINFO=( 2 05b 0 1 release )
31+
32+
savejobstates=( ${(kv)jobstates} )
33+
savejobtexts=( ${(kv)jobtexts} )
34+
35+
[[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
36+
37+
matches=( ${(f)"$(compgen $@ -- ${words[CURRENT]})"} )
38+
39+
if [[ -n $matches ]]; then
40+
if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
41+
compset -P '*/' && matches=( ${matches##*/} )
42+
compset -S '/*' && matches=( ${matches%%/*} )
43+
compadd -Q -f "${suf[@]}" -a matches && ret=0
44+
else
45+
compadd -Q "${suf[@]}" -a matches && ret=0
46+
fi
47+
fi
48+
49+
if (( ret )); then
50+
if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then
51+
_default "${suf[@]}" && ret=0
52+
elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then
53+
_directories "${suf[@]}" && ret=0
54+
fi
55+
fi
56+
57+
return ret
58+
}
59+
60+
complete -C aws_completer aws

test/aws-cli/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
4+
set -e
5+
6+
# Optional: Import test library bundled with the devcontainer CLI
7+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
8+
# Provides the 'check' and 'reportResults' commands.
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
13+
# check <LABEL> <cmd> [args...]
14+
15+
check "execute command" bash -c "aws --version | grep 'aws'"
16+
17+
# Report results
18+
# If any of the checks above exited with a non-zero exit code, the test will fail.
19+
reportResults

0 commit comments

Comments
 (0)