#!/bin/sh12# This script gets called from CI to build several flavours of docker images3# which contain Sage.45# ****************************************************************************6# Copyright (C) 2018 Julian Rüth <[email protected]>7#8# This program is free software: you can redistribute it and/or modify9# it under the terms of the GNU General Public License as published by10# the Free Software Foundation, either version 2 of the License, or11# (at your option) any later version.12# http://www.gnu.org/licenses/13# ****************************************************************************1415set -ex1617# We speed up the build process by copying built artifacts from ARTIFACT_BASE18# during docker build. See /docker/Dockerfile for more details.19ARTIFACT_BASE=${ARTIFACT_BASE:-sagemath/sagemath-dev:develop}2021# Seed our cache with $ARTIFACT_BASE if it exists.22docker pull "$ARTIFACT_BASE" > /dev/null || true2324docker_build() {25# Docker's --cache-from does not really work with multi-stage builds: https://github.com/moby/moby/issues/3471526# So we just have to rely on the local cache.27time docker build -f docker/Dockerfile \28--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 $@29}3031# We use a multi-stage build /docker/Dockerfile. For the caching to be32# effective, we populate the cache by building the run/build-time-dependencies33# and the make-all target. (Just building the last target is not enough as34# intermediate targets could be discarded from the cache [depending on the35# docker version] and therefore the caching would fail for our actual builds36# below.)37docker_build --target run-time-dependencies --tag run-time-dependencies:$DOCKER_TAG .38docker_build --target build-time-dependencies --tag build-time-dependencies:$DOCKER_TAG .39docker_build --target make-all --tag make-all:$DOCKER_TAG .4041# Copy docs out of the docker image to save them into browseable GitLab artifacts42container=$(docker create make-all:$DOCKER_TAG)43docker cp $container:/home/sage/sage/local/share/doc/sage/html html_44# GitLab's browser does not like symlinks, so we flatten them45rsync html_/ html/ -a --copy-links4647# Build the release image without build artifacts.48docker_build --target sagemath --tag "$DOCKER_IMAGE_CLI" .49# Tag the sagemath:$DOCKER_TAG image that CI has just built as50# sagemath:$COMMIT_HASH so we can refer to it uniquely later.51docker tag "$DOCKER_IMAGE_CLI" "$DOCKER_IMAGE_BINDER"52# Display the layers of this image53docker history "$DOCKER_IMAGE_CLI"54# Build the developer image with the build artifacts intact.55# Note: It is important to build the dev image last because it might be tagged as ARTIFACT_BASE.56docker_build --target sagemath-dev --tag "$DOCKER_IMAGE_DEV" .57# Display the layers of this image58docker history "$DOCKER_IMAGE_DEV"596061