Skip to content

Commit

Permalink
Containerized Extension (#47)
Browse files Browse the repository at this point in the history
* added Dockerfile

* action test

* took out debug steps

* added to README

* dynamic branch test in docker build

* updated README to include links to previous version

* added version tag to  command

* added base image, removed call to git

* attempted fix

* fixed README instructions

* attempt at using specified python version in scipy-notebook

* verified version of node

* attempted fix

* test
  • Loading branch information
mrzengel authored Jul 26, 2024
1 parent dc74cca commit a06c775
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: main
pull_request:
branches: main

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
flavor: |
latest=true
tags: |
type=sha
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM quay.io/jupyter/scipy-notebook:python-3.11.9
LABEL maintainer="mrzengel"

SHELL ["/bin/bash", "-c"]

COPY . /zenodo_jupyterlab_extension

# Change ownership to the default user 'jovyan'
USER root
RUN chown -R jovyan:users /zenodo_jupyterlab_extension

# Set the working directory and switch back to non-root user
USER jovyan
WORKDIR /zenodo_jupyterlab_extension

#install correct version of Node
RUN conda upgrade -c conda-forge nodejs

# Install Python requirements
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install -r requirements.txt

# Install Yarn dependencies and build
RUN jlpm && jlpm run build

# Install and enable extension
RUN python3 -m pip install .
RUN jupyter server extension enable zenodo_jupyterlab.server

# Expose port and run JupyterLab
EXPOSE 8888
CMD ["jupyter", "lab", "--ip=*", "--NotebookApp.token=''", "--NotebookApp.password=''", "--no-browser", "--allow-root"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ Install and Build the Extension:\
Enable the Extension:\
`jupyter server extension enable zenodo_jupyterlab.server`

Now open a local instance of Jupyter Lab, and it should be present on the sidebar.
Now open a local instance of Jupyter Lab, and it should be present on the sidebar.

# Docker
Rather than manually cloning the repository, it is possible to run the extension in a Docker container. To do this, use the following command:\
`docker run -d -p 8888:8888 ghcr.io/vre-hub/zenodo-jupyterlab-extension:<version>`

All available versions can be found [here](https://github.com/vre-hub/zenodo-jupyterlab-extension/pkgs/container/zenodo-jupyterlab-extension)

Now the instance of Jupyter Lab with the extension installed and enabled should be avilable on localhost:8888

0 comments on commit a06c775

Please sign in to comment.