-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.Dockerfile
More file actions
110 lines (94 loc) · 3.26 KB
/
python.Dockerfile
File metadata and controls
110 lines (94 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
FROM ubuntu:22.04
# Set environment variables
ENV PYENV_ROOT="/root/.pyenv" \
PATH="/root/.pyenv/bin:/root/.pyenv/shims:/root/.pyenv/versions/3.12.0/bin:$PATH" \
DEBIAN_FRONTEND=noninteractive
# Install system dependencies and additional tools
RUN adduser --force-badname --system --no-create-home _apt \
&& apt-get update -yqq \
&& apt-get install -yqq \
python3 \
python3-pip \
curl \
wget \
tree \
zip \
unzip \
git \
software-properties-common \
build-essential \
zlib1g-dev \
libssl-dev \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
liblzma-dev \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
llvm \
libxml2-dev \
libxmlsec1-dev
# CSV with version and release of python-build-standalone: https://github.com/astral-sh/python-build-standalone
# FIXME: Consider bumping the patch versions of these one day to support `install_only_stripped`
COPY <<EOF /tmp/python-versions.csv
3.13.1,20241205
3.12.0,20231002
3.11.7,20240107
3.10.13,20240224
3.9.18,20240224
3.8.18,20240224
EOF
# Install Pyenv and multiple Python versions
RUN set -eu; \
git clone https://github.com/pyenv/pyenv.git $PYENV_ROOT; \
ARCH=$(uname -m); \
DOWNLOADS="https://github.com/astral-sh/python-build-standalone/releases/download"; \
while IFS="," read -r VERSION RELEASE; do \
mkdir -p "$PYENV_ROOT/versions/$VERSION"; \
wget --quiet "$DOWNLOADS/$RELEASE/cpython-$VERSION+$RELEASE-$ARCH-unknown-linux-gnu-install_only.tar.gz" \
-O "/tmp/$VERSION.tar.gz"; \
tar -xzf "/tmp/$VERSION.tar.gz" \
-C "$PYENV_ROOT/versions/$VERSION" \
--strip-components=1; \
ln -frs "$PYENV_ROOT/versions/$VERSION/bin/python${VERSION%.*}" \
"$PYENV_ROOT/versions/$VERSION/bin/python"; \
rm "/tmp/$VERSION.tar.gz"; \
done < /tmp/python-versions.csv; \
pyenv rehash
# Install miniconda
ENV CONDA_DIR=/opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-py313_25.3.1-1-Linux-$(uname -m).sh -O /tmp/miniconda.sh \
&& /bin/bash /tmp/miniconda.sh -b -p /opt/conda \
&& rm /tmp/miniconda.sh
# Put conda in path so we can use conda activate
ENV PATH=$CONDA_DIR/bin:$PATH
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - \
&& ln -s /root/.local/bin/poetry /usr/bin/poetry
# Install uv
RUN pip install --no-cache-dir uv
# Install Pyright and other Python tools
RUN pip install --no-cache-dir pyright \
&& pip install search-and-replace \
&& pip install pipenv
# Install Node.js and jq
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs jq
# Remove lists
RUN rm -rf /var/lib/apt/lists/*
# Create and set working directory
RUN mkdir -p /data/project
WORKDIR /data/project
# Make conda always say yes to prompts
ENV CONDA_ALWAYS_YES=true
# Global pyenv versions:
# python3.13 points to 3.13.5, python3.12 points to 3.12.11, ...
RUN pyenv global $(cut -d"," -f1 /tmp/python-versions.csv | tr "\n" " ") \
&& rm /tmp/python-versions.csv
# Conda init bash
RUN conda init bash
# Set default shell to bash
CMD ["/bin/bash"]