|
13 | 13 | # docker build without any external orchestration script. #
|
14 | 14 | # #
|
15 | 15 | # The idea to achieve (1) is to reuse the build artifacts from the latest #
|
16 |
| -# master build. This is slightly against the philosophy of a Dockerfile (which # |
| 16 | +# develop build. This is slightly against the philosophy of a Dockerfile (which# |
17 | 17 | # should produce perfectly reproducible outputs) but building Sage from scratch#
|
18 | 18 | # just takes too long at the moment to do this all the time. ARTIFACT_BASE #
|
19 | 19 | # controls which build artifacts are used. You probably want to set this to #
|
20 |
| -# sagemath/sagemath-dev:latest which takes the latest build from the official # |
21 |
| -# master branch. The default is source-clean which builds Sage from scratch. # |
| 20 | +# sagemath/sagemath-dev:develop which takes the latest build from the official # |
| 21 | +# develop branch. The default is source-clean which builds Sage from scratch. # |
22 | 22 | # If you want to understand how this works, have a look at source-from-context #
|
23 | 23 | # which merges ARTIFACT_BASE with the context, i.e., the contents of the sage #
|
24 | 24 | # source directory. #
|
|
92 | 92 | FROM $ARTIFACT_BASE as source-from-context
|
93 | 93 | WORKDIR $HOME
|
94 | 94 | COPY --chown=sage:sage . sage-context
|
95 |
| -# Checkout the commit that is in $HOME/sage-context |
| 95 | +# Checkout the commit that checked out in $HOME/sage-context |
| 96 | +# This is a bit complicated because our local .git/ is empty and we want to |
| 97 | +# make sure that we only change the mtimes of a minimal number of files. |
| 98 | +# 1) Restore the git checkout ARTIFACT_BASE was built from, recorded in |
| 99 | +# docker/commit. (Or go directly to FETCH_HEAD if there is no history to |
| 100 | +# restore.) |
| 101 | +# 2) Merge in FETCH_HEAD but only if it is a fast-forward, i.e., if it is an |
| 102 | +# ancestor of the commit restored in 1. If we would not do that we would get |
| 103 | +# a new commit hash in docker/commit that is not known outside of this build |
| 104 | +# run. Since docker/commit was in the history of FETCH_HEAD this should |
| 105 | +# automatically be a fast-forward. |
| 106 | +# 3) Trash .git again to save some space. |
96 | 107 | ARG SAGE_ROOT=/home/sage/sage
|
97 | 108 | WORKDIR $SAGE_ROOT
|
98 | 109 | RUN git fetch "$HOME/sage-context" HEAD \
|
99 |
| - && git reset FETCH_HEAD \ |
100 |
| - && git checkout -f FETCH_HEAD \ |
| 110 | + && if [ -e docker/commit ]; then \ |
| 111 | + git reset `cat docker/commit` \ |
| 112 | + || ( echo "Could not find commit `cat docker/commit` in your local Git history. Please merge in the latest develop branch to fix this: git fetch trac && git merge trac/develop." && exit 1 ) \ |
| 113 | + else \ |
| 114 | + echo "You are building from $ARTIFACT_BASE which has no docker/commit file. That's a bug unless you are building from source-clean or something similar." \ |
| 115 | + && git reset FETCH_HEAD \ |
| 116 | + && git checkout -f FETCH_HEAD; \ |
| 117 | + fi \ |
| 118 | + && git merge --ff-only FETCH_HEAD \ |
101 | 119 | && git log -1 --format=%H > docker/commit \
|
102 | 120 | && rm -rf .git
|
103 |
| -# Copy over all the untracked/staged/unstaged changes from sage-context |
| 121 | +# Copy over all the untracked/staged/unstaged changes from sage-context. This |
| 122 | +# is relevant for non-CI invocations of this Dockerfile. |
104 | 123 | WORKDIR $HOME/sage-context
|
105 | 124 | RUN if git status --porcelain | read CHANGES; then \
|
106 | 125 | git -c user.name=docker-build -c [email protected] stash -u \
|
|
0 commit comments