Skip to content

Add Dockerfile with minimal supported Python version (3.10) #16

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tchemineau
Copy link
Contributor

Description

The idea is to provide a minimal Dockerfile to build a container image that can run stacks tool properly.

I would like to reuse that mechanism to eventually publish the container image to docker hub, and use it in the CI to do some more advanced testing.

For my use-case, I found out the result container image very useful to quickly run stacks encrypt command line.

Let me know your thought, and if that could be useful.

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@tchemineau tchemineau requested a review from a team as a code owner May 23, 2025 20:29
@ribejara-te
Copy link
Collaborator

ribejara-te commented May 27, 2025

This is an interesting addition to the repo, however:

  • We don't currently have plans to support the pipeline and registry to build it automatically, so users may build the image themselves if they want to use it.
  • The current Dockerfile as it stands has several number of flaws, I'll put those in inline code review comments.

Otherwise, we're open to accepting this, thanks for your contribution!

Comment on lines +4 to +7
ca-certificates \
curl \
git \
unzip \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ca-certificates: we shouldn't need to install anymore than what the image includes, unless you're telling me it doesn't have any, then this is acceptable. Have we verified that or is this cargo-culted, is my ask.
  • curl: doesn't look like we're using cURL anywhere in this Dockerfile, if so, please remove it.
  • git: all we're using GIt is to download ASDF, for which I'll add comments later.
  • unzip: same as cURL, we aren't using it so this just bloats the image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review,

  • curl is used by ASDF to download latest Terraform available version. We can decide to get rid of it or keep it in the image so that the user can eventually update its Terraform version
  • git is used by both the ASDF installation and the stacks tools as well (hosted on GitHub). Good point, this might be removed after
  • unzip is used by ASDF during when installation Terraform version and also by the installation of the stacks tool (mainly by some Python dependencies, but not sure)

For ca-certificates, I can't recall, but I think I got TLS warning preventing me to download from GitHub and all Python module dependencies.

For most of them, true, we can decide if we want to keep them or not.

Let me know what you'd prefer.

@@ -0,0 +1,32 @@
FROM python:3.10-slim
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FROM python:3.10-slim
FROM docker.io/python:3.10-slim

Comment on lines +11 to +12
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rm -rf /var/lib/apt/lists/* is all you need here, but I might be wrong on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to purge all installed dependencies pull from the packages we want, as well as unused packages. This is what the line 11 does.

I might have kept the line 11 because I found out that there was no need to uninstall tools provisioned for installation what we want (stacks and ASDF).

Comment on lines +14 to +28
ARG ASDF_VERSION="v0.16.7"
ENV ASDF_DATA_DIR="/opt/asdf-data"
ENV ASDF_INSTALL_DIR="/opt/asdf"
ENV PATH="${ASDF_DATA_DIR}/shims:${ASDF_INSTALL_DIR}/bin:${PATH}"

RUN git clone \
--branch "${ASDF_VERSION}" \
--depth=1 \
https://github.com/asdf-vm/asdf.git "${ASDF_INSTALL_DIR}" \
&& asdf --help

RUN asdf plugin add tfswitch \
&& asdf install tfswitch latest \
&& asdf global tfswitch latest \
&& tfswitch --latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong to Stacks and shouldn't be part of this image.

May I suggest removing this from the Stacks Dockerfile and then building an image FROM stacks that adds these tools if you need them? Otherwise we're bloating the image with unrelated stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need Terraform for running stacks ?

Indeed, tfswitch is not needed. It is only a convenient way to get the latest version of Terraform. I can uninstall it, definitely.

&& asdf global tfswitch latest \
&& tfswitch --latest

RUN apt-get update \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apt-get update is unnecessary and defeats the purpose of the rm -rf /var/lib/apt/lists/* above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean ? If there is no cache file in /var/lib/apt/lists/, you can't run an apt-get install command if you did not run an apt-get update before to get updated lists.

&& tfswitch --latest

RUN apt-get update \
&& pip install git+https://github.com/tchemineau/cisco-thousandeyes-stacks.git@provides-dockerfile \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's switch to uv instead of pip, it's what we want to primarily support going forward (even though we're keeping pip compatibility.
  • This line installs stacks from your own branch on your own fork, we want to use the code in the Docker build context instead so this Dockerfile is not bound to (1) any network services, like GitHub; (2) any specific Git repository; and (3) any specific Git branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Good point for the URL. Only submitted to get a review first, indeed this should be from master repo.

@@ -9,7 +9,6 @@ dependencies = [
"cryptography>=43.0.3",
"deepmerge>=2.0",
"gitpython>=3.1.43",
"importlib>=1.0.4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing importlib here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the installation of the stacks tool using pip3 fails otherwise on dependency requirements.

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.

2 participants