Skip to content

Commit

Permalink
Update files for Binder
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu authored and alice committed Apr 18, 2024
0 parents commit 45d8b2b
Show file tree
Hide file tree
Showing 8 changed files with 2,332 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.3 AS target

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

WORKDIR /sage

# Strip executables in /sage
RUN LC_ALL=C find local src pkgs -executable -type f -exec strip '{}' ';' 2>&1 | grep -v "file format not recognized" || true

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

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

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
82 changes: 82 additions & 0 deletions .github/workflows/update-dockerfile-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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: Prepare .github/Dockerfile
run: |
SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
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}
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
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 }}

# Update files for Binder

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Update files for Binder
run: |
PACKAGE_NAME=${{ env.PACKAGE_NAME }}
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 ${PACKAGE_NAME_ESCAPED}/g" README.rst
git config --global user.email alice@wonderland
git config --global user.name alice
git commit -a --amend -m "Update files for Binder"
git push -f origin $BRANCH
# 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
82 changes: 82 additions & 0 deletions .github/workflows/update-dockerfile-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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: Prepare .github/Dockerfile
run: |
SAGE_VERSION=$(docker run --rm ${SAGE_TARGET}:$TAG /sage/sage --version | grep -oP 'SageMath version \K[0-9.]+(?:beta\d+)?(?:rc\d+)?')
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}
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
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 }}

# Update files for Binder

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Update files for Binder
run: |
PACKAGE_NAME=${{ env.PACKAGE_NAME }}
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 ${PACKAGE_NAME_ESCAPED}/g" README.rst
git config --global user.email alice@wonderland
git config --global user.name alice
git commit -a --amend -m "Update files for Binder"
git push -f origin $BRANCH
# 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.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Dockerfile for binder
# Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html

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

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}

# 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}

0 comments on commit 45d8b2b

Please sign in to comment.