feat(dockerfile): install Python 3.11 via Miniconda in CI base image#4759
feat(dockerfile): install Python 3.11 via Miniconda in CI base image#4759wuhuizuo wants to merge 1 commit into
Conversation
Add Miniconda-based Python 3.11 installation to the CI base Dockerfile. This provides tomllib support needed by ticdc PR #5357. - Install Miniconda to /opt/miniconda - Create python=3.11 conda environment - Symlink python3.11 to /usr/local/bin - Add /opt/miniconda/bin to PATH Signed-off-by: wuhuizuo <wuhuizuo@126.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
I have already done a preliminary review for you, and I hope to help you do a better job.
Summary
This PR enhances the CI base Docker image by installing Python 3.11 through Miniconda, enabling the use of the tomllib module required by ticdc. The approach uses a Miniconda installer script based on architecture, installs Python 3.11 via conda, symlinks the python3.11 executable, and updates the PATH environment variable. The implementation is straightforward and logically isolated from existing Python installations, which is good. Overall, the change looks functional but could benefit from some improvements around layer caching, idempotency, and minor hygiene.
Critical Issues
-
Layer Caching and Image Size
-
File:
dockerfiles/ci/base/Dockerfile(lines 18-28) -
Issue: The current RUN command downloads the Miniconda installer, installs Python 3.11, and cleans up the installer in one layer which is good. However, the
conda installstep will fetch a large environment and potentially update conda itself, which can lead to a large image size and slow rebuilds. -
Suggestion: Consider pinning the Miniconda installer version instead of
Miniconda3-latestto avoid unexpected changes breaking the build. Also, addconda clean -afyafter installation to reduce image size:RUN ARCH=$([ "$(arch)" = "x86_64" ] && echo x86_64 || echo aarch64); \ wget "https://repo.anaconda.com/miniconda/Miniconda3-py311_23.3.1-Linux-${ARCH}.sh" -O /tmp/miniconda.sh && \ bash /tmp/miniconda.sh -b -p /opt/miniconda && \ rm /tmp/miniconda.sh && \ /opt/miniconda/bin/conda install -y python=3.11 && \ /opt/miniconda/bin/conda clean -afy && \ ln -s /opt/miniconda/bin/python3.11 /usr/local/bin/python3.11
-
-
Symlink Safety and PATH Precedence
-
File:
dockerfiles/ci/base/Dockerfile(line 27-28) -
Issue: Symlinking
python3.11is good, but the Dockerfile adds/opt/miniconda/binto the front of PATH viaENV. This means the defaultpythonandpython3will point to Miniconda’s versions, possibly interfering with existing workflows. This conflicts with the PR description that says no interference is expected. -
Suggestion: If you want to avoid overriding default python commands, consider adding only the symlink and avoid prepending Miniconda to PATH. Alternatively, use a dedicated environment or explicit calls to
/usr/local/bin/python3.11. For example:ENV PATH=/opt/miniconda/bin:$PATH # or avoid adding PATH and rely on symlink only
Confirm this aligns with your risk assessment.
-
Code Improvements
-
Architecture Detection Logic
-
File:
dockerfiles/ci/base/Dockerfile(line 18) -
Issue: The
archcheck only considersx86_64and assumes anything else isaarch64. This may fail on other architectures or if thearchoutput differs (e.g.,amd64on some systems). -
Suggestion: Use a more robust detection (e.g.,
uname -m), and add a fallback or error for unsupported arch:RUN ARCH=$(uname -m); \ if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then ARCH=x86_64; \ elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then ARCH=aarch64; \ else echo "Unsupported architecture: $ARCH" && exit 1; fi; \ # continue with wget...
-
-
Explicit Python Version Pinning
- File:
dockerfiles/ci/base/Dockerfile(line 24) - Issue:
conda install -y python=3.11installs the latest patch of 3.11, which could break reproducibility over time. - Suggestion: Pin to a specific minor version, e.g.,
python=3.11.4, to ensure stable builds.
- File:
Best Practices
-
Documentation / Comments
- File:
dockerfiles/ci/base/Dockerfile(line 17-28) - Issue: The new RUN block has only a minimal comment.
- Suggestion: Add more detailed comments explaining why Miniconda is installed, the rationale behind symlinking, and the PATH modification. This will help future maintainers.
- File:
-
Testing Coverage
- General
- Issue: The PR description mentions manual verification commands but no automated tests or CI steps validating the Python 3.11 environment or
tomllibimport. - Suggestion: Add a minimal test in the CI pipeline that runs
python3.11 -c "import tomllib"or checks the Python version to catch regressions early.
-
Style / Formatting
-
File:
dockerfiles/ci/base/Dockerfile -
Issue: The backslashes in the RUN command could be aligned for readability (e.g., one argument per line).
-
Suggestion: Format as:
RUN ARCH=... && \ wget ... && \ bash ... && \ rm ... && \ /opt/miniconda/bin/conda install -y python=3.11 && \ ln -s ...
-
Overall, this is a useful and needed enhancement. Addressing caching, reproducibility, and architecture detection will improve robustness and maintainability. Adding minimal tests and clarifying PATH usage will reduce unexpected side effects.
Summary
Add Miniconda-based Python 3.11 installation to the CI base Dockerfile. This provides
tomllibsupport needed by ticdc (PR #5357).Changes
/opt/minicondapython=3.11via condapython3.11to/usr/local/bin/python3.11/opt/miniconda/bintoPATHTesting
/opt/miniconda/bin/python3.11 --versiontomllibimport works:python3.11 -c "import tomllib"Risk
Low. Miniconda is installed in a separate directory (
/opt/miniconda) and does not interfere with existingpython27/python3system packages. The symlink is to a newpython3.11binary that doesn't conflict with existingpythonorpython3commands.Ref: FLA-231