slimtoolkit / slimtoolkit/slim

Slim Images Sometimes Bigger than Regular Images

Open
#301 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
23.4k
Forks
840
PR merge metrics
No merged PRs in 30d

Description

Sometimes the slim image ends up being bigger than the regular image but I'm not sure why. Here's what I'm doing:

Dockerfile

FROM alpine:3 AS build

RUN apk --no-cache add \
  bc~=1 \
  cargo~=1 \
  gcc~=10 \
  libffi-dev~=3 \
  musl-dev~=1 \
  openssl-dev~=1 \
  python3~=3 \
  python3-dev~=3 \
  py3-pip~=20 \
  rust~=1 \
  && pip3 install --no-cache-dir \
  "ansible==3.*" \
  && pip3 install --no-cache-dir --no-compile \
  "ansible-lint==5.*"

FROM alpine:3 AS codeclimate

ENV container docker

WORKDIR /work

COPY --from=build /usr/lib/python3.9/site-packages/ /usr/lib/python3.9/site-packages/
COPY --from=build /usr/bin/ansible-lint /usr/bin/ansible-lint
COPY --from=build /usr/bin/ansible /usr/bin/ansible
COPY --from=build /usr/bin/ansible-connection /usr/bin/ansible-connection
COPY local/engine.json ./engine.json
COPY local/codeclimate-ansible-lint local/codeclimate-format.py /usr/local/bin/

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN adduser --uid 9000 --gecos "" --disabled-password app \
  && apk --no-cache add --virtual build-deps \
  jq~=1 \
  && apk --no-cache add \
  git~=2 \
  python3~=3 \
  && ln -sf ansible /usr/bin/ansible-config \
  && ln -sf ansible /usr/bin/ansible-console \
  && ln -sf ansible /usr/bin/ansible-doc \
  && ln -sf ansible /usr/bin/ansible-galaxy \
  && ln -sf ansible /usr/bin/ansible-inventory \
  && ln -sf ansible /usr/bin/ansible-playbook \
  && ln -sf ansible /usr/bin/ansible-pull \
  && ln -sf ansible /usr/bin/ansible-test \
  && ln -sf ansible /usr/bin/ansible-vault \
  && find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
  && find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf \
  && VERSION="$(ansible-lint --version | sed 's/^[^ ]* //' | sed 's/ .*$//')" \
  && jq --arg version "$VERSION" '.version = $version' > /engine.json < ./engine.json \
  && rm ./engine.json \
  && apk del build-deps

USER app

VOLUME /code
WORKDIR /code

CMD ["codeclimate-ansible-lint"]

ARG BUILD_DATE
ARG REVISION
ARG VERSION

LABEL maintainer="Megabyte Labs <help@megabyte.space>"
LABEL org.opencontainers.image.authors="Brian Zalewski <brian@megabyte.space>"
LABEL org.opencontainers.image.created=$BUILD_DATE
LABEL org.opencontainers.image.description="An Ansible Lint slim container and a CodeClimate engine container for GitLab CI"
LABEL org.opencontainers.image.documentation="https://github.com/ProfessorManhattan/codeclimate-ansible-lint/blob/master/README.md"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.revision=$REVISION
LABEL org.opencontainers.image.source="https://gitlab.com/megabyte-labs/docker/codeclimate/ansible-lint.git"
LABEL org.opencontainers.image.url="https://megabyte.space"
LABEL org.opencontainers.image.vendor="Megabyte Labs"
LABEL org.opencontainers.image.version=$VERSION
LABEL space.megabyte.type="codeclimate"

FROM codeclimate AS ansible-lint

WORKDIR /work

USER root

RUN rm /engine.json /usr/local/bin/codeclimate-ansible-lint /usr/local/bin/codeclimate-format.py

ENTRYPOINT ["ansible-lint"]
CMD ["--version"]

LABEL space.megabyte.type="linter"

Build Command

docker build --build-arg BUILD_DATE=2022-03-21T05:04:32-04:00 --build-arg REVISION=449fae9486c1865ac08320b9cd70f12a7908ab70 --build-arg VERSION=5.4.0 --tag megabytelabs/ansible-lint:latest  --target ansible-lint .

Slim Command

docker-slim build --tag megabytelabs/ansible-lint:slim  --http-probe=false --exec "ansible-lint --version" --preserve-path-file "local/paths.txt" megabytelabs/ansible-lint:latest

Logs

docker-slim: message='join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'
docker-slim: message='join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
docker-slim: message='Github discussions' info='https://github.com/docker-slim/docker-slim/discussions'
cmd=build info=exec message='changing continue-after from probe to nothing because http-probe is disabled' 
cmd=build info=exec message='updating continue-after mode to exec' 
cmd=build state=started
cmd=build info=params continue.mode='exec' rt.as.user='true' keep.perms='true' tags='megabytelabs/ansible-lint:slim' target.type='image' target='megabytelabs/ansible-lint:latest' 
cmd=build state=image.inspection.start
cmd=build info=image id='sha256:31efc3f2e48115837fba76f077684cefd1fb2c552db60b534b53cc1f14649a8c' size.bytes='379494236' size.human='380 MB' 
cmd=build info=image.stack name='alpine:3' id='sha256:c059bfaa849c4d8e4aecaeb3a10c2d9b3d85f5165c66ad3a4d937758128c4d18' index='0' 
cmd=build info=image.stack name='codeclimate/codeclimate-ansible-lint:latest' id='sha256:78dc182a27e7defbd1e4b889f235f90c2b72b31ae345ad8f8ca3ad861cf2bbbf' index='1' 
cmd=build info=image.stack index='2' name='megabytelabs/ansible-lint:5-latest' id='sha256:31efc3f2e48115837fba76f077684cefd1fb2c552db60b534b53cc1f14649a8c' 
cmd=build state=image.inspection.done
cmd=build state=container.inspection.start
cmd=build info=container status='created' name='dockerslimk_1024221_20220321105226' id='81e3473986369369629ac9a38c4ff6be65918c12870a23891c058dc40bac2e19' 
cmd=build info=cmd.startmonitor status='sent' 
cmd=build info=event.startmonitor.done status='received' 
cmd=build info=container target.port.info='' message='YOU CAN USE THESE PORTS TO INTERACT WITH THE CONTAINER' name='dockerslimk_1024221_20220321105226' id='81e3473986369369629ac9a38c4ff6be65918c12870a23891c058dc40bac2e19' target.port.list='' 
cmd=build info=continue.after mode='exec' message='provide the expected input to allow the container inspector to continue its execution' 
cmd=build info=continue.after mode='exec' shell='ansible-lint --version' 
docker-slim[build][exec]: output: ansible-lint 5.4.0 using ansible 2.10.17
cmd=build info=continue.after exitcode='0' mode='exec' 
cmd=build state=container.inspection.finishing
cmd=build state=container.inspection.artifact.processing
cmd=build state=container.inspection.done
cmd=build state=building message=building optimized image 
cmd=build state=completed
cmd=build info=results status='MINIFIED' by='0.89X' size.original='380 MB' size.optimized='428 MB' 
cmd=build info=results image.name='megabytelabs/ansible-lint:slim' image.size='428 MB' has.data='true' 
cmd=build info=results artifacts.location='/tmp/docker-slim-state/.docker-slim-state/images/31efc3f2e48115837fba76f077684cefd1fb2c552db60b534b53cc1f14649a8c/artifacts' 
cmd=build info=results artifacts.report='creport.json' 
cmd=build info=results artifacts.dockerfile.reversed='Dockerfile.fat' 
cmd=build info=results artifacts.dockerfile.optimized='Dockerfile' 
cmd=build info=results artifacts.seccomp='megabytelabs-ansible-lint-seccomp.json' 
cmd=build info=results artifacts.apparmor='megabytelabs-ansible-lint-apparmor-profile' 
cmd=build state=done
cmd=build info=commands message='use the xray command to learn more about the optimize image' 
cmd=build info=version status='OUTDATED' local='1.37.2' current='1.37.5' 
cmd=build message='Your version of DockerSlim is out of date! Use the "update" command or download the new version from https://dockersl.im/downloads.html'
cmd=build info=report file='slim.report.json' 
docker-slim: message='join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'
docker-slim: message='join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
docker-slim: message='Github discussions' info='https://github.com/docker-slim/docker-slim/discussions'

Is there something I am doing wrong? Or maybe we can have slim return the regular image if the slim image is bigger than the regular one?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the supplied Dockerfile, build command, and DockerSlim command, then inspect the generated slim.report.json and optimized image results. Trace how the optimization result is measured and reported, and define completion as handling cases where the optimized image exceeds the original without regressing normal minification.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.