Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Dockerfile and narrow context #580

Closed

Conversation

aiven-anton
Copy link
Contributor

@aiven-anton aiven-anton commented Apr 10, 2023

About this change - What it does

  • Move to using Python base images for builder and final stage. This allows omitting installation of some build tools. It also allows moving to a more recent Python version, no longer being bound by what's in distro repositories. Wheel availability of some of our Python dependencies prevents us from moving to 3.11 for now.
  • Change installation approach to construct a virtualenv in the builder step, and copying it unaltered to the final stage, with dependencies and Karapace itself installed in it. This allows having even fewer layers in the final stage, and is simpler.
  • Introduces a much stricter .dockerignore, ignoring files by default and explicitly including what's required. This makes sure changes in unrelated files does not evict layer cache. For example, a few files that previously erroneously evicted caches, because everything was included:
    • .git/*
    • .mypy_cache/*
    • container/Dockerfile itself
    • __pycache__/*
    • .idea/*

Image size remains the about the same as previously, but slightly reduced (the karapace-dev tag is the new version):

$ docker image ls
REPOSITORY                           TAG               IMAGE ID       CREATED          SIZE
karapace-dev                         latest            b31c7d811294   10 seconds ago   194MB
ghcr.io/aiven/karapace               develop           b8366c494bec   5 days ago       204MB
ghcr.io/aiven/karapace               latest            ef8485cb1181   3 weeks ago      203MB

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 10, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0ecb0e0
Status: ✅  Deploy successful!
Preview URL: https://9a7c7fdd.karapace.pages.dev
Branch Preview URL: https://chore-simplify-dockerfile.karapace.pages.dev

View logs

- Use cache mounts for pip and apt, heavily reducing network requests
  when cache is warm.
- Remove git as a build-time dependency, other than switching to archive
  endpoints as was done in 39b4f08, this also requires either setting
  `KARAPACE_VERSION` as container build arg or building
  karapace/version.py independently.
- Add hadolint pre-commit check for linting Dockerfile.
- Pin all apt dependencies (hadolint rule).
@aiven-anton aiven-anton changed the base branch from main to chore/optimize-container-build May 4, 2023 16:26
- Move to using Python base images for builder and final stage. This
  allows omitting installation of some build tools. It also allows
  moving to a more recent Python version, no longer being bound by
  what's in distro repositories. Wheel availability of some of our
  Python dependencies prevents us from moving to 3.11 for now.
- Change installation approach to construct a virtualenv in the builder
  step, and copying it unaltered to the final stage, with dependencies
  and Karapace itself installed in it. This allows having even fewer
  layers in the final stage, and is simpler.
- Introduces a _much_ stricter .dockerignore, ignoring files by default
  and explicitly including what's required. This makes sure changes in
  unrelated files does not evict layer cache. For example, a few files
  that previously erroneously evicted caches, because everything was
  included:
  - .git/*
  - .mypy_cache/*
  - container/Dockerfile itself
  - __pycache__/*
  - .idea/*
@aiven-anton aiven-anton force-pushed the chore/optimize-container-build branch from 0e0ce92 to 793e204 Compare May 4, 2023 16:30
@aiven-anton aiven-anton closed this May 4, 2023
@aiven-anton aiven-anton deleted the chore/simplify-dockerfile branch May 4, 2023 16:30
@aiven-anton
Copy link
Contributor Author

Closed in favor of #579.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant