Skip to content

Instantly share code, notes, and snippets.

@rstms
Forked from skyzyx/Dockerfile
Created October 12, 2021 07:23
Show Gist options
  • Save rstms/82bf2c87f49a529e8f0fb94e77674a59 to your computer and use it in GitHub Desktop.
Save rstms/82bf2c87f49a529e8f0fb94e77674a59 to your computer and use it in GitHub Desktop.
AWS CLI v2 for Alpine Linux

AWS CLI v2 for Alpine Linux

I got tired of waiting for #5578, so I did it myself.

Building

You need to have Docker and Docker Compose installed locally. It will take several minutes to run.

make run

The end result should be two .whl files in this directory.

Docker Troubleshooting

If there are space or I/O errors, try running the following, then try again:

docker image prune -a -f && \
docker system prune --volumes -f

Installation

apk add alpine-sdk git libffi-dev openssh openssl-dev py3-pip python3-dev
pip install botocore*.whl
pip install awscli*.whl
version: "3.8"
services:
builder:
build:
context: .
dockerfile: Dockerfile
network: host
image: aws-cli-v2-alpine-builder:latest
volumes:
- $PWD:/workspace
FROM alpine:3.12
RUN apk add make util-linux
WORKDIR /workspace
ENTRYPOINT ["make", "compile"]
#-------------------------------------------------------------------------------
# Global variables.
AWSCLI_VERSION=2.1.9
BOTOCORE_VERSION=da21506af7f56e6a39643178cbd73790a963ba3b
#-------------------------------------------------------------------------------
# Running `make` will show the list of subcommands that will run.
all: help
.PHONY: help
## help: prints this help message
help:
@echo "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
#-------------------------------------------------------------------------------
.PHONY: run
## run: Boots an Alpine Linux container for performing the compilation.
run:
docker-compose up
.PHONY: compile
## compile: Fetches the source code and compiles an installable .whl file. Runs automatically from inside the container.
compile:
mkdir -p /workspace/.cache
apk add alpine-sdk git libffi-dev openssh openssl-dev py3-pip python3-dev
pip install --ignore-installed virtualenv && virtualenv .venv
source .venv/bin/activate && \
if [ ! -d /workspace/.cache/botocore ]; then git clone https://github.com/boto/botocore.git /workspace/.cache/botocore; fi && \
cd /workspace/.cache/botocore && \
git checkout $(BOTOCORE_VERSION) && \
pip install --ignore-installed -r requirements.txt && \
python3 setup.py bdist_wheel && \
cp -vf /workspace/.cache/botocore/dist/botocore*.whl /workspace
source .venv/bin/activate && \
if [ ! -d /workspace/.cache/aws-cli ]; then git clone https://github.com/aws/aws-cli.git /workspace/.cache/aws-cli; fi && \
cd /workspace/.cache/aws-cli && \
git checkout $(AWSCLI_VERSION) && \
pip install --ignore-installed -r requirements.txt && \
python3 setup.py install && \
echo "============> THIS WILL TAKE SEVERAL MINUTES <============" && \
python3 scripts/gen-ac-index --include-builtin-index && \
python3 setup.py bdist_wheel && \
cp -vf /workspace/.cache/aws-cli/dist/awscli*.whl /workspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment