-
-
Notifications
You must be signed in to change notification settings - Fork 913
Expand file tree
/
Copy pathwrite-dockerfile.sh
More file actions
executable file
·374 lines (362 loc) · 13.4 KB
/
Copy pathwrite-dockerfile.sh
File metadata and controls
executable file
·374 lines (362 loc) · 13.4 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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#! /usr/bin/env bash
set -e
shopt -s extglob
##
## Write a Dockerfile for portability testing to stdout.
##
## This script needs to be run from SAGE_ROOT (root of the Sage repository).
## It is called by $SAGE_ROOT/tox.ini for all environments 'tox -e docker-...'
##
## Positional arguments:
##
SYSTEM="${1:-debian}"
SAGE_PACKAGE_LIST_ARGS="${2:-:standard:}"
WITH_SYSTEM_SPKG="${3:-yes}"
IGNORE_MISSING_SYSTEM_PACKAGES="${4:-no}"
EXTRA_SAGE_PACKAGES="${5:-_bootstrap}"
##
## Environment variables that take influence:
##
## - BOOTSTRAP
## - CONFIGURE_ARGS
## - DEVTOOLSET
## - DIST_UPGRADE
## - DOCKER_BUILDKIT
## - EXTRA_PATH
## - EXTRA_REPOSITORIES
## - EXTRA_SYSTEM_PACKAGES
## - FULL_BASE_IMAGE_AND_TAG
## - SKIP_SYSTEM_PKG_INSTALL
## - USE_CONDARC
## - __CHOWN
## - __SUDO
##
STRIP_COMMENTS="sed s/#.*//;"
SAGE_ROOT=.
export PATH="$SAGE_ROOT"/build/bin:$PATH
SYSTEM_PACKAGES=$EXTRA_SYSTEM_PACKAGES
SYSTEM_CONFIGURE_ARGS=" --enable-option-checking"
for SPKG in $(sage-package list --has-file=spkg-configure.m4 $SAGE_PACKAGE_LIST_ARGS) $EXTRA_SAGE_PACKAGES; do
SYSTEM_PACKAGE=$(sage-get-system-packages $SYSTEM $SPKG)
if [ -n "${SYSTEM_PACKAGE}" ]; then
# SYSTEM_PACKAGE can be empty if, for example, the environment
# variable ENABLE_SYSTEM_SITE_PACKAGES is empty.
for a in $SYSTEM_PACKAGE; do
# shell-quote package if necessary
SYSTEM_PACKAGES+=$(printf " %q" "$a")
done
# Check if SPKG is not a dummy package
if [[ $SPKG != _* ]]; then
SYSTEM_CONFIGURE_ARGS+=" --with-system-${SPKG}=${WITH_SYSTEM_SPKG}"
fi
fi
done
echo "# Automatically generated by SAGE_ROOT/.ci/write-dockerfile.sh"
echo "# the :comments: separate the generated file into sections"
echo "# to simplify writing scripts that customize this file"
if [ -z "$__CHOWN" ]; then
ADD="ADD"
else
ADD="ADD $__CHOWN"
fi
RUN=RUN
cat <<EOF
ARG BASE_IMAGE=$(eval echo "${FULL_BASE_IMAGE_AND_TAG}")
FROM \${BASE_IMAGE} AS with-system-packages
EOF
case $SYSTEM in
debian*|ubuntu*)
if [ -n "$__SUDO" ]; then
SUDO="sudo"
else
unset SUDO
fi
EXISTS="2>/dev/null >/dev/null apt-cache show"
UPDATE="$SUDO apt-get update &&"
INSTALL="$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -qqq --no-install-recommends --yes"
CLEAN="&& $SUDO apt-get clean"
if [ -n "$EXTRA_PATH" ]; then
RUN="RUN export PATH=$EXTRA_PATH:\$PATH && "
fi
case "$SKIP_SYSTEM_PKG_INSTALL" in
1|y*|Y*)
;;
*)
#
# The Ubuntu Docker images are "minimized", meaning that some large
# bits such as documentation has been removed. We have to unminimize
# once (which reinstalls the full versions of some minimized packages),
# or e.g. the maxima documentation (which we depend on for correct operation)
# will be missing.
#
# But we only have to do this once. To save time in incremental builds,
# we remove the unminimize binary here after it has done its job.
#
cat <<EOF
RUN if command -v unminimize > /dev/null; then (yes | unminimize) || echo "(ignored)"; rm -f "\$(command -v unminimize)"; fi
EOF
if [ -n "$DIST_UPGRADE" ]; then
cat <<EOF
RUN sed -i.bak $DIST_UPGRADE /etc/apt/sources.list && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade
EOF
fi
if [ -n "$EXTRA_REPOSITORIES" ]; then
cat <<EOF
RUN $UPDATE $INSTALL software-properties-common && ($INSTALL gpg gpg-agent || echo "(ignored)")
EOF
for repo in $EXTRA_REPOSITORIES; do
cat <<EOF
RUN $SUDO add-apt-repository $repo
EOF
done
fi
esac
;;
fedora*|redhat*|centos*)
EXISTS="2>/dev/null >/dev/null yum install -y --downloadonly"
INSTALL="yum install -y"
if [ -n "$DEVTOOLSET" ]; then
case "$SKIP_SYSTEM_PKG_INSTALL" in
1|y*|Y*)
;;
*)
cat <<EOF
RUN $INSTALL centos-release-scl
RUN $INSTALL devtoolset-$DEVTOOLSET
EOF
esac
RUN="RUN . /opt/rh/devtoolset-$DEVTOOLSET/enable && "
fi
;;
gentoo*)
EXISTS="2>/dev/null >/dev/null emerge -f"
UPDATE="" # not needed. "FROM gentoo/portage" used instead
INSTALL="emerge -DNut --with-bdeps=y --complete-graph=y"
;;
slackware*)
# https://docs.slackware.com/slackbook:package_management
# slackpkg install ignores packages that it does not know, so we do not have to filter
EXISTS="true"
UPDATE="(yes|slackpkg update) &&"
INSTALL="slackpkg install"
;;
arch*)
# https://hub.docker.com/_/archlinux/
UPDATE="pacman -Sy &&"
EXISTS="pacman -Si"
INSTALL="pacman -Su --noconfirm"
cat <<EOF
RUN sed -i '/^NoExtract/d' /etc/pacman.conf
EOF
;;
nix*)
# https://hub.docker.com/r/nixos/nix
case "$SKIP_SYSTEM_PKG_INSTALL" in
1|y*|Y*)
;;
*)
cat <<EOF
RUN nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
RUN nix-channel --update
ENV PACKAGES="$SYSTEM_PACKAGES"
EOF
esac
INSTALL="nix-env --install"
RUN="RUN nix-shell --packages \$PACKAGES --run "\'
ENDRUN=\'
;;
void*)
UPDATE="xbps-install -Suy &&"
EXISTS="xbps-query -R"
INSTALL="xbps-install --yes"
;;
opensuse*)
UPDATE="zypper refresh &&"
EXISTS="zypper --quiet install --no-confirm --auto-agree-with-licenses --no-recommends --download-only > /dev/null"
INSTALL="zypper --ignore-unknown install --no-confirm --auto-agree-with-licenses --no-recommends --details"
;;
conda*)
case "$SKIP_SYSTEM_PKG_INSTALL" in
1|y*|Y*)
;;
*)
cat <<EOF
ARG USE_CONDARC=${USE_CONDARC-condarc.yml}
ADD *condarc*.yml /tmp/
RUN echo \${CONDARC}; cd /tmp && conda config --stdin < \${USE_CONDARC}
RUN conda update -n base conda
RUN ln -sf /bin/bash /bin/sh
EOF
esac
# On this image, /bin/sh -> /bin/dash;
# but some of the scripts in /opt/conda/etc/conda/activate.d
# from conda-forge (as of 2020-01-27) contain bash-isms:
# /bin/sh: 5: /opt/conda/etc/conda/activate.d/activate-binutils_linux-64.sh: Syntax error: "(" unexpected
# The command '/bin/sh -c . /opt/conda/etc/profile.d/conda.sh; conda activate base; ./bootstrap' returned a non-zero code
# We just change the link to /bin/bash.
INSTALL="conda install --update-all --quiet --yes"
EXISTS="2>/dev/null >/dev/null conda search -f"
#EXISTS="conda search -f"
CLEAN="&& conda info; conda list"
RUN="RUN . /opt/conda/etc/profile.d/conda.sh; conda activate base; " # to activate the conda env
;;
*)
cat <<EOF
ARG BASE_IMAGE
FROM \${BASE_IMAGE} AS with-system-packages
EOF
INSTALL=$(sage-print-system-package-command $SYSTEM install " ")
;;
esac
case "$SKIP_SYSTEM_PKG_INSTALL" in
1|y*|Y*)
;;
*)
cat <<EOF
#:packages:
EOF
case "$IGNORE_MISSING_SYSTEM_PACKAGES" in
no)
cat <<EOF
RUN $UPDATE $INSTALL $SYSTEM_PACKAGES $CLEAN
EOF
;;
yes)
if [ -n "$EXISTS" ]; then
# Filter by existing packages, try to install these in one shot; fall back to one by one.
cat <<EOF
RUN $UPDATE EXISTING_PACKAGES=""; for pkg in $SYSTEM_PACKAGES; do echo -n .; if $EXISTS \$pkg; then EXISTING_PACKAGES="\$EXISTING_PACKAGES \$pkg"; echo -n "\$pkg"; fi; done; $INSTALL \$EXISTING_PACKAGES || (echo "Trying again one by one:"; for pkg in \$EXISTING_PACKAGES; do echo "Trying to install \$pkg"; $INSTALL \$pkg || echo "(ignoring error)"; done); : $CLEAN
EOF
else
# Try in one shot, fall back to one by one. Separate "RUN" commands
# for caching by docker.
cat <<EOF
RUN $UPDATE $INSTALL $SYSTEM_PACKAGES || echo "(ignoring error)"
EOF
for pkg in $SYSTEM_PACKAGES; do
cat <<EOF
RUN $INSTALL $pkg || echo "(ignoring error)"
EOF
done
if [ -n "$CLEAN" ]; then
cat <<EOF
RUN : $CLEAN
EOF
fi
fi
;;
*)
echo "Argument IGNORE_MISSING_SYSTEM_PACKAGES must be yes or no"
;;
esac
esac
case ${DOCKER_BUILDKIT-0} in
1)
# With buildkit we cannot retrieve failed builds.
# So we do not allow the main step of a build stage to fail.
# Instead we record the exit code in the file STATUS.
THEN_SAVE_STATUS=' ; echo $? > STATUS'
# ... and at the beginning of the next build stage,
# we check the status and exit with an error status.
CHECK_STATUS_THEN=' STATUS=$(cat STATUS 2>/dev/null); case "$STATUS" in ""|0) ;; *) exit $STATUS;; esac;'
esac
if [ -n "$GITHUB_ACTIONS" ]; then
cat <<EOF
ENV GITHUB_ACTIONS=1
EOF
fi
cat <<EOF
FROM with-system-packages AS bootstrapped
#:bootstrapping:
RUN rm -rf /new /sage/.git
$ADD Makefile VERSION.txt COPYING.txt condarc.yml README.md bootstrap bootstrap-conda configure.ac sage .homebrew-build-env tox.ini Pipfile.m4 .gitignore /new/
$ADD config/config.rpath /new/config/config.rpath
$ADD src/doc/bootstrap /new/src/doc/bootstrap
$ADD src/bin /new/src/bin
$ADD src/Pipfile.m4 src/pyproject.toml src/requirements.txt.m4 src/VERSION.txt /new/src/
$ADD m4 /new/m4
$ADD pkgs /new/pkgs
$ADD build /new/build
$ADD .upstream.d /new/.upstream.d
ADD .ci /.ci
RUN if [ -d /sage ]; then \\
echo "### Incremental build from \$(cat /sage/VERSION.txt)" && \\
printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /sage/.gitignore && \\
printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /new/.gitignore && \\
if ! (cd /new && /.ci/retrofit-worktree.sh worktree-image /sage); then \\
echo "retrofit-worktree.sh failed, falling back to replacing /sage"; \\
for a in local logs; do \\
if [ -d /sage/\$a ]; then mv /sage/\$a /new/; fi; \\
done; \\
rm -rf /sage; \\
mv /new /sage; \\
fi; \\
else \\
mv /new /sage; \\
fi
WORKDIR /sage
ARG BOOTSTRAP="${BOOTSTRAP-./bootstrap}"
$RUN sh -x -c "\${BOOTSTRAP}"$ENDRUN$THEN_SAVE_STATUS
FROM bootstrapped AS configured
#:configuring:
RUN$CHECK_STATUS_THEN mkdir -p logs/pkgs; rm -f config.log; ln -s logs/pkgs/config.log config.log
ARG CONFIGURE_ARGS="${CONFIGURE_ARGS:---enable-build-as-root}"
EOF
if [ ${WITH_SYSTEM_SPKG} = "force" ]; then
cat <<EOF
$RUN ./configure $SYSTEM_CONFIGURE_ARGS \${CONFIGURE_ARGS} || (echo "::group::config.log"; cat config.log; echo "::endgroup::"; echo "********** configuring without forcing ***********"; ./configure \${CONFIGURE_ARGS}; echo "::group::config.log"; cat config.log; echo "::endgroup::"; exit 1)$ENDRUN$THEN_SAVE_STATUS
EOF
else
cat <<EOF
$RUN ./configure $SYSTEM_CONFIGURE_ARGS \${CONFIGURE_ARGS} || (echo "::group::config.log"; cat config.log; echo "::endgroup::"; exit 1)$ENDRUN$THEN_SAVE_STATUS
EOF
fi
cat <<EOF
FROM configured AS with-base-toolchain
# We first compile base-toolchain because otherwise lots of packages are missing their dependency on 'patch'
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
ENV SAGE_CHECK=warn
ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!cmake,!rpy2,!sage_sws2rst"
#:toolchain:
$RUN$CHECK_STATUS_THEN make \${USE_MAKEFLAGS} base-toolchain$ENDRUN$THEN_SAVE_STATUS
FROM with-base-toolchain AS with-targets-pre
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
ENV SAGE_CHECK=warn
ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!cmake,!rpy2,!sage_sws2rst"
#:make:
ARG TARGETS_PRE="all-sage-local"
$RUN$CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \${USE_MAKEFLAGS} \${TARGETS_PRE}$ENDRUN$THEN_SAVE_STATUS
FROM with-targets-pre AS with-targets
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
ENV SAGE_CHECK=warn
ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!cmake,!rpy2,!sage_sws2rst"
$ADD .gitignore /new/.gitignore
$ADD src /new/src
RUN cd /new && rm -rf .git && \\
if /.ci/retrofit-worktree.sh worktree-pre /sage; then \\
cd /sage && touch configure build/make/Makefile; \\
else \\
echo "retrofit-worktree.sh failed, falling back to replacing /sage/src"; \\
rm -rf /sage/src; \\
mv src /sage/src; \\
cd /sage && ./bootstrap && ./config.status; \\
fi; \\
cd /sage && rm -rf .git; rm -rf /new || echo "(error ignored)"
ARG TARGETS="build"
$RUN$CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \${USE_MAKEFLAGS} \${TARGETS}$ENDRUN$THEN_SAVE_STATUS
FROM with-targets AS with-targets-optional
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
ENV SAGE_CHECK=warn
ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!cmake,!rpy2,!sage_sws2rst"
ARG TARGETS_OPTIONAL="ptest"
$RUN$CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \${USE_MAKEFLAGS} \${TARGETS_OPTIONAL} || echo "(error ignored)"$ENDRUN$THEN_SAVE_STATUS
#:end:
EOF