11#! /usr/bin/env bash
2- set -e
3- shopt -s extglob
42# #
53# # Write a Dockerfile for portability testing to stdout.
64# #
75# # This script needs to be run from SAGE_ROOT (root of the Sage repository).
86# # It is called by $SAGE_ROOT/tox.ini for all environments 'tox -e docker-...'
97# #
8+ # # The generated Dockerfile needs Sage source tree directory as context,
9+ # # and builds Sage docker images based on the source tree.
10+ # #
11+ # # Hence this is how to use it:
12+ # #
13+ # # git worktree add source-tree
14+ # # docker build source-tree -f Dockerfile ...
15+ # # git worktree remove source-tree
16+ # #
17+ # # where we assume the current directory is SAGE_ROOT.
18+ # #
19+ set -e
20+ shopt -s extglob
1021# # Positional arguments:
1122# #
1223SYSTEM=" ${1:- debian} "
@@ -15,7 +26,7 @@ WITH_SYSTEM_SPKG="${3:-yes}"
1526IGNORE_MISSING_SYSTEM_PACKAGES=" ${4:- no} "
1627EXTRA_SAGE_PACKAGES=" ${5:- _bootstrap} "
1728# #
18- # # Environment variables that take influence:
29+ # # Environment variables that influence:
1930# #
2031# # - BOOTSTRAP
2132# # - CONFIGURE_ARGS
@@ -274,32 +285,28 @@ cat <<EOF
274285
275286FROM with-system-packages AS bootstrapped
276287#:bootstrapping:
277- RUN rm -rf /new /sage/.git
278- $ADD Makefile VERSION.txt COPYING.txt condarc.yml README.md bootstrap conftest.py configure_wrapper configure.ac sage .homebrew-build-env tox.ini .gitignore /new/
279- $ADD config/config.rpath /new/config/config.rpath
280- $ADD src/doc/bootstrap /new/src/doc/bootstrap
281- $ADD src/bin /new/src/bin
282- $ADD src/pyproject.toml src/requirements.txt.m4 src/setup.cfg.m4 src/VERSION.txt /new/src/
283- $ADD m4 /new/m4
284- $ADD pkgs /new/pkgs
285- $ADD build /new/build
286- $ADD .upstream.d /new/.upstream.d
287- ADD .ci /.ci
288- RUN if [ -d /sage ]; then \\
289- echo "### Incremental build from \$ (cat /sage/VERSION.txt)" && \\
290- printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /sage/.gitignore && \\
291- printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /new/.gitignore && \\
292- if ! (cd /new && /.ci/retrofit-worktree.sh worktree-image /sage); then \\
293- echo "retrofit-worktree.sh failed, falling back to replacing /sage"; \\
294- for a in local logs; do \\
295- if [ -d /sage/\$ a ]; then mv /sage/\$ a /new/; fi; \\
296- done; \\
297- rm -rf /sage; \\
298- mv /new /sage; \\
299- fi; \\
300- else \\
301- mv /new /sage; \\
302- fi
288+ RUN rm -rf /source-tree
289+ $ADD . /source-tree
290+ RUN <<EOT
291+ rm -rf /source-tree/.git
292+ if [ -d /sage ]; then
293+ BASE_VERSION=\$ (cat /sage/VERSION.txt)
294+ if (cd /source-tree && .ci/retrofit-worktree.sh worktree-image /sage); then
295+ echo "### Starting incremental build from \$ BASE_VERSION"
296+ else
297+ echo "retrofit-worktree.sh failed..."
298+ rm -rf /sage
299+ mv /source-tree /sage
300+ echo "### Starting build from scratch"
301+ fi
302+ else
303+ git config --global user.name "ci-sage workflow"
304+ git config --global user.email "ci-sage@example.com"
305+ (cd /source-tree && git init && git add -A && git commit --quiet --allow-empty -m "new")
306+ mv /source-tree /sage
307+ echo "### Starting build from scratch"
308+ fi
309+ EOT
303310WORKDIR /sage
304311ARG BOOTSTRAP="${BOOTSTRAP-./ bootstrap} "
305312$RUN sh -x -c "\$ {BOOTSTRAP}"$ENDRUN$THEN_SAVE_STATUS
@@ -346,18 +353,7 @@ ENV MAKE="make -j\${NUMPROC}"
346353ARG USE_MAKEFLAGS="-k V=0"
347354ENV SAGE_CHECK=warn
348355ENV SAGE_CHECK_PACKAGES="!cython,!python3,!cysignals,!linbox,!ppl,!cmake,!rpy2,!sage_sws2rst"
349- $ADD .gitignore /new/.gitignore
350- $ADD src /new/src
351- RUN cd /new && rm -rf .git && \\
352- if /.ci/retrofit-worktree.sh worktree-pre /sage; then \\
353- cd /sage && touch configure build/make/Makefile; \\
354- else \\
355- echo "retrofit-worktree.sh failed, falling back to replacing /sage/src"; \\
356- rm -rf /sage/src; \\
357- mv src /sage/src; \\
358- cd /sage && ./bootstrap && ./config.status; \\
359- fi; \\
360- cd /sage && rm -rf .git; rm -rf /new || echo "(error ignored)"
356+ RUN cd /sage && touch configure build/make/Makefile
361357ARG TARGETS="build"
362358$RUN$CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \$ {USE_MAKEFLAGS} \$ {TARGETS}$ENDRUN$THEN_SAVE_STATUS
363359
0 commit comments