├── .gitignore ├── entrypoint.sh ├── Dockerfile ├── aws.sh ├── .circleci └── config.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | **/.#* 3 | **/#*# 4 | **/*~ 5 | **/*.swp 6 | /.idea/ 7 | 8 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | case $1 in 3 | --init-rc=*) 4 | install_dir=`expr "$1" : '--init-rc=\(.*\)'` 5 | echo "mkdir -p \"${install_dir}\"" 6 | echo "cd \"${install_dir}\" && (" 7 | echo 'install_path=`pwd`' 8 | echo "cat >aws <<'EOF'" 9 | cat /usr/local/bin/aws.sh 10 | echo "EOF" 11 | echo "chmod +x aws )" ;; 12 | *) 13 | exec aws "$@" ;; 14 | esac 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye-slim 2 | 3 | ENV HOME=/home \ 4 | WORKDIR=/home/workdir 5 | RUN cd /etc/dpkg/dpkg.cfg.d ; \ 6 | sed -e 's:path-exclude /usr/share/groff:#&:' docker >docker.t ; \ 7 | mv docker.t docker ; \ 8 | cd ; \ 9 | apt-get update -y && \ 10 | apt-get install -y \ 11 | curl \ 12 | unzip \ 13 | groff \ 14 | less -y && \ 15 | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" ; \ 16 | unzip awscliv2.zip ; \ 17 | ./aws/install ; \ 18 | mkdir -p $WORKDIR $HOME/.aws 19 | COPY entrypoint.sh /usr/local/bin 20 | 21 | WORKDIR $WORKDIR 22 | 23 | ENTRYPOINT ["entrypoint.sh"] -------------------------------------------------------------------------------- /aws.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PROG=aws.sh 3 | DESC="Wrapper script for ncar/aws-cli docker container" 4 | AWS_CLI_VERSION=${AWS_CLI_VERSION:-latest} 5 | AWS_CLI_IMAGE=ncar/aws-cli:${AWS_CLI_VERSION} 6 | AWS_ENV_VARS=" 7 | AWS_ACCESS_KEY_ID 8 | AWS_SECRET_ACCESS_KEY 9 | AWS_SESSION_TOKEN 10 | AWS_DEFAULT_REGION 11 | AWS_DEFAULT_OUTPUT 12 | AWS_DEFAULT_PROFILE 13 | AWS_CA_BUNDLE 14 | AWS_SHARED_CREDENTIALS_FILE 15 | AWS_CONFIG_FILE" 16 | 17 | uid=`id -u` 18 | gid=`id -g` 19 | s=`docker info 2>&1 >/dev/null` 20 | case $s in 21 | *permission*denied*) 22 | DOCKER="sudo docker" ;; 23 | *) 24 | DOCKER="docker" ;; 25 | esac 26 | 27 | set ${AWS_CLI_IMAGE} "$@" 28 | if [ -d $HOME/.aws ] ; then 29 | set : --volume=$HOME/.aws:/home/.aws "$@" 30 | shift 31 | fi 32 | for var in ${AWS_ENV_VARS} ; do 33 | eval val="\"\$${var}\"" 34 | if [ ":${val}" != ":" ] ; then 35 | set : -e "${var}=${val}" "$@" 36 | shift 37 | fi 38 | done 39 | ${DOCKER} run -u $uid:$gid --rm -it --volume=`pwd`:/home/workdir "$@" | 40 | tr -d '\r' 41 | 42 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/python 6 | 7 | steps: 8 | - checkout 9 | 10 | - setup_remote_docker 11 | 12 | - run: 13 | name: Build 14 | command: | 15 | set -vxe 16 | docker build --progress plain -t ncar/aws-cli:latest . 17 | verstr=`docker run --rm ncar/aws-cli --version 2>&1` 18 | version=`expr "${verstr}" : 'aws-cli/\([^ ]*\) .*'` 19 | if [ ":${version}" = ":" ] ; then 20 | echo "Unable to determine version!" 21 | exit 1 22 | fi 23 | echo version=${version} 24 | docker tag ncar/aws-cli:latest ncar/aws-cli:${version} 25 | printenv DOCKERHUB_PASSWORD | docker login --username ${DOCKERHUB_USERNAME} --password-stdin 26 | docker push ncar/aws-cli 27 | 28 | workflows: 29 | version: 2 30 | 31 | update: 32 | jobs: 33 | - build: 34 | context: sweg 35 | 36 | weekly: 37 | triggers: 38 | - schedule: 39 | cron: "0 0 * * 0" 40 | filters: 41 | branches: 42 | only: 43 | - master 44 | jobs: 45 | - build: 46 | context: sweg 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS CLI 2 | 3 | This repo is used to build a simple Docker image containing the Amazon Web 4 | Services Command Line Interface. It can be used when you don't want to install 5 | the AWS CLI locally. 6 | 7 | The repo includes a CircleCI configuration that builds and pushes the Docker 8 | image to docker hub periodically, and when this source repo changes. The name 9 | of the docker hub repo is `ncar/aws-cli`. Images are tagged with the CLI 10 | version number, and the latest image is always tagged `latest`. 11 | 12 | To run the image, just use "docker run ncar/aws-cli" instead of "aws"; to 13 | be effective, you should either bind-mount a `~/.aws` directory with 14 | configuration and credentials files to `/root/.aws`, or pass needed environment 15 | variables into the container: 16 | 17 |   `docker run --rm --volume=$HOME/.aws:/root/.aws ncar/aws-cli` *aws_subcommand* 18 | 19 |   `docker run --rm -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY ncar/aws-cli` *aws_subcommand* 20 | 21 | 22 | Alternatively, you can use the `aws.sh` script included in this repo to run the 23 | docker container for you. It adds `--volume` and `-e` arguments for you, and 24 | also bind-mounts "`.`'" as the container's work directory. It sets the uid and 25 | gid in the container to your effective uid and gid, and tries to run docker 26 | using sudo if you don't have permission to run it directly. 27 | 28 | The `ncar/aws-cli` image itself can install the `aws.sh` for you. Just run the 29 | following: 30 | 31 | docker run --rm ncar/aws-cli --init-rc= | sh 32 | 33 | where `` is a writable local directory in your PATH. 34 | --------------------------------------------------------------------------------