cloudposse / geodesic

🚀 Geodesic is a DevOps Linux Toolbox in Docker
https://cloudposse.com/accelerate
Apache License 2.0
954 stars 122 forks source link

Can we look into what we can do to slim down the Geodesic image size? #702

Closed Gowiem closed 3 years ago

Gowiem commented 3 years ago

Describe the Feature

When building images on top of debian Geodesic, the resulting image size is ~12gb. This is painful to push a container registry. I'd like to know if there is anything we can do to slim down the size of the Geodesic base image.

Use Case

General use.

Describe Ideal Solution

Cut the image size in half? Provide ways for the consumer to slim down the size?

Alternatives Considered

N/A

Additional Context

Here is my Dockerfile which produces a 11.9gb image:

ARG VERSION=latest
ARG OS=debian
ARG CLI_NAME=toolbox

FROM cloudposse/geodesic:$VERSION-$OS

# Move AWS CLI v1 to aws1 and set up alternatives
RUN mv /usr/local/bin/aws /usr/local/bin/aws1 && \
  update-alternatives --install /usr/local/bin/aws aws /usr/local/bin/aws1 1

# Install AWS CLI 2
# Get version from https://github.com/aws/aws-cli/blob/v2/CHANGELOG.rst
ARG AWS_CLI_VERSION=2.1.34
RUN AWSTMPDIR=$(mktemp -d -t aws-inst-XXXXXXXXXX) && \
  curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip" -o "$AWSTMPDIR/awscliv2.zip" && \
  cd $AWSTMPDIR && \
  unzip -qq awscliv2.zip && \
  ./aws/install -i /usr/share/aws/v2 -b /usr/share/aws/v2/bin && \
  update-alternatives --install /usr/local/bin/aws aws /usr/share/aws/v2/bin/aws 2 && \
  rm -rf $AWSTMPDIR

# Install terraform 0.13 + 0.14
RUN apt-get update && apt-get install -y -u terraform-0.13 terraform-0.14
# Set Terraform 0.14.x as the default `terraform`.
RUN update-alternatives --set terraform /usr/share/terraform/0.14/bin/terraform

# Install Atmos + Vendir
RUN apt-get install -y --allow-downgrades \
  atmos \
  vendir \
  packer

# Shell banner
ENV BANNER="Toolbox"

# Geodesic message of the Day, which we override via rootfs/etc/motd
ENV MOTD_URL=""

ENV AWS_VAULT_BACKEND=file

ENV DOCKER_IMAGE="toolbox"
ENV DOCKER_TAG="latest"

COPY rootfs/ / # Very little is in rootfs/

WORKDIR /
Nuru commented 3 years ago

@Gowiem I don't know what you are doing to cause this. Our published Alpine image is around 2.25 GB and our Debian image is around 3 GB. Our client images, built on top of Geodesic in a fashion similar to what your Dockerfile looks like, add around 0.5 GB to the image. My guess is that you do not have a proper .dockerignore file. We recommend this as a start:

.dockerignore ``` # Things that could be checked into Git but need not be in the Docker image .git .editorconfig # Below here should be pretty much a copy of .gitignore .build-harness build-harness/ aws-assumed-role/ .idea/ *.iml # Compiled and auto-generated files **/nohup.out **/*.tfstate **/*.tfstate.* **/planfile **/*.planfile **/*.kubeconfig **/terraform.tfvars.json **/terraform.auto.tfvars.json **/*.terraform.tfvars.json **/*.terraform.auto.tfvars.json **/*.helmfile.vars.yaml **/crash.log # Module directory **/.terraform/ **/.module/ **/.helmfile/ # Draft or auto-saved version # Note that the leading "**/" appears necessary for Docker even if not for Git **/*.draft.* **/*.draft **/*.orig **/*.bak **/*~ # macOS and Windows special files and folders **/.DS_Store **/.CFUserTextEncoding **/.Trash/ **/$RECYCLE.BIN/ ```
Gowiem commented 3 years ago

@Nuru huh. Let me look into that. I wouldn't think it would be something in the directory that I'm building the image in, but I very well could be wrong. I'll get back with more info.

Gowiem commented 3 years ago

@Nuru must have been the Dockerignore -- adding that fixed it 👍

nitrocode commented 5 months ago

Even tho I see the issue was dockerignore here. Just wanted to add that Nuru merger pr #945 which lead to a smaller debian image of geodesic in release 3.0.0!

https://github.com/cloudposse/geodesic/releases/tag/3.0.0

Nuru commented 5 months ago

Additional slim down in:

Also note that the arm64 image is significantly smaller than the amd64 image.