From 2e5e6cf1d43c4152af16df1aa8106f3db456e96a Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Fri, 19 Feb 2016 10:55:51 +0100 Subject: [PATCH 1/3] Reworked Sage installation script to be shared between sagemath and sagemath-develop images, reducing the duplication between them. Improved the Makeful to clarify which files are generated and should be ignored by git. --- .gitignore | 6 +++ Makefile | 30 ++++++++++----- common/install_sage.sh | 55 ++++++++++++++++++++++++++++ postinstall_sage.sh | 21 ----------- sagemath-develop/Dockerfile | 29 +++++++-------- sagemath-develop/install_sage.sh | 15 -------- sagemath-develop/postinstall_sage.sh | 21 ----------- sagemath/Dockerfile | 26 ++++++------- sagemath/install_sage.sh | 17 --------- sagemath/postinstall_sage.sh | 21 ----------- 10 files changed, 108 insertions(+), 133 deletions(-) create mode 100755 common/install_sage.sh delete mode 100644 postinstall_sage.sh delete mode 100644 sagemath-develop/install_sage.sh delete mode 100644 sagemath-develop/postinstall_sage.sh delete mode 100644 sagemath/install_sage.sh delete mode 100644 sagemath/postinstall_sage.sh diff --git a/.gitignore b/.gitignore index 397b4a7..6c9c1bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ *.log + +# Generated files +*/scripts/common + +# Editor files +*.sw[po] diff --git a/Makefile b/Makefile index 05c8948..be05307 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,17 @@ -all: check_postinstall +.PHONY: all build clean docker-clean sagemath-develop-test # Images and their dependencies IMAGES=sagemath sagemath-develop sagemath-jupyter sagemath-patchbot -sagemath: sagemath/install_sage.sh sagemath/postinstall_sage.sh +common_scripts:=$(wildcard common/*.sh) +common_script_copies:=$(addprefix %/scripts/, $(common_scripts)) +scripts=$(common_script_copies) -sagemath-develop: sagemath/install_sage.sh sagemath/postinstall_sage.sh +all: build + +sagemath: %: $(scripts) + +sagemath-develop: %: $(scripts) sagemath-jupyter: sagemath @@ -18,6 +24,9 @@ build: $(IMAGES) push: for image in $(IMAGES); do docker push sagemath/$$image; done +clean: + for image in $(IMAGES); do rm -rf $(image)/scripts/common; done + # Refs: # - https://www.calazan.com/docker-cleanup-commands/ # - http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers @@ -31,12 +40,15 @@ docker-clean: # Takes care of common file that we need to duplicate in several subdirectories # See https://github.com/docker/docker/issues/1676 -%/postinstall_sage.sh: postinstall_sage.sh - cp $< > $@ - - -sagemat%: sagemat%/Dockerfile FORCE - echo Building sagemath/$@ +$(common_script_copies): $(common_scripts) + @echo "Copying $< > $@" + mkdir -p $(@D) + head -1 $< > $@ + echo "# !!! GENERATED FILE: DO NOT MODIFY! !!!" >> $@ + tail -n +2 $< >> $@ + +$(IMAGES): %: %/Dockerfile FORCE + @echo Building sagemath/$@ time docker build --tag="sagemath/$@" $@ 2>&1 | tee $@.log FORCE: diff --git a/common/install_sage.sh b/common/install_sage.sh new file mode 100755 index 0000000..f7dd118 --- /dev/null +++ b/common/install_sage.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# !!!NOTE!!! This script is intended to be run with root privileges +# It will run as the 'sage' user when the time is right. +SAGE_SRC_TARGET=${1%/} +BRANCH=$2 + +if [ -z $SAGE_SRC_TARGET ]; then + >&2 echo "Must specifiy a target directory for the sage source checkout" + exit 1 +fi + +if [ -z $BRANCH ]; then + >&2 echo "Must specify a branch to build" + exit 1 +fi + +N_CORES=$(cat /proc/cpuinfo | grep processor | wc -l) + +export SAGE_FAT_BINARY="yes" +export MAKE="make -j${N_CORES}" +cd "$SAGE_SRC_TARGET" +git clone --depth 1 --branch ${BRANCH} https://github.com/sagemath/sage.git +chown -R sage:sage sage +cd sage + +# Sage can't be built as root, for reasons... +sudo -H -E -u sage make || exit 1 + +# Put scripts to start gap, gp, maxima, ... in /usr/bin +./sage --nodotsage -c "install_scripts('/usr/bin')" + +# Add aliases for sage and sagemath +ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sage +ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sagemath + +# Setup the admin password for Sage's lecacy notebook to avoid need for later user interaction +./sage < +ARG SAGE_SRC_TARGET=/opt +# Note: SAGE_BRANCH may also be a tag name +ARG SAGE_BRANCH=develop + RUN apt-get update -qq \ - && apt-get install -y wget build-essential m4 dpkg-dev sudo python libssl-dev git \ + && apt-get install -y wget build-essential automake m4 dpkg-dev sudo python libssl-dev git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -12,24 +16,19 @@ RUN adduser --quiet --shell /bin/bash --gecos "Sage user,101,," --disabled-pa && adduser sage sudo \ && chown -R sage:sage /home/sage/ -USER sage - +COPY scripts/ /tmp/scripts +RUN chmod -R +x /tmp/scripts +# make source checkout target, then run the install script # see https://github.com/docker/docker/issues/9547 for the sync - -ADD install_sage.sh /tmp/install_sage.sh -RUN sudo chown sage:sage /tmp/install_sage.sh \ - && chmod +x /tmp/install_sage.sh \ +RUN mkdir -p $SAGE_SRC_TARGET \ + && /tmp/scripts/common/install_sage.sh $SAGE_SRC_TARGET $SAGE_BRANCH \ && sync \ - && /tmp/install_sage.sh - -ADD postinstall_sage.sh /tmp/postinstall_sage.sh -RUN sudo chown sage:sage /tmp/postinstall_sage.sh \ - && chmod +x /tmp/postinstall_sage.sh \ - && sync \ - && /tmp/postinstall_sage.sh - + && rm -rf /tmp/scripts +USER sage ENV HOME /home/sage WORKDIR /home/sage +EXPOSE 8080 + CMD [ "sage" ] diff --git a/sagemath-develop/install_sage.sh b/sagemath-develop/install_sage.sh deleted file mode 100644 index 42d5576..0000000 --- a/sagemath-develop/install_sage.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -number_cores=$(cat /proc/cpuinfo | grep processor | wc -l) - -export SAGE_FAT_BINARY="yes" -export MAKE="make -j${number_cores}" - - -cd /opt -sudo git clone --depth 1 --branch develop https://github.com/sagemath/sage.git -sudo chown -R sage:sage /opt/sage - -cd sage -make - diff --git a/sagemath-develop/postinstall_sage.sh b/sagemath-develop/postinstall_sage.sh deleted file mode 100644 index c57aba6..0000000 --- a/sagemath-develop/postinstall_sage.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cd /opt/sage - -# Put scripts to start gap, gp, maxima, ... in /usr/bin -sudo ./sage --nodotsage -c "install_scripts('/usr/bin')" - -# Add aliases for sage and sagemath -sudo ln -sf /opt/sage/sage /usr/bin/sage -sudo ln -sf /opt/sage/sage /usr/bin/sagemath - -# Setup the admin password for Sage's lecacy notebook to avoid need for later user interaction -./sage < +ARG SAGE_SRC_TARGET=/opt +# Note: SAGE_BRANCH may also be a tag name +ARG SAGE_BRANCH=7.0 + RUN apt-get update -qq \ - && apt-get install -y wget build-essential m4 dpkg-dev sudo python libssl-dev \ + && apt-get install -y wget build-essential automake m4 dpkg-dev sudo python libssl-dev git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -12,22 +16,16 @@ RUN adduser --quiet --shell /bin/bash --gecos "Sage user,101,," --disabled-pa && adduser sage sudo \ && chown -R sage:sage /home/sage/ -USER sage - +COPY scripts/ /tmp/scripts +RUN chmod -R +x /tmp/scripts +# make source checkout target, then run the install script # see https://github.com/docker/docker/issues/9547 for the sync - -ADD install_sage.sh /tmp/install_sage.sh -RUN sudo chown sage:sage /tmp/install_sage.sh \ - && chmod +x /tmp/install_sage.sh \ +RUN mkdir -p $SAGE_SRC_TARGET \ + && /tmp/scripts/common/install_sage.sh $SAGE_SRC_TARGET $SAGE_BRANCH \ && sync \ - && /tmp/install_sage.sh - -ADD postinstall_sage.sh /tmp/postinstall_sage.sh -RUN sudo chown sage:sage /tmp/postinstall_sage.sh \ - && chmod +x /tmp/postinstall_sage.sh \ - && sync \ - && /tmp/postinstall_sage.sh + && rm -rf /tmp/scripts +USER sage ENV HOME /home/sage WORKDIR /home/sage diff --git a/sagemath/install_sage.sh b/sagemath/install_sage.sh deleted file mode 100644 index f4ae020..0000000 --- a/sagemath/install_sage.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -number_cores=$(cat /proc/cpuinfo | grep processor | wc -l) - -export SAGE_FAT_BINARY="yes" -export MAKE="make -j${number_cores}" - - -cd /opt -sudo wget http://www-ftp.lip6.fr/pub/math/sagemath/src/sage-7.0.tar.gz -sudo tar -xf sage-7.0.tar.gz -sudo rm sage-7.0.tar.gz -sudo chown -R sage:sage /opt/sage-7.0 -sudo ln -sf sage-7.0 sage - -cd sage -make \ No newline at end of file diff --git a/sagemath/postinstall_sage.sh b/sagemath/postinstall_sage.sh deleted file mode 100644 index c57aba6..0000000 --- a/sagemath/postinstall_sage.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cd /opt/sage - -# Put scripts to start gap, gp, maxima, ... in /usr/bin -sudo ./sage --nodotsage -c "install_scripts('/usr/bin')" - -# Add aliases for sage and sagemath -sudo ln -sf /opt/sage/sage /usr/bin/sage -sudo ln -sf /opt/sage/sage /usr/bin/sagemath - -# Setup the admin password for Sage's lecacy notebook to avoid need for later user interaction -./sage < Date: Tue, 23 Feb 2016 17:34:08 +0100 Subject: [PATCH 2/3] Oops, this configuration should also be performed as the 'sage' user so that it goes into the correct .sage directory. --- common/install_sage.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/install_sage.sh b/common/install_sage.sh index f7dd118..02030a4 100755 --- a/common/install_sage.sh +++ b/common/install_sage.sh @@ -33,8 +33,9 @@ sudo -H -E -u sage make || exit 1 ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sage ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sagemath -# Setup the admin password for Sage's lecacy notebook to avoid need for later user interaction -./sage < Date: Wed, 24 Feb 2016 16:24:54 +0100 Subject: [PATCH 3/3] Adding some clarification I meant to include. --- common/install_sage.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/install_sage.sh b/common/install_sage.sh index 02030a4..ab5db94 100755 --- a/common/install_sage.sh +++ b/common/install_sage.sh @@ -24,6 +24,9 @@ chown -R sage:sage sage cd sage # Sage can't be built as root, for reasons... +# Here -E inherits the environment from root, however it's important to +# include -H to set HOME=/home/sage, otherwise DOT_SAGE will not be set +# correctly and the build will fail! sudo -H -E -u sage make || exit 1 # Put scripts to start gap, gp, maxima, ... in /usr/bin @@ -35,6 +38,8 @@ ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sagemath # Setup the admin password for Sage's lecacy notebook to avoid need for later # user interaction +# This should also be run as the 'sage' user to ensure that the resulting +# configuration is written to their DOT_SAGE sudo -H -u sage ./sage <