Skip to content

Commit e4f0a2c

Browse files
authored
Merge pull request #45 from deepnote/ach/fix-installation-python
Fix installation python
2 parents 44f4e99 + 173fbfd commit e4f0a2c

File tree

7 files changed

+498
-93
lines changed

7 files changed

+498
-93
lines changed

.circleci/config.yml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ orbs:
55
docker: circleci/docker@2.8
66

77
commands:
8-
split_python_version:
9-
steps:
10-
- run:
11-
name: Split python version
12-
command: |
13-
echo "export PYTHON_VERSION=$(echo $PYTHON_VERSION_PATCH | cut -d'.' -f1,2)" >> $BASH_ENV
14-
source $BASH_ENV
158
setup_buildkit_builder:
169
steps:
1710
- run:
@@ -69,25 +62,23 @@ jobs:
6962
python-version:
7063
type: string
7164
environment:
72-
PYTHON_VERSION_PATCH: << parameters.python-version >>
65+
PYTHON_VERSION: << parameters.python-version >>
7366
steps:
7467
- checkout
7568
- docker_login
76-
- split_python_version # This provides PYTHON_VERSION
7769
- setup_buildkit_builder
7870
- run:
7971
name: Build and push python image
8072
command: |
8173
REPOSITORY="deepnote/python"
8274
TAG="${PYTHON_VERSION}"
8375
TAG_SUFFIX="${CIRCLE_PULL_REQUEST:+-ra-${CIRCLE_PULL_REQUEST##*/}}"
76+
8477
docker buildx build \
85-
--file=./python/python/Dockerfile.python \
78+
--file=./python/python/Dockerfile.python${PYTHON_VERSION} \
8679
--tag=978928340082.dkr.ecr.us-east-1.amazonaws.com/${REPOSITORY}:${TAG}${TAG_SUFFIX} \
8780
--tag=docker.io/${REPOSITORY}:${TAG}${TAG_SUFFIX} \
8881
--build-arg CIRCLE_PULL_REQUEST=${CIRCLE_PULL_REQUEST} \
89-
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
90-
--build-arg PYTHON_VERSION_PATCH=${PYTHON_VERSION_PATCH} \
9182
--cache-from type=registry,ref=docker.io/${REPOSITORY}:${TAG}-buildcache \
9283
--cache-from type=registry,ref=docker.io/${REPOSITORY}:${TAG}${TAG_SUFFIX}-buildcache \
9384
--cache-to type=registry,ref=docker.io/${REPOSITORY}:${TAG}${TAG_SUFFIX}-buildcache,mode=max,image-manifest=true,oci-mediatypes=true \
@@ -105,11 +96,10 @@ jobs:
10596
python-version:
10697
type: string
10798
environment:
108-
PYTHON_VERSION_PATCH: << parameters.python-version >>
99+
PYTHON_VERSION: << parameters.python-version >>
109100
steps:
110101
- checkout
111102
- docker_login
112-
- split_python_version # This provides PYTHON_VERSION
113103
- setup_buildkit_builder
114104
- run:
115105
name: Build and push python-datascience image
@@ -140,11 +130,10 @@ jobs:
140130
python-version:
141131
type: string
142132
environment:
143-
PYTHON_VERSION_PATCH: << parameters.python-version >>
133+
PYTHON_VERSION: << parameters.python-version >>
144134
steps:
145135
- checkout
146136
- docker_login
147-
- split_python_version # This provides PYTHON_VERSION
148137
- setup_buildkit_builder
149138
- run:
150139
name: Build and push python-conda image
@@ -275,10 +264,10 @@ jobs:
275264
./gpu
276265
277266
python-versions: &python-versions
278-
- "3.8.19"
279-
- "3.9.19"
280-
- "3.10.15"
281-
- "3.11.10"
267+
- "3.8"
268+
- "3.9"
269+
- "3.10"
270+
- "3.11"
282271

283272
r-versions: &r-versions
284273
- "4.0.4"
@@ -316,7 +305,7 @@ workflows:
316305
parameters:
317306
r-version: *r-versions
318307
requires:
319-
- Python 3.9.19
308+
- Python 3.9
320309
- build-and-push-ir-with-libs:
321310
name: R with libs << matrix.r-version >>
322311
matrix:

python/base/Dockerfile.base

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
FROM debian:bullseye-20241111-slim
1+
## Source of the image with list included dependencies!
2+
# https://github.com/docker-library/buildpack-deps/blob/master/debian/bullseye/Dockerfile
3+
FROM buildpack-deps:bullseye
24
ENV DEBIAN_FRONTEND noninteractive
35

46
# Install OS dependencies
5-
RUN apt-get update && apt-get -yq dist-upgrade \
6-
&& apt-get install -yq --no-install-recommends \
7-
build-essential \
8-
bzip2 \
9-
cmake \
10-
curl \
11-
git \
12-
graphviz \
13-
libgtk2.0-dev \
14-
locales \
15-
sudo \
16-
unzip \
17-
vim \
18-
wget \
19-
ssh \
20-
gnupg2 \
21-
ca-certificates \
22-
&& apt-get clean \
23-
&& rm -rf /var/lib/apt/lists/*
24-
7+
RUN apt-get update \
8+
&& apt-get install -yq --no-install-recommends \
9+
build-essential \
10+
bzip2 \
11+
cmake \
12+
curl \
13+
git \
14+
graphviz \
15+
libgtk2.0-dev \
16+
locales \
17+
sudo \
18+
unzip \
19+
vim \
20+
wget \
21+
ssh \
22+
gnupg2 \
23+
ca-certificates \
24+
&& apt-get clean \
25+
&& rm -rf /var/lib/apt/lists/*
2526
ENV SHELL=/bin/bash \
2627
LC_ALL=en_US.UTF-8 \
2728
LANG=en_US.UTF-8 \

python/python/Dockerfile.python

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
## WARNING: This image is plane copy of:
2+
## https://github.com/docker-library/python/blob/7c8595e8e2b1c8bca0b6d9d146675b94c2a37ec7/3.10/bullseye/Dockerfile
3+
## This is temporary solution and we come with proper solution in the future.
4+
## Ticket: https://linear.app/deepnote/issue/PLA-3219/cleanup-build-pipeline-for-deepnote-python-images
5+
6+
ARG CIRCLE_PULL_REQUEST
7+
FROM deepnote/python:base${CIRCLE_PULL_REQUEST:+-ra-${CIRCLE_PULL_REQUEST##*/}}
8+
9+
10+
# ensure local python is preferred over distribution python
11+
ENV PATH /usr/local/bin:$PATH
12+
13+
# cannot remove LANG even though https://bugs.python.org/issue19846 is fixed
14+
# last attempted removal of LANG broke many users:
15+
# https://github.com/docker-library/python/pull/570
16+
ENV LANG C.UTF-8
17+
18+
# runtime dependencies
19+
RUN set -eux; \
20+
apt-get update; \
21+
apt-get install -y --no-install-recommends \
22+
libbluetooth-dev \
23+
tk-dev \
24+
uuid-dev \
25+
; \
26+
rm -rf /var/lib/apt/lists/*
27+
28+
ENV GPG_KEY A035C8C19219BA821ECEA86B64E628F8D684696D
29+
ENV PYTHON_VERSION 3.10.15
30+
31+
RUN set -eux; \
32+
\
33+
wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"; \
34+
wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc"; \
35+
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
36+
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY"; \
37+
gpg --batch --verify python.tar.xz.asc python.tar.xz; \
38+
gpgconf --kill all; \
39+
rm -rf "$GNUPGHOME" python.tar.xz.asc; \
40+
mkdir -p /usr/src/python; \
41+
tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
42+
rm python.tar.xz; \
43+
\
44+
cd /usr/src/python; \
45+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
46+
./configure \
47+
--build="$gnuArch" \
48+
--enable-loadable-sqlite-extensions \
49+
--enable-optimizations \
50+
--enable-option-checking=fatal \
51+
--enable-shared \
52+
--with-lto \
53+
--with-system-expat \
54+
--with-ensurepip \
55+
; \
56+
nproc="$(nproc)"; \
57+
EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
58+
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
59+
make -j "$nproc" \
60+
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
61+
"LDFLAGS=${LDFLAGS:-}" \
62+
"PROFILE_TASK=${PROFILE_TASK:-}" \
63+
; \
64+
# https://github.com/docker-library/python/issues/784
65+
# prevent accidental usage of a system installed libpython of the same version
66+
rm python; \
67+
make -j "$nproc" \
68+
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
69+
"LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
70+
"PROFILE_TASK=${PROFILE_TASK:-}" \
71+
python \
72+
; \
73+
make install; \
74+
\
75+
# enable GDB to load debugging data: https://github.com/docker-library/python/pull/701
76+
bin="$(readlink -ve /usr/local/bin/python3)"; \
77+
dir="$(dirname "$bin")"; \
78+
mkdir -p "/usr/share/gdb/auto-load/$dir"; \
79+
cp -vL Tools/gdb/libpython.py "/usr/share/gdb/auto-load/$bin-gdb.py"; \
80+
\
81+
cd /; \
82+
rm -rf /usr/src/python; \
83+
\
84+
find /usr/local -depth \
85+
\( \
86+
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
87+
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
88+
\) -exec rm -rf '{}' + \
89+
; \
90+
\
91+
ldconfig; \
92+
\
93+
export PYTHONDONTWRITEBYTECODE=1; \
94+
python3 --version; \
95+
\
96+
pip3 install \
97+
--disable-pip-version-check \
98+
--no-cache-dir \
99+
--no-compile \
100+
'setuptools==65.5.1' \
101+
wheel \
102+
; \
103+
pip3 --version
104+
105+
# make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends)
106+
RUN set -eux; \
107+
for src in idle3 pip3 pydoc3 python3 python3-config; do \
108+
dst="$(echo "$src" | tr -d 3)"; \
109+
[ -s "/usr/local/bin/$src" ]; \
110+
[ ! -e "/usr/local/bin/$dst" ]; \
111+
ln -svT "$src" "/usr/local/bin/$dst"; \
112+
done
113+
114+
115+
# We create the virtual environment in the home directory in the Dockerfile
116+
# for performance improvement.
117+
RUN python -m venv --system-site-packages ~/venv

0 commit comments

Comments
 (0)