Skip to content

Commit

Permalink
Dockerfile for Sage 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu authored and alice committed Sep 29, 2023
0 parents commit ad14542
Show file tree
Hide file tree
Showing 8 changed files with 2,318 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Multi-stage Dockerfile for slim Sage
# https://docs.docker.com/build/building/multi-stage

FROM ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets:10.0 AS target

# Resolve symbolic links to recreate them later
RUN readlink /sage/prefix >> /sage/prefix_link
RUN readlink /sage/venv >> /sage/venv_link

# To exclude doc directory in the next stage
RUN rm -rf /sage/local/share/doc

FROM ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-system-packages:10.0

USER root

# Remove warnings
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NOWARNINGS="yes"

# Install JupyterLab to the system
RUN apt-get update
RUN apt-get install -y python3-pip
RUN python3 -m pip install --no-warn-script-location notebook jupyterlab ipywidgets

# Disable annoying pupup for Jupyter news
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"

# Install /sage from target
COPY --from=target /sage/local /sage/local
COPY --from=target /sage/src/bin /sage/src/bin
COPY --from=target /sage/src/sage /sage/src/sage
COPY --from=target /sage/sage /sage/sage
COPY --from=target /sage/pkgs/sage-conf /sage/pkgs/sage-conf

# Recreate symbolic links
COPY --from=target /sage/prefix_link /sage/prefix_link
COPY --from=target /sage/venv_link /sage/venv_link
RUN ln -s $(cat /sage/prefix_link) /sage/prefix && rm /sage/prefix_link
RUN ln -s $(cat /sage/venv_link) /sage/venv && rm /sage/venv_link

# Configure Sage library
RUN /sage/sage -pip install --root-user-action=ignore /sage/pkgs/sage-conf

# Remove problematic lines!
RUN sed -i '/^__requires__/d' /sage/venv/bin/sage-venv-config
RUN sed -i '/^__import__/d' /sage/venv/bin/sage-venv-config
73 changes: 73 additions & 0 deletions .github/workflows/update-dockerfile-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Update dev image

on:
schedule:
- cron: '0 1 * * *' # Run every day
workflow_dispatch:

env:
SAGE_TARGET: ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets
SAGE_SYSTEM: ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-system-packages
TAG: dev
BRANCH: dev

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:

# Prepare .github/Dockerfile for slim Sage image

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Get SageMath version
run: |
SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
echo "SAGE_VERSION=${SAGE_VERSION}" >> $GITHUB_ENV
- name: Update version in files
run: |
SAGE_TARGET_ESCAPED=$(echo "${SAGE_TARGET}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
SAGE_TARGET_VERSION_ESCAPED=$(echo "${SAGE_TARGET}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
sed -i "s/FROM ${SAGE_TARGET_ESCAPED}:\S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" .github/Dockerfile
SAGE_SYSTEM_ESCAPED=$(echo "${SAGE_SYSTEM}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
SAGE_SYSTEM_VERSION_ESCAPED=$(echo "${SAGE_SYSTEM}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
sed -i "s/FROM ${SAGE_SYSTEM_ESCAPED}:\S*/FROM ${SAGE_SYSTEM_VERSION_ESCAPED}/g" .github/Dockerfile
PACKAGE_NAME=ghcr.io/${{ github.repository }}:${SAGE_VERSION}
PACKAGE_NAME_ESCAPED=$(echo "${PACKAGE_NAME}" | sed 's/\//\\\//g')
sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" Dockerfile
sed -i "s/FROM \S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" README.rst
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
- name: Commit changes
run: |
git config --global user.email alice@wonderland
git config --global user.name alice
git commit -a --amend -m "Dockerfile for Sage ${SAGE_VERSION}"
git push -f origin $BRANCH
# Build and publish the slim Sage image to github package registry (ghpr)

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .github
push: true
tags: ${{ env.PACKAGE_NAME }}

# Build docker image for Binder from Dockerfile at root

- name: Binder build
timeout-minutes: 30
continue-on-error: true
run: |
curl --keepalive-time 600 -L https://mybinder.org/build/gh/sagemath/sage-binder-env/$BRANCH
73 changes: 73 additions & 0 deletions .github/workflows/update-dockerfile-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Update master image

on:
schedule:
- cron: '0 0 * * *' # Run every day
workflow_dispatch:

env:
SAGE_TARGET: ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets
SAGE_SYSTEM: ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-system-packages
TAG: latest
BRANCH: master

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:

# Prepare .github/Dockerfile for slim Sage image

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Get SageMath version
run: |
SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
echo "SAGE_VERSION=${SAGE_VERSION}" >> $GITHUB_ENV
- name: Update version in files
run: |
SAGE_TARGET_ESCAPED=$(echo "${SAGE_TARGET}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
SAGE_TARGET_VERSION_ESCAPED=$(echo "${SAGE_TARGET}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
sed -i "s/FROM ${SAGE_TARGET_ESCAPED}:\S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" .github/Dockerfile
SAGE_SYSTEM_ESCAPED=$(echo "${SAGE_SYSTEM}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
SAGE_SYSTEM_VERSION_ESCAPED=$(echo "${SAGE_SYSTEM}:${SAGE_VERSION}" | sed 's/\//\\\//g' | sed 's/\./\\\./g')
sed -i "s/FROM ${SAGE_SYSTEM_ESCAPED}:\S*/FROM ${SAGE_SYSTEM_VERSION_ESCAPED}/g" .github/Dockerfile
PACKAGE_NAME=ghcr.io/${{ github.repository }}:${SAGE_VERSION}
PACKAGE_NAME_ESCAPED=$(echo "${PACKAGE_NAME}" | sed 's/\//\\\//g')
sed -i "s/FROM \S*/FROM ${PACKAGE_NAME_ESCAPED}/g" Dockerfile
sed -i "s/FROM \S*/FROM ${SAGE_TARGET_VERSION_ESCAPED}/g" README.rst
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
- name: Commit changes
run: |
git config --global user.email alice@wonderland
git config --global user.name alice
git commit -a --amend -m "Dockerfile for Sage ${SAGE_VERSION}"
git push -f origin $BRANCH
# Build and publish the slim Sage image to github package registry (ghpr)

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .github
push: true
tags: ${{ env.PACKAGE_NAME }}

# Build docker image for Binder from Dockerfile at root

- name: Binder build
timeout-minutes: 30
continue-on-error: true
run: |
curl --keepalive-time 600 -L https://mybinder.org/build/gh/sagemath/sage-binder-env/$BRANCH
Empty file added .gitignore
Empty file.
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Dockerfile for binder
# Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html

FROM ghcr.io/sagemath/sage-binder-env:10.0

USER root

# Create user alice with uid 1000
ARG NB_USER=alice
ARG NB_UID=1000
ENV NB_USER alice
ENV NB_UID 1000
ENV HOME /home/${NB_USER}
RUN adduser --disabled-password --gecos "Default user" --uid ${NB_UID} ${NB_USER}

# Make sure the contents of the notebooks directory are in ${HOME}
COPY notebooks/* ${HOME}/
RUN chown -R ${NB_USER}:${NB_USER} ${HOME}

# Install Sage package
# RUN /sage/sage -i <spkg-name>

# Switch to the user
USER ${NB_USER}

# Install Sage kernel to Jupyter
RUN mkdir -p $(jupyter --data-dir)/kernels
RUN ln -s /sage/venv/share/jupyter/kernels/sagemath $(jupyter --data-dir)/kernels

# Start in the home directory of the user
WORKDIR /home/${NB_USER}
Loading

0 comments on commit ad14542

Please sign in to comment.