Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/docker/build-docker.sh
4052 views
1
#!/bin/sh
2
3
# This script gets called from CI to build several flavours of docker images
4
# which contain Sage.
5
6
# ****************************************************************************
7
# Copyright (C) 2018 Julian Rüth <[email protected]>
8
#
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 2 of the License, or
12
# (at your option) any later version.
13
# http://www.gnu.org/licenses/
14
# ****************************************************************************
15
16
set -ex
17
18
# We speed up the build process by copying built artifacts from ARTIFACT_BASE
19
# during docker build. See /docker/Dockerfile for more details.
20
ARTIFACT_BASE=${ARTIFACT_BASE:-sagemath/sagemath-dev:develop}
21
22
# Seed our cache with $ARTIFACT_BASE if it exists.
23
docker pull "$ARTIFACT_BASE" > /dev/null || true
24
25
docker_build() {
26
# Docker's --cache-from does not really work with multi-stage builds: https://github.com/moby/moby/issues/34715
27
# So we just have to rely on the local cache.
28
time docker build -f docker/Dockerfile \
29
--build-arg "MAKEFLAGS=${MAKEFLAGS}" --build-arg "SAGE_NUM_THREADS=${SAGE_NUM_THREADS}" --build-arg "MAKEFLAGS_DOCBUILD=${MAKEFLAGS}" --build-arg "SAGE_NUM_THREADS_DOCBUILD=${SAGE_NUM_THREADS_DOCBUILD}" --build-arg ARTIFACT_BASE=$ARTIFACT_BASE $@
30
}
31
32
# We use a multi-stage build /docker/Dockerfile. For the caching to be
33
# effective, we populate the cache by building the run/build-time-dependencies
34
# and the make-all target. (Just building the last target is not enough as
35
# intermediate targets could be discarded from the cache [depending on the
36
# docker version] and therefore the caching would fail for our actual builds
37
# below.)
38
docker_build --target run-time-dependencies --tag run-time-dependencies:$DOCKER_TAG .
39
docker_build --target build-time-dependencies --tag build-time-dependencies:$DOCKER_TAG .
40
docker_build --target make-all --tag make-all:$DOCKER_TAG .
41
42
# Copy docs out of the docker image to save them into browseable GitLab artifacts
43
container=$(docker create make-all:$DOCKER_TAG)
44
docker cp $container:/home/sage/sage/local/share/doc/sage/html html_
45
# GitLab's browser does not like symlinks, so we flatten them
46
rsync html_/ html/ -a --copy-links
47
48
# Build the release image without build artifacts.
49
docker_build --target sagemath --tag "$DOCKER_IMAGE_CLI" .
50
# Tag the sagemath:$DOCKER_TAG image that CI has just built as
51
# sagemath:$COMMIT_HASH so we can refer to it uniquely later.
52
docker tag "$DOCKER_IMAGE_CLI" "$DOCKER_IMAGE_BINDER"
53
# Display the layers of this image
54
docker history "$DOCKER_IMAGE_CLI"
55
# Build the developer image with the build artifacts intact.
56
# Note: It is important to build the dev image last because it might be tagged as ARTIFACT_BASE.
57
docker_build --target sagemath-dev --tag "$DOCKER_IMAGE_DEV" .
58
# Display the layers of this image
59
docker history "$DOCKER_IMAGE_DEV"
60
61