|
| 1 | +#!/bin/bash |
| 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 | +set -ex |
| 16 | + |
| 17 | +[[ -z "$DOCKER_TAG" ]] && DOCKER_TAG=none |
| 18 | +[[ "$DOCKER_TAG" = "master" ]] && DOCKER_TAG=latest |
| 19 | + |
| 20 | +. .ci/setup-make-parallelity.sh |
| 21 | + |
| 22 | +# We speed up the build process by copying built artifacts from ARTIFACT_BASE |
| 23 | +# during docker build. See /docker/Dockerfile for more details. |
| 24 | +ARTIFACT_BASE=${ARTIFACT_BASE:-sagemath/sagemath-dev:latest} |
| 25 | + |
| 26 | +# Seed our cache with $ARTIFACT_BASE if it exists |
| 27 | +docker pull $ARTIFACT_BASE || true |
| 28 | + |
| 29 | +function docker_build { |
| 30 | + time docker build -f docker/Dockerfile --build-arg "MAKE=${MAKE}" --build-arg ARTIFACT_BASE=$ARTIFACT_BASE $@ |
| 31 | +} |
| 32 | + |
| 33 | +# We use a multi-stage build /docker/Dockerfile. For the caching to be |
| 34 | +# effective, we populate the cache by building the make-all target. (Just |
| 35 | +# building the last target is not enough as intermediate targets would be |
| 36 | +# discarded from the cache and therefore the caching would fail for our actual |
| 37 | +# builds below.) |
| 38 | +docker_build --pull --tag make-all --target make-all . |
| 39 | + |
| 40 | +# Build the release image without build artifacts. |
| 41 | +DOCKER_IMAGE_CLI=${DOCKER_USER:-sagemath}/sagemath:$DOCKER_TAG |
| 42 | +docker_build --target sagemath --tag "$DOCKER_IMAGE_CLI" . |
| 43 | +# Build the developer image with the build artifacts intact. |
| 44 | +# Note: It's important to build the dev image last because it might be tagged as ARTIFACT_BASE. |
| 45 | +DOCKER_IMAGE_DEV=${DOCKER_USER:-sagemath}/sagemath-dev:$DOCKER_TAG |
| 46 | +docker_build --target sagemath-dev --tag "$DOCKER_IMAGE_DEV" . |
0 commit comments