-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile-python
283 lines (224 loc) · 12.2 KB
/
Dockerfile-python
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
ARG ARCH=
# AlpineLinux with a glibc-2.29-r0 and python3
FROM ${ARCH}/alpine:3.12
ARG ARCH
ENV ARCH=${ARCH}
RUN set -ex && \
echo $ARCH > /etc/ARCH
# This hack is widely applied to avoid python printing issues in docker containers.
# See: https://github.com/Docker-Hub-frolvlad/docker-alpine-python3/pull/13
ENV PYTHONUNBUFFERED=1
ENV LANG=C.UTF-8
# Suppress non-meannigfull WARNING:
#WARNING: "Running pip as root will break packages and permissions. You should install packages reliably \
#by using venv: https://pip.pypa.io/warnings/venv"
# See: https://stackoverflow.com/questions/68673221/warning-running-pip-as-the-root-user
ENV PIP_ROOT_USER_ACTION=ignore
#see below
#ARG GLIBC_REPO=https://github.com/$GLIBC_REPO_INFIX/alpine-pkg-glibc
ARG GLIBC_VERSION=2.32-r0
#updating from alpine 3.8 to 3.12 as of 23.05.2021
RUN set -ex && \
#apk -U upgrade && \
apk add --no-cache musl busybox alpine-baselayout ca-certificates-bundle \
ssl_client musl-utils
#Git
RUN set -ex && \
apk add --no-cache git && \
#git config --global credential.helper store
#git config --global credential.helper cache
#see https://git-scm.com/docs/git-credential-cache
git config --global credential.helper 'cache --timeout=3600'
#for maturing see https://pyo3.rs/v0.19.2/getting_started ("failed to get `pyo3` as a dependency
# of package `cryptography-rust v0.1.0")
RUN set -ex && \
apk add --no-cache maturin --repository=https://dl-cdn.alpinelinux.org/alpine/v3.14/community
#ssl, curl
#for curl-dev see https://stackoverflow.com/a/51849028/1137529
#for libffi-dev see https://stackoverflow.com/a/58396708/1137529
#for cargo see https://github.com/pyca/cryptography/issues/5776#issuecomment-775158562
RUN set -ex && \
apk add --no-cache maturin openssl-dev musl-dev cyrus-sasl-dev \
linux-headers unixodbc-dev curl-dev libffi-dev cargo
#https://stackoverflow.com/questions/5178416/libxml-install-error-using-pip
RUN set -ex && \
apk add --no-cache libxml2-dev libxslt-dev
#gcc, gfortran, lapack, blas (requires ssl layer above)
#see https://stackoverflow.com/questions/11912878/gcc-error-gcc-error-trying-to-exec-cc1-execvp-no-such-file-or-directory
#see https://stackoverflow.com/a/38571314/1137529
#see https://unix.stackexchange.com/questions/550290/using-blas-in-alpine-linux
RUN set -ex && \
apk add --no-cache make=4.3-r0 gcc=9.3.0-r2 build-base=0.5-r2 lapack-dev=3.9.0-r2 freetype-dev=2.10.4-r2 \
gfortran=9.3.0-r2 openblas-dev=0.3.9-r2
#https://github.com/h5py/h5py/issues/1461#issuecomment-562871041
#https://stackoverflow.com/questions/66705108/how-to-install-hdf5-on-docker-image-with-linux-alpine-3-13
RUN set -ex && \
apk add --no-cache hdf5-dev
#https://pillow.readthedocs.io/en/latest/installation.html
#Pillow
#zlib-dev exists in parent
#libjpeg-turbo and libjpeg-turbo-dev doesn't mentioned in the link above
RUN set -ex && \
apk add jpeg-dev libjpeg libjpeg-turbo libjpeg-turbo-dev
#bash+usefull utils
#curl is installed above
RUN set -ex && \
apk --no-cache add bash=5.0.17-r0 nano=4.9.3-r0 mlocate=0.26-r7 && \
updatedb && \
#disable coloring for nano, see https://stackoverflow.com/a/55597765/1137529
echo "syntax \"disabled\" \".\"" > ~/.nanorc; echo "color green \"^$\"" >> ~/.nanorc
#install glibc (another c++ compiler, older one)
# do all in one step
RUN set -ex && \
#Remarked by Alex \
#apk -U upgrade && \
#Alex added --no-cache
apk --no-cache add curl && \
#Added by Alex \
#Alex added --no-cache
apk --no-cache add net-tools=1.60_git20140218-r2 && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
#Added by Alex \
if [ "$ARCH" = "arm64v8" ]; then suffix='-arm64'; else suffix=''; fi && \
#Added by Alex \
if [ "$ARCH" = "arm64v8" ]; then infix='ljfranklin'; else infix='sgerrand'; fi && \
GLIBC_REPO=https://github.com/$infix/alpine-pkg-glibc && \
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION} glibc-i18n-${GLIBC_VERSION}; do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}${suffix}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
#Alex added --no-cache
apk --no-cache --allow-untrusted add /tmp/*.apk && \
rm -v /tmp/*.apk && \
( /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 C.UTF-8 || true ) && \
echo "export LANG=C.UTF-8" > /etc/profile.d/locale.sh && \
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib
#https://pillow.readthedocs.io/en/latest/installation.html
#Pillow
#zlib-dev exists in parent
#libjpeg-turbo and libjpeg-turbo-dev doesn't mentioned in the link above
RUN set -ex && \
apk add jpeg-dev libjpeg libjpeg-turbo libjpeg-turbo-dev
#https://stackoverflow.com/questions/9510474/removing-pips-cache
#https://pip.pypa.io/en/stable/reference/pip_install/#caching
#pip config set global.cache-dir false doesn't work
#https://stackoverflow.com/questions/9510474/removing-pips-cache/61762308#61762308
RUN mkdir -p /root/.config/pip
RUN echo "[global]" > /root/.config/pip/pip.conf; echo "no-cache-dir = false" >> /root/.config/pip/pip.conf; echo >> /root/.config/pip/pip.conf;
#python3-dev (we need C++ header for cffi)
RUN set -ex && \
apk add --no-cache make==4.3-r0 python3-dev==3.8.10-r0
#https://stackoverflow.com/a/62555259/1137529
RUN set -ex && \
ln -s /usr/bin/python3.8 /usr/bin/python && \
ln -s /usr/bin/python3.8-config /usr/bin/python-config && \
python -m ensurepip && \
cp /usr/bin/pip3.8 /usr/bin/pip
RUN set -ex && \
pip install --upgrade pip==23.2.1 setuptools==68.0.0 wheel==0.36.1
RUN set -ex && \
pip install ruamel_yaml==0.15.100
RUN set -ex && \
#entrypoints==0.2.3 used in setup.py
pip install entrypoints==0.2.3 pyyaml==6.0.1
#slim
RUN set -ex && \
#twine
#https://twine.readthedocs.io/en/latest/changelog.html see 3.0.0 changelog
#Add Python 3.8 support
#see https://github.com/pypa/twine/pull/518
pip install twine==3.2.0 pkginfo==1.6.1 colorama==0.4.4 rfc3986==1.4.0 readme-renderer==28.0 \
webencodings==0.5.1 bleach==3.2.1 requests-toolbelt==0.9.1 \
packaging==20.4 pyparsing==3.1.1 \
cffi==1.14.5 cryptography==38.0.4 \
\
#pin pyOpenSSL==20.0.1 requests==2.24.0 tqdm==4.59.0
pip install cffi==1.14.5 cryptography==38.0.4 idna==2.10 pycparser==2.20 pyOpenSSL==22.1.0 \
docutils==0.16 requests==2.24.0 chardet==3.0.4 tqdm==4.59.0 urllib3==1.25.11 toml==0.10.2
##extras
RUN set -ex && \
#boto3 \
pip install awscli==1.29.17 boto3==1.28.17 botocore==1.31.17 colorama==0.4.4 s3transfer==0.6.1 && \
pip install python-dotenv==0.15.0 && \
pip install bidict==0.21.2 && \
\
#fabric & pyOpenSSL
pip install fabric==2.5.0 invoke==1.7.3 paramiko==2.7.2 PyNaCl==1.3.0 bcrypt==3.2.0 \
cffi==1.14.5 cryptography==38.0.4 pycparser==2.20 PyNaCl==1.3.0 six==1.16.0 \
pyOpenSSL==22.1.0 \
\
#twine
#https://twine.readthedocs.io/en/latest/changelog.html see 3.0.0 changelog
#Add Python 3.8 support
#see https://github.com/pypa/twine/pull/518
pip install twine==3.2.0 pkginfo==1.6.1 colorama==0.4.4 rfc3986==1.4.0 readme-renderer==28.0 \
requests-toolbelt==0.9.1 && \
#SQLAlchemy & Hive & Postgress
pip install SQLAlchemy==1.4.31 thrift==0.13.0 thrift-sasl==0.4.2 sasl==0.2.1 PyHive==0.6.2 pg8000==1.29.4 \
pure-sasl==0.6.2 pure-transport==0.2.0 future==0.18.2
#nltk-data
#RUN set -ex && python -m nltk.downloader -d /usr/share/nltk_data all
RUN set -ex && pip freeze > /etc/installed.txt
#Cleanup
RUN set -ex && rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
#RUN apk del glibc-i18n make gcc musl-dev build-base gfortran
RUN rm -rf /var/cache/apk/*
#COPY enter_keyring.sh /etc/enter_keyring.sh
#COPY reuse_keyring.sh /etc/reuse_keyring.sh
#COPY unlock_keyring.sh /etc/unlock_keyring.sh
#COPY rest_keyring.sh /etc/rest_keyring.sh
WORKDIR /
#CMD ["/bin/sh"]
CMD tail -f /dev/null
##docker system prune --all
#docker rmi -f alpine-python3-amd64 alpine-python3-arm64v8
#docker rm -f py3-amd64 py3-amd64-arm64v8
#docker build . -t alpine-python3-amd64 --build-arg ARCH=amd64 --file Dockerfile-python
#docker build . -t alpine-python3-arm64v8 --build-arg ARCH=arm64v8 --file Dockerfile-python
#docker run --name py3-amd64 -d alpine-python3-amd64
#docker run --name py3-arm64v8 -d alpine-python3-arm64v8
#smoke test
#docker exec -it $(docker ps -q -n=1) pip config list
#docker exec -it $(docker ps -q -n=1) bash
##docker build --squash . -t alpine-python3-amd64 --build-arg ARCH=amd64
##docker build --squash . -t alpine-python3-arm64v8 --build-arg ARCH=arm64v8
#see https://github.com/fabioz/PyDev.Debugger
#docker run --env-file .env.docker --name py3 -p 54717:54717/tcp -v //C/dev/work/:/opt/project -v //C/Program\ Files/JetBrains/PyCharm\ 2020.1.4/plugins/python/helpers:/opt/.pycharm_helpers -d alpine-python3
##docker exec -it $(docker ps -q -n=1) dbus-run-session bash
#python /opt/.pycharm_helpers/pydev/pydevconsole.py --mode=server --port=54717 #run
#python -u /opt/.pycharm_helpers/pydev/pydevd.py --cmd-line --multiprocess --qt-support=auto --port 54717 --file /opt/project/alpine-python3/keyring_check.py #debug
#runfile('/opt/project/alpine-anaconda3/keyring_check.py', wdir='/opt/project/alpine-anaconda3')
#docker run --name py3-amd64 -d alpine-python3-amd64
#docker export $(docker ps -q -n=1) | docker import - alpine-python3-amd64-e
#docker run --name py3-amd64-e -d alpine-python3-amd64-e bash
#populate from docker inspect -f "{{ .Config.Env }}" alpine-python3-amd64
#populate from docker inspect -f "{{ .Config.Cmd }}" alpine-python3-amd64
#based on https://docs.docker.com/engine/reference/commandline/commit/
#docker commit --change "CMD /bin/sh" --change "ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: \
# ARCH=amd64 \
# PYTHONUNBUFFERED=1 \
# LANG=C.UTF-8 \
# PIP_ROOT_USER_ACTION=ignore" \
# $(docker ps -q -n=1) alpine-python3-amd64-ef
#docker run --name py3-arm64v8 -d alpine-python3-arm64v8
#docker export $(docker ps -q -n=1) | docker import - alpine-python3-arm64v8-e
#docker run --name py3-arm64v8-e -d alpine-python3-arm64v8-e bash
#populate from docker inspect -f "{{ .Config.Env }}" alpine-python3-arm64v8
#populate from docker inspect -f "{{ .Config.Cmd }}" alpine-python3-arm64v8
#based on https://docs.docker.com/engine/reference/commandline/commit/
#docker commit --change "CMD /bin/sh" --change "ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: \
# ARCH=arm64v8 \
# PYTHONUNBUFFERED=1 \
# LANG=C.UTF-8 \
# PIP_ROOT_USER_ACTION=ignore" \
# $(docker ps -q -n=1) alpine-python3-arm64v8-ef
#docker tag alpine-python3-amd64-ef alexberkovich/alpine-python3:0.3.5-amd64
#docker tag alpine-python3-arm64v8-ef alexberkovich/alpine-python3:0.3.5-arm64v8
#docker push alexberkovich/alpine-python3:0.3.5-amd64
#docker push alexberkovich/alpine-python3:0.3.5-arm64v8
#docker manifest create alexberkovich/alpine-python3:0.3.5 --amend alexberkovich/alpine-python3:0.3.5-arm64v8 --amend alexberkovich/alpine-python3:0.3.5-amd64
#docker manifest annotate --arch arm64 --variant v8 alexberkovich/alpine-python3:0.3.5 alexberkovich/alpine-python3:0.3.5-arm64v8
#docker manifest annotate --arch amd64 alexberkovich/alpine-python3:0.3.5 alexberkovich/alpine-python3:0.3.5-amd64
#docker manifest push --purge alexberkovich/alpine-python3:0.3.5
#docker manifest create alexberkovich/alpine-python3:latest --amend alexberkovich/alpine-python3:0.3.5-arm64v8 --amend alexberkovich/alpine-python3:0.3.5-amd64
#docker manifest annotate --arch arm64 --variant v8 alexberkovich/alpine-python3:latest alexberkovich/alpine-python3:0.3.5-arm64v8
#docker manifest annotate --arch amd64 alexberkovich/alpine-python3:latest alexberkovich/alpine-python3:0.3.5-amd64
#docker manifest push --purge alexberkovich/alpine-python3:latest
# EOF