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

Commit a77dc10

Browse files
committed
Merge pull request #16 from embray/reorg
First reorganization
2 parents 929e4fa + cb02bd9 commit a77dc10

10 files changed

+114
-133
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
*.log
2+
3+
# Generated files
4+
*/scripts/common
5+
6+
# Editor files
7+
*.sw[po]

Makefile

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
all: check_postinstall
1+
.PHONY: all build clean docker-clean sagemath-develop-test
22

33
# Images and their dependencies
44
IMAGES=sagemath sagemath-develop sagemath-jupyter sagemath-patchbot
55

6-
sagemath: sagemath/install_sage.sh sagemath/postinstall_sage.sh
6+
common_scripts:=$(wildcard common/*.sh)
7+
common_script_copies:=$(addprefix %/scripts/, $(common_scripts))
8+
scripts=$(common_script_copies)
79

8-
sagemath-develop: sagemath/install_sage.sh sagemath/postinstall_sage.sh
10+
all: build
11+
12+
sagemath: %: $(scripts)
13+
14+
sagemath-develop: %: $(scripts)
915

1016
sagemath-jupyter: sagemath
1117

@@ -18,6 +24,9 @@ build: $(IMAGES)
1824
push:
1925
for image in $(IMAGES); do docker push sagemath/$$image; done
2026

27+
clean:
28+
for image in $(IMAGES); do rm -rf $(image)/scripts/common; done
29+
2130
# Refs:
2231
# - https://www.calazan.com/docker-cleanup-commands/
2332
# - http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers
@@ -31,12 +40,15 @@ docker-clean:
3140

3241
# Takes care of common file that we need to duplicate in several subdirectories
3342
# See https://github.com/docker/docker/issues/1676
34-
%/postinstall_sage.sh: postinstall_sage.sh
35-
cp $< > $@
36-
37-
38-
sagemat%: sagemat%/Dockerfile FORCE
39-
echo Building sagemath/$@
43+
$(common_script_copies): $(common_scripts)
44+
@echo "Copying $< > $@"
45+
mkdir -p $(@D)
46+
head -1 $< > $@
47+
echo "# !!! GENERATED FILE: DO NOT MODIFY! !!!" >> $@
48+
tail -n +2 $< >> $@
49+
50+
$(IMAGES): %: %/Dockerfile FORCE
51+
@echo Building sagemath/$@
4052
time docker build --tag="sagemath/$@" $@ 2>&1 | tee $@.log
4153

4254
FORCE:

common/install_sage.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# !!!NOTE!!! This script is intended to be run with root privileges
3+
# It will run as the 'sage' user when the time is right.
4+
SAGE_SRC_TARGET=${1%/}
5+
BRANCH=$2
6+
7+
if [ -z $SAGE_SRC_TARGET ]; then
8+
>&2 echo "Must specifiy a target directory for the sage source checkout"
9+
exit 1
10+
fi
11+
12+
if [ -z $BRANCH ]; then
13+
>&2 echo "Must specify a branch to build"
14+
exit 1
15+
fi
16+
17+
N_CORES=$(cat /proc/cpuinfo | grep processor | wc -l)
18+
19+
export SAGE_FAT_BINARY="yes"
20+
export MAKE="make -j${N_CORES}"
21+
cd "$SAGE_SRC_TARGET"
22+
git clone --depth 1 --branch ${BRANCH} https://github.com/sagemath/sage.git
23+
chown -R sage:sage sage
24+
cd sage
25+
26+
# Sage can't be built as root, for reasons...
27+
# Here -E inherits the environment from root, however it's important to
28+
# include -H to set HOME=/home/sage, otherwise DOT_SAGE will not be set
29+
# correctly and the build will fail!
30+
sudo -H -E -u sage make || exit 1
31+
32+
# Put scripts to start gap, gp, maxima, ... in /usr/bin
33+
./sage --nodotsage -c "install_scripts('/usr/bin')"
34+
35+
# Add aliases for sage and sagemath
36+
ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sage
37+
ln -sf "${SAGE_SRC_TARGET}/sage/sage" /usr/bin/sagemath
38+
39+
# Setup the admin password for Sage's lecacy notebook to avoid need for later
40+
# user interaction
41+
# This should also be run as the 'sage' user to ensure that the resulting
42+
# configuration is written to their DOT_SAGE
43+
sudo -H -u sage ./sage <<EOFSAGE
44+
from sage.misc.misc import DOT_SAGE
45+
from sagenb.notebook import notebook
46+
directory = DOT_SAGE+'sage_notebook'
47+
nb = notebook.load_notebook(directory)
48+
nb.user_manager().add_user('admin', 'sage', '', force=True)
49+
nb.save()
50+
quit
51+
EOFSAGE
52+
53+
# Clean up artifacts from the sage build that we don't need for runtime or
54+
# running the tests
55+
#
56+
# Unfortunately none of the existing make targets for sage cover this ground
57+
# exactly
58+
make misc-clean
59+
make -C src/ clean
60+
rm -rf upstream/
61+
rm -rf src/doc/output/doctrees/

postinstall_sage.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

sagemath-develop/Dockerfile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ FROM ubuntu:wily
22

33
MAINTAINER Sebastian Gutsche <[email protected]>
44

5+
ARG SAGE_SRC_TARGET=/opt
6+
# Note: SAGE_BRANCH may also be a tag name
7+
ARG SAGE_BRANCH=develop
8+
59
RUN apt-get update -qq \
6-
&& apt-get install -y wget build-essential m4 dpkg-dev sudo python libssl-dev git \
10+
&& apt-get install -y wget build-essential automake m4 dpkg-dev sudo python libssl-dev git \
711
&& apt-get clean \
812
&& rm -rf /var/lib/apt/lists/*
913

@@ -12,24 +16,19 @@ RUN adduser --quiet --shell /bin/bash --gecos "Sage user,101,," --disabled-pa
1216
&& adduser sage sudo \
1317
&& chown -R sage:sage /home/sage/
1418

15-
USER sage
16-
19+
COPY scripts/ /tmp/scripts
20+
RUN chmod -R +x /tmp/scripts
21+
# make source checkout target, then run the install script
1722
# see https://github.com/docker/docker/issues/9547 for the sync
18-
19-
ADD install_sage.sh /tmp/install_sage.sh
20-
RUN sudo chown sage:sage /tmp/install_sage.sh \
21-
&& chmod +x /tmp/install_sage.sh \
23+
RUN mkdir -p $SAGE_SRC_TARGET \
24+
&& /tmp/scripts/common/install_sage.sh $SAGE_SRC_TARGET $SAGE_BRANCH \
2225
&& sync \
23-
&& /tmp/install_sage.sh
24-
25-
ADD postinstall_sage.sh /tmp/postinstall_sage.sh
26-
RUN sudo chown sage:sage /tmp/postinstall_sage.sh \
27-
&& chmod +x /tmp/postinstall_sage.sh \
28-
&& sync \
29-
&& /tmp/postinstall_sage.sh
30-
26+
&& rm -rf /tmp/scripts
3127

28+
USER sage
3229
ENV HOME /home/sage
3330
WORKDIR /home/sage
3431

32+
EXPOSE 8080
33+
3534
CMD [ "sage" ]

sagemath-develop/install_sage.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

sagemath-develop/postinstall_sage.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

sagemath/Dockerfile

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ FROM ubuntu:wily
22

33
MAINTAINER Sebastian Gutsche <[email protected]>
44

5+
ARG SAGE_SRC_TARGET=/opt
6+
# Note: SAGE_BRANCH may also be a tag name
7+
ARG SAGE_BRANCH=7.0
8+
59
RUN apt-get update -qq \
6-
&& apt-get install -y wget build-essential m4 dpkg-dev sudo python libssl-dev \
10+
&& apt-get install -y wget build-essential automake m4 dpkg-dev sudo python libssl-dev git \
711
&& apt-get clean \
812
&& rm -rf /var/lib/apt/lists/*
913

@@ -12,22 +16,16 @@ RUN adduser --quiet --shell /bin/bash --gecos "Sage user,101,," --disabled-pa
1216
&& adduser sage sudo \
1317
&& chown -R sage:sage /home/sage/
1418

15-
USER sage
16-
19+
COPY scripts/ /tmp/scripts
20+
RUN chmod -R +x /tmp/scripts
21+
# make source checkout target, then run the install script
1722
# see https://github.com/docker/docker/issues/9547 for the sync
18-
19-
ADD install_sage.sh /tmp/install_sage.sh
20-
RUN sudo chown sage:sage /tmp/install_sage.sh \
21-
&& chmod +x /tmp/install_sage.sh \
23+
RUN mkdir -p $SAGE_SRC_TARGET \
24+
&& /tmp/scripts/common/install_sage.sh $SAGE_SRC_TARGET $SAGE_BRANCH \
2225
&& sync \
23-
&& /tmp/install_sage.sh
24-
25-
ADD postinstall_sage.sh /tmp/postinstall_sage.sh
26-
RUN sudo chown sage:sage /tmp/postinstall_sage.sh \
27-
&& chmod +x /tmp/postinstall_sage.sh \
28-
&& sync \
29-
&& /tmp/postinstall_sage.sh
26+
&& rm -rf /tmp/scripts
3027

28+
USER sage
3129
ENV HOME /home/sage
3230
WORKDIR /home/sage
3331

sagemath/install_sage.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

sagemath/postinstall_sage.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)