Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

First reorganization #16

Merged
merged 3 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
*.log

# Generated files
*/scripts/common

# Editor files
*.sw[po]
30 changes: 21 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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 [email protected]

FORCE:
Expand Down
61 changes: 61 additions & 0 deletions common/install_sage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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...
# 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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note--I've reworked this script so that it is run as root (before the USER sage command in the Dockerfile). This gives it freedom to perform operations that should be done as root, like creating links in /usr/bin/. However it runs the sage build as the sage user.

This means there's actually no reason for the sage user to be in the sudoers list in the first place, and we could remove that entirely (though this PR doesn't do that yet).


# 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
# 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 <<EOFSAGE
from sage.misc.misc import DOT_SAGE
from sagenb.notebook import notebook
directory = DOT_SAGE+'sage_notebook'
nb = notebook.load_notebook(directory)
nb.user_manager().add_user('admin', 'sage', '', force=True)
nb.save()
quit
EOFSAGE

# Clean up artifacts from the sage build that we don't need for runtime or
# running the tests
#
# Unfortunately none of the existing make targets for sage cover this ground
# exactly
make misc-clean
make -C src/ clean
rm -rf upstream/
rm -rf src/doc/output/doctrees/
21 changes: 0 additions & 21 deletions postinstall_sage.sh

This file was deleted.

29 changes: 14 additions & 15 deletions sagemath-develop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ FROM ubuntu:wily

MAINTAINER Sebastian Gutsche <[email protected]>

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/*

Expand All @@ -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" ]
15 changes: 0 additions & 15 deletions sagemath-develop/install_sage.sh

This file was deleted.

21 changes: 0 additions & 21 deletions sagemath-develop/postinstall_sage.sh

This file was deleted.

26 changes: 12 additions & 14 deletions sagemath/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ FROM ubuntu:wily

MAINTAINER Sebastian Gutsche <[email protected]>

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/*

Expand All @@ -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

Expand Down
17 changes: 0 additions & 17 deletions sagemath/install_sage.sh

This file was deleted.

21 changes: 0 additions & 21 deletions sagemath/postinstall_sage.sh

This file was deleted.