Skip to content

Commit

Permalink
Update Dockerfile for Sage 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu authored and Alice committed Jan 28, 2024
0 parents commit d6c71fe
Show file tree
Hide file tree
Showing 8 changed files with 2,315 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Dockerfile for binder
# Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html

# Pull the Sage docker image
FROM ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets:dev AS target

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

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

USER root

# These lines are here to remove warnings
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NOWARNINGS="yes"

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

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

# Install /sage
COPY --from=target /sage/src/bin /sage/src/bin
COPY --from=target /sage/src/sage /sage/src/sage
COPY --from=target /sage/local /sage/local
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

# Remove built doc
RUN rm -R /sage/local/share/doc

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

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

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

env:
SAGE_DOCKER: ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets
TAG: dev
BRANCH: dev

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Get SageMath version
run: |
SAGE_VERSION=$(docker run --rm $SAGE_DOCKER:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
echo "SAGE_VERSION=${SAGE_VERSION}" >> $GITHUB_ENV
- name: Replace Docker image tag
run: |
IMAGE_NAME="${SAGE_DOCKER}:${SAGE_VERSION}"
echo "SAGE_DOCKER_VERSION=${IMAGE_NAME}" >> $GITHUB_ENV
- name: Update Dockerfile
run: |
SAGE_DOCKER_VERSION_ESCAPED=$(echo "${SAGE_DOCKER_VERSION}" | sed 's/\//\\\//g')
sed -i "s/FROM \S*/FROM $SAGE_DOCKER_VERSION_ESCAPED/g" Dockerfile
working-directory: .github/workflows
- 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
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .github/workflows
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Update Dockerfile
run: |
IMAGE_NAME=ghcr.io/${{ github.repository }}:$BRANCH
IMAGE_NAME_ESCAPED=$(echo "${IMAGE_NAME}" | sed 's/\//\\\//g')
sed -i "s/FROM \S*/FROM $IMAGE_NAME_ESCAPED/g" Dockerfile
sed -i "s/FROM \S*/FROM $SAGE_DOCKER_UPDATED_ESCAPED/g" README.rst
- name: Have Binder build
timeout-minutes: 10
continue-on-error: true
run: |
curl --keepalive-time 600 -L https://mybinder.org/build/gh/kwankyu/sage-binder-env/$BRANCH
49 changes: 49 additions & 0 deletions .github/workflows/update-dockerfile-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Monitor Sage stable image updates

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

jobs:
build:
runs-on: ubuntu-latest

env:
SAGE_DOCKER_LATEST: "ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets:latest"

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: master

- name: Get SageMath version
run: |
SAGE_VERSION=$(docker run --rm $SAGE_DOCKER_LATEST /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?')
echo "SAGE_VERSION=${SAGE_VERSION}" >> $GITHUB_ENV
- name: Replace Docker image tag
run: |
SAGE_IMAGE_NAME="${SAGE_DOCKER_LATEST%:latest}"
NEW_IMAGE_NAME="${SAGE_IMAGE_NAME}:${SAGE_VERSION}"
echo "SAGE_DOCKER_UPDATED=${NEW_IMAGE_NAME}" >> $GITHUB_ENV
- name: Update Dockerfile
run: |
SAGE_DOCKER_UPDATED_ESCAPED=$(echo "${SAGE_DOCKER_UPDATED}" | sed 's/\//\\\//g')
sed -i "s/FROM \S*/FROM $SAGE_DOCKER_UPDATED_ESCAPED/g" Dockerfile
sed -i "s/FROM \S*/FROM $SAGE_DOCKER_UPDATED_ESCAPED/g" README.rst
- name: Commit changes
run: |
git config --global user.email alice@wonderland
git config --global user.name Alice
git commit -a --amend -m "Update Dockerfile for Sage ${SAGE_VERSION}"
git push -f origin master
- name: Have Binder build
timeout-minutes: 10
continue-on-error: true
run: |
curl -L https://mybinder.org/build/gh/sagemath/sage-binder-env/master
Empty file added .gitignore
Empty file.
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Dockerfile for binder
# Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html

# Pull the Sage docker image
FROM ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets:10.2

USER root

# These lines are here to remove warnings
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NOWARNINGS="yes"

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

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

# Create user "alice" whose uid is 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_UID} ${HOME}

# Install jupyterlab to Sage
RUN /sage/sage -pip install --no-warn-script-location jupyterlab

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

# Switch to the user
USER ${NB_USER}

# This is where kernels are installed
RUN mkdir -p $(jupyter --data-dir)/kernels

# Install sagemath kernel
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 d6c71fe

Please sign in to comment.