-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# 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 | ||
|
||
USER root | ||
|
||
# Remove warnings | ||
ENV DEBIAN_FRONTEND noninteractive | ||
ENV DEBCONF_NOWARNINGS="yes" | ||
|
||
# Install system packages | ||
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 the pupup of Jupyter news | ||
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements" | ||
|
||
# Create the 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} | ||
|
||
# Prepare for building Sage | ||
ENV PR_REPO https://github.com/REPO_NAME | ||
ENV PR_BRANCH BRANCH_NAME | ||
ENV BINDER_BRANCH sagemath-environment | ||
RUN apt-get install -y git | ||
|
||
# Build Sage incrementally | ||
WORKDIR /sage | ||
RUN export PATH="/sage/build/bin:$PATH" | ||
RUN git config --global user.email ${NB_USER}@wonderland | ||
RUN git config --global user.name ${NB_USER} | ||
RUN git config --global --add safe.directory $(pwd) | ||
RUN pwd | ||
COPY .gitignore /sage/.gitignore | ||
RUN if [ ! -d .git ]; then git init && git add -A; fi | ||
RUN git fetch ${PR_REPO} ${PR_BRANCH} | ||
RUN git checkout -f -b ${BINDER_BRANCH} FETCH_HEAD | ||
RUN ./bootstrap && ./configure --enable-build-as-root && make -j4 | ||
|
||
# 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 packages | ||
# 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Create Binder branch | ||
|
||
# How to use this workflow | ||
# | ||
# (1) Go to your forked Sage repo | ||
# (2) In the Actions tab, find "Create Binder branch" workflow | ||
# (3) Run the workflow with your PR branch named say "contribution" | ||
# (4) Wait for the workflow run to finish | ||
# (5) In the Code tab, select the new "contribution-binder" branch | ||
# (6) Find the Binder badge in README.md | ||
# (7) Copy the Binder badge from README.md (in edit mode) | ||
# (8) Paste the Binder badge into the description of your PR in the sagemath/sage repo | ||
# (9) Click the Binder badge to start creating the Binder environment | ||
# (10) Leave it open and come back after an hour. | ||
# (11) The Binder badge is now ready for reviewers of your PR | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
create-branch: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Create binder branch | ||
run: | | ||
set -ex | ||
REPO_NAME=${{ github.repository }} | ||
BRANCH_NAME=${GITHUB_REF#refs/heads/} | ||
BINDER_REPO_NAME=${REPO_NAME} | ||
BINDER_BRANCH_NAME=${BRANCH_NAME}-binder | ||
cp .github/workflows/binder-dockerfile Dockerfile | ||
sed -i 's/REPO_NAME/'$(echo "${REPO_NAME}" | sed 's/\//\\\//g')'/' Dockerfile | ||
sed -i 's/BRANCH_NAME/'$(echo "${BRANCH_NAME}" | sed 's/\//\\\//g')'/' Dockerfile | ||
sed -i 's/sagemath\/sage-binder-env\/master/'$(echo "${BINDER_REPO_NAME}/${BINDER_BRANCH_NAME}" | sed 's/\//\\\//g')'/' README.md | ||
if [ ! -d .git ]; then git init; fi | ||
if [ ! -d notebooks ]; then mkdir notebooks && touch notebooks/my_favorite_notebooks.md; fi | ||
git config --global user.email alice@wonderland | ||
git config --global user.name Alice | ||
git config --global --add safe.directory $(pwd) | ||
git checkout -b $BINDER_BRANCH_NAME | ||
git add -A | ||
git commit -a -m "Binder environment for '${BRANCH_NAME}' branch" | ||
git push -f origin $BINDER_BRANCH_NAME |