Debian Codegraph @

docker/Dockerfile

raw
1 FROM debian:bookworm-slim
2
3 ENV PYTHONUNBUFFERED=1
4 ENV PYTHONIOENCODING=UTF-8
5
6 ARG DEBIAN_FRONTEND=noninteractive
7
8 # Pypy3 is installed from a package manager because it takes so long to build.
9 RUN apt-get update && apt-get install -y build-essential \
10 libcurl4-openssl-dev \
11 apt-utils \
12 debconf \
13 libffi-dev \
14 tk-dev \
15 xz-utils \
16 ca-certificates \
17 curl \
18 lsb-release \
19 git \
20 libmemcached-dev \
21 make \
22 liblzma-dev \
23 libreadline-dev \
24 libbz2-dev \
25 llvm \
26 libncurses5-dev \
27 libsqlite3-dev \
28 wget \
29 pypy3 \
30 pypy3-lib \
31 python3-openssl \
32 libncursesw5-dev \
33 zlib1g-dev \
34 pkg-config \
35 libssl-dev \
36 sudo
37
38 # Setup variables. Even though changing these may cause unnecessary invalidation of
39 # unrelated elements, grouping them together makes the Dockerfile read better.
40 ENV PROVISIONING=/provisioning
41 ENV PIP_NO_CACHE_DIR=off
42 ENV PYTHONDONTWRITEBYTECODE=1
43 ENV PIP_PREFER_BINARY=1
44
45
46 ARG CELERY_USER=developer
47
48 # Check for mandatory build arguments
49 RUN : "${CELERY_USER:?CELERY_USER build argument needs to be set and non-empty.}"
50
51 ENV HOME=/home/$CELERY_USER
52 ENV PATH="$HOME/.pyenv/bin:$PATH"
53
54 # Copy and run setup scripts
55 WORKDIR $PROVISIONING
56 #COPY docker/scripts/install-couchbase.sh .
57 # Scripts will lose their executable flags on copy. To avoid the extra instructions
58 # we call the shell directly.
59 #RUN sh install-couchbase.sh
60 RUN useradd -m -s /bin/bash $CELERY_USER
61
62 # Swap to the celery user so packages and celery are not installed as root.
63 USER $CELERY_USER
64
65 # Install pyenv
66 RUN curl https://pyenv.run | bash
67
68 # Install required Python versions
69 RUN pyenv install 3.13 && \
70 pyenv install 3.12 && \
71 pyenv install 3.11 && \
72 pyenv install 3.10 && \
73 pyenv install 3.9 && \
74 pyenv install pypy3.11
75
76
77 # Set global Python versions
78 RUN pyenv global 3.13 3.12 3.11 3.10 3.9 pypy3.11
79
80 # Install celery
81 WORKDIR $HOME
82 COPY --chown=1000:1000 requirements $HOME/requirements
83 COPY --chown=1000:1000 docker/entrypoint /entrypoint
84 RUN chmod gu+x /entrypoint
85
86 # Define the local pyenvs
87 RUN pyenv local 3.13 3.12 3.11 3.10 3.9 pypy3.11
88
89 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
90 pyenv exec python3.13 -m pip install --upgrade pip setuptools wheel && \
91 pyenv exec python3.12 -m pip install --upgrade pip setuptools wheel && \
92 pyenv exec python3.11 -m pip install --upgrade pip setuptools wheel && \
93 pyenv exec python3.10 -m pip install --upgrade pip setuptools wheel && \
94 pyenv exec python3.9 -m pip install --upgrade pip setuptools wheel && \
95 pyenv exec pypy3.11 -m pip install --upgrade pip setuptools wheel
96
97 # Install requirements first to leverage Docker layer caching
98 # Split into separate RUN commands to reduce memory pressure and improve layer caching
99 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
100 pyenv exec python3.13 -m pip install -r requirements/default.txt \
101 -r requirements/dev.txt \
102 -r requirements/docs.txt \
103 -r requirements/pkgutils.txt \
104 -r requirements/test-ci-base.txt \
105 -r requirements/test-ci-default.txt \
106 -r requirements/test-integration.txt \
107 -r requirements/test.txt \
108 --build-constraint requirements/constraints.txt
109
110 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
111 pyenv exec python3.12 -m pip install -r requirements/default.txt \
112 -r requirements/dev.txt \
113 -r requirements/docs.txt \
114 -r requirements/pkgutils.txt \
115 -r requirements/test-ci-base.txt \
116 -r requirements/test-ci-default.txt \
117 -r requirements/test-integration.txt \
118 -r requirements/test.txt \
119 --build-constraint requirements/constraints.txt
120
121 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
122 pyenv exec python3.11 -m pip install -r requirements/default.txt \
123 -r requirements/dev.txt \
124 -r requirements/docs.txt \
125 -r requirements/pkgutils.txt \
126 -r requirements/test-ci-base.txt \
127 -r requirements/test-ci-default.txt \
128 -r requirements/test-integration.txt \
129 -r requirements/test.txt \
130 --build-constraint requirements/constraints.txt
131
132 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
133 pyenv exec python3.10 -m pip install -r requirements/default.txt \
134 -r requirements/dev.txt \
135 -r requirements/docs.txt \
136 -r requirements/pkgutils.txt \
137 -r requirements/test-ci-base.txt \
138 -r requirements/test-ci-default.txt \
139 -r requirements/test-integration.txt \
140 -r requirements/test.txt \
141 --build-constraint requirements/constraints.txt
142
143 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
144 pyenv exec python3.9 -m pip install -r requirements/default.txt \
145 -r requirements/dev.txt \
146 -r requirements/docs.txt \
147 -r requirements/pkgutils.txt \
148 -r requirements/test-ci-base.txt \
149 -r requirements/test-ci-default.txt \
150 -r requirements/test-integration.txt \
151 -r requirements/test.txt \
152 --build-constraint requirements/constraints.txt
153
154 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
155 pyenv exec pypy3.11 -m pip install -r requirements/default.txt \
156 -r requirements/dev.txt \
157 -r requirements/docs.txt \
158 -r requirements/pkgutils.txt \
159 -r requirements/test-ci-base.txt \
160 -r requirements/test-ci-default.txt \
161 -r requirements/test-integration.txt \
162 -r requirements/test.txt \
163 --build-constraint requirements/constraints.txt
164
165 COPY --chown=1000:1000 . $HOME/celery
166
167 # Install celery in editable mode (dependencies already installed above)
168 RUN --mount=type=cache,target=/home/$CELERY_USER/.cache/pip \
169 pyenv exec python3.13 -m pip install --no-deps -e $HOME/celery && \
170 pyenv exec python3.12 -m pip install --no-deps -e $HOME/celery && \
171 pyenv exec python3.11 -m pip install --no-deps -e $HOME/celery && \
172 pyenv exec python3.10 -m pip install --no-deps -e $HOME/celery && \
173 pyenv exec python3.9 -m pip install --no-deps -e $HOME/celery && \
174 pyenv exec pypy3.11 -m pip install --no-deps -e $HOME/celery
175
176 WORKDIR $HOME/celery
177
178 RUN git config --global --add safe.directory /home/developer/celery
179
180 # Setup the entrypoint, this ensures pyenv is initialized when a container is started
181 # and that any compiled files from earlier steps or from mounts are removed to avoid
182 # pytest failing with an ImportMismatchError
183 ENTRYPOINT ["/entrypoint"]