Skip to content

Commit

Permalink
Add 573 Python Image (#17)
Browse files Browse the repository at this point in the history
* Provide new python base

* Relocate changes for permissions issues

* Test course image

* Fix broken path

* Testing for 573

* Update 573/python/Dockerfile

Co-authored-by: Joel Ostblom <[email protected]>

---------

Co-authored-by: Joel Ostblom <[email protected]>
  • Loading branch information
ZacWarham and joelostblom authored Nov 25, 2024
1 parent 891b93d commit 4ebd37b
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 14 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/docker-publish-573-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Publishes docker image, pinning actions to a commit SHA,
# and updating most recently built image with the latest tag.
# Can be triggered by either pushing a commit that changes the `Dockerfile`,
# or manually dispatching the workflow.

name: Publish Docker image (573 Python)

on:
workflow_dispatch:
push:
paths:
- '573/python/Dockerfile'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ubcmds/573-python
tags: |
type=raw, value={{sha}},enable=${{github.ref_type != 'tag' }}
type=raw, value=latest
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: ./573/python
file: 573/python/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
44 changes: 44 additions & 0 deletions .github/workflows/docker-publish-tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Publishes docker image, pinning actions to a commit SHA,
# and updating most recently built image with the latest tag.
# Can be triggered by either pushing a commit that changes the `Dockerfile`,
# or manually dispatching the workflow.

name: Publish Docker image (Testing Purposes)

on:
workflow_dispatch:
push:
paths:
- 'base-python/course-example/Dockerfile'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ubcmds/pl-testing
tags: |
type=raw, value=pythonRebuild
type=raw, value=latest
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: ./base-python/course-example/
file: base-python/course-example/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
73 changes: 73 additions & 0 deletions 573/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
FROM jupyter/minimal-notebook:2023-10-20

ENV XDG_DATA_HOME=/tmp/local/share
ENV XDG_CACHE_HOME=/tmp/cache
ENV XDG_CONFIG_HOME=/tmp/config
ENV JUPYTER_RUNTIME_DIR /tmp/runtime
ENV JUPYTER_ALLOW_INSECURE_WRITES true
ENV JUPYTER_CONFIG_DIR=/tmp/jupyter_config
ENV NPM_CONFIG_CACHE=/tmp/npm
ENV NO_UPDATE_NOTIFIER=true
ENV IPYTHONDIR=/tmp/ipython
ENV YARN_CACHE_FOLDER=/tmp/yarn_cache
ENV PYTHONSTARTUP=/pythonstartup.py

USER root
# Install dependencies and various libraries
RUN apt-get update && apt-get -y upgrade
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Suppress the opt-in dialog for announcements.
# https://stackoverflow.com/questions/75511508/how-to-stop-this-message-would-you-like-to-receive-official-jupyter-news
RUN jupyter labextension disable @jupyterlab/apputils-extension:announcements
RUN mamba install --yes \
'altair-all==5.4.1' \
'vegafusion==1.6.9' \
'vega_datasets' \
'python>=3.11,<3.13' \
'pip' \
'ipykernel' \
'nb_conda_kernels' \
'otter-grader=6.*' \
'scipy' \
'matplotlib>=3.2.2' \
'scikit-learn' \
'requests>=2.24.0' \
'graphviz' \
'python-graphviz' \
'eli5' \
'shap' \
'jinja2' \
'lightgbm' \
'spacy' \
'xgboost' \
'catboost' \
'nltk' \
'imbalanced-learn' && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

RUN python -m pip install mglearn spacymoji "altair_ally>=0.1.1"


# This seems to be needed for Jupyterlab to get the anywidget extension installed
# although the package is technically already installed as part of altair-all.
# This package is needed to show altair charts offline, such as in CBTF.
# Each notebook need to start with `alt.renderers.enable('jupyter', offline=True)`
RUN python -m pip install anywidget
RUN pip3 cache purge

COPY jupyter_server_config.py /etc/jupyter/
#COPY plugin.jupyterlab-settings /etc/jupyter/
COPY ipython_config.py /etc/ipython/

RUN sed -i 's/"default": 120/"default": 1/' /opt/conda/share/jupyter/lab/schemas/@jupyterlab/docmanager-extension/plugin.json
RUN sed -i 's/"default": 120/"default": 1/' /opt/conda/lib/python3.11/site-packages/jupyterlab/schemas/@jupyterlab/docmanager-extension/plugin.json


EXPOSE 8080

USER jovyan
COPY pythonstartup.py /
CMD ["start.sh", "jupyter", "lab"]
3 changes: 3 additions & 0 deletions 573/python/ipython_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ipython_config.py
c = get_config()
c.Completer.use_jedi = False
32 changes: 32 additions & 0 deletions 573/python/jupyter_server_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

c = get_config() # type: ignore # noqa F821

c.ServerApp.base_url = "/"
if "WORKSPACE_BASE_URL" in os.environ:
c.NotebookApp.base_url = os.environ["WORKSPACE_BASE_URL"]

c.ServerApp.port = 8080
c.ServerApp.ip = "0.0.0.0"
c.ServerApp.open_browser = False
c.ServerApp.password = ""
c.ServerApp.token = ""
c.ServerApp.allow_origin = "*"

# RTC appears to be broken in the current version of `jupyter-collaboration`:
# https://github.com/jupyterlab/jupyter-collaboration/issues/162
# This opt-in will only be useful once the underlying issue is resolved.
enable_rtc = bool(os.environ.get("ENABLE_REAL_TIME_COLLABORATION", False))
c.YDocExtension.disable_rtc = not enable_rtc

# `LAUNCH_FILE_NAME` can be set to open a specific file when the workspace is opened.
if "LAUNCH_FILE_NAME" in os.environ:
# The "RTC" drive needs to be used if real-time collaboration is enabled.
# This isn't documented, but is discussed in these issues:
# https://github.com/jupyterlab/jupyter-collaboration/issues/202
# https://github.com/jupyterlab/jupyter-collaboration/issues/183
drive = "RTC:" if enable_rtc else ""
c.LabApp.default_url= f"/lab/tree/{drive}{os.environ['LAUNCH_FILE_NAME']}"

c.FileContentsManager.delete_to_trash = False
c.FileCheckpoints.checkpoint_dir = "/tmp/ipynb_checkpoints"
2 changes: 2 additions & 0 deletions 573/python/pythonstartup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import altair as alt
alt.renderers.enable('jupyter', offline=True)
17 changes: 11 additions & 6 deletions base-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the prairielearn modified version of jupyter lab
FROM prairielearn/workspace-jupyterlab-python:92c4d45d172f248640753e49dd6e4557431e3495
FROM prairielearn/workspace-jupyterlab-python:053e561ec8c268097e844a030ebbadb7afc276ec

# root required to install for ubuntu commands
USER root
Expand All @@ -9,6 +9,14 @@ RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Set auto-save interval
RUN sed -i '/"autosaveInterval": {/,/}/ s/"default": [0-9]*/"default": 1/' /opt/conda/share/jupyter/lab/schemas/@jupyterlab/docmanager-extension/plugin.json
RUN sed -i '/"autosaveInterval": {/,/}/ s/"default": [0-9]*/"default": 1/' /opt/conda/lib/python3.11/site-packages/jupyterlab/schemas/@jupyterlab/docmanager-extension/plugin.json

# Set default viewer for instructions
RUN sed -i '/"defaultViewers": {/,/}/ s/"default": {[^}]*}/"default": {"markdown": "Markdown Preview"}/' /opt/conda/share/jupyter/lab/schemas/@jupyterlab/docmanager-extension/plugin.json
RUN sed -i '/"defaultViewers": {/,/}/ s/"default": {[^}]*}/"default": {"markdown": "Markdown Preview"}/' /opt/conda/lib/python3.11/site-packages/jupyterlab/schemas/@jupyterlab/docmanager-extension/plugin.json

# jovyan is the default user for jupyter lab
USER jovyan

Expand All @@ -20,8 +28,5 @@ USER jovyan
# eg.
# RUN pip install --no-cache-dir $PYTHON_PACKAGES

# Create directories for user settings
RUN mkdir -p /tmp/jupyter_config/lab/user-settings/@jupyterlab/docmanager-extension/

# Copy the custom plugin.jupyterlab-settings file to the correct location to increase auto-save frequency
COPY plugin.jupyterlab-settings /tmp/jupyter_config/lab/user-settings/@jupyterlab/docmanager-extension/
# Disable jedi for autocomplete
COPY ipython_config.py /etc/ipython/
11 changes: 11 additions & 0 deletions base-python/course-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use the base image provided by MDS
FROM ubcmds/base-python:6acbbd2

# Define additional packages that are specific to this course
ENV PYTHON_PACKAGES="scipy"

# Install the pre-defined Python packages
RUN pip install --no-cache-dir $PYTHON_PACKAGES

EXPOSE 8080
# End course image
3 changes: 3 additions & 0 deletions base-python/ipython_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ipython_config.py
c = get_config()
c.Completer.use_jedi = False
8 changes: 0 additions & 8 deletions base-python/plugin.jupyterlab-settings

This file was deleted.

0 comments on commit 4ebd37b

Please sign in to comment.