How to get AWS-CLI v2 down from 127M to 67M

Take these steps:

FROM alpine:3.12

# install glibc compatibility for alpine
RUN apk --no-cache add binutils \
    && echo "getting libc libraries" \
    && curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \
    && curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \
    && curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \
    && echo "installing libc libraries" \
    && apk add --no-cache \
        glibc-${GLIBC_VER}.apk \
        glibc-bin-${GLIBC_VER}.apk \
    && echo "installing of rush parallel runner (temporary)" \
    && curl -sSfL https://github.com/shenwei356/rush/releases/download/v0.4.2/rush_linux_amd64.tar.gz  -o - \
        | tar -C /tmp/ -zxf - \
    && echo "installing AWS CLI" \
    && curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
    && unzip awscliv2.zip \
        -x 'aws/dist/awscli/examples/**' 'aws/dist/docutils/**'\
    && aws/install  \
    && echo "Cleaning and sliming AWS CLI installation" \
    && rm -rvf \
        awscliv2.zip \
        aws \
        /usr/local/aws-cli/v2/*/dist/aws_completer \
        /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
        /usr/local/aws-cli/v2/*/dist/awscli/examples \
    && find /usr/local/aws-cli/v2/current/dist/botocore/data/ -name "*.json" -name "examples*" -exec rm {} \; \
    && find /usr/local/aws-cli/v2/current/dist/botocore/data/ -name "*.json" \
        | /tmp/rush 'echo "optimizing {}"; jq -cer "del(.. | .documentation?)" "{}" > "{}.tmp" && mv "{}.tmp" "{}"' \
    && echo "Removing artificats" \
    && rm /tmp/rush \
    && apk --no-cache del \
        binutils \
    && rm glibc-${GLIBC_VER}.apk \
    && rm glibc-bin-${GLIBC_VER}.apk \
    && rm -rf /var/cache/apk/*

I do think there can be much more improved in botocore (like compressing assets) or just rewritting AWS CLI to Golang. I hope if an v3 hits the floor it is in Golang (for the easy of use; go sdk is already very powerful and maybe there is an alternative client – but would be fine if that is 100% compatible to AWS CLI).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.