Skip to content

added Jupyter and Rshiny Quickstarters #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/modules/quickstarters/pages/ds-jupyter-lab.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
= Data Science Jupyter Lab

== Purpose of this quickstarter

Provision a shared Jupyter Lab within OpenShift for rapid prototyping of data science applications using OpenShift OAuth.

== What files / architecture is generated?

----
.
├── Jenkinsfile
├── .pre-commit-config.yaml
├── docker
│ ├── Dockerfile
│ ├── jupyter_lab_config.json
│ ├── requirements.txt
│ └── run.sh
├── metadata.yml - Component metadata
└── release-manager.yml - Configuration file for the Release Manager
----

== Frameworks used

* https://docs.python.org/3.11[Python 3.11]
* https://jupyterlab.readthedocs.io/en/stable/[JupyterLab]

== Usage - how do you start after you provisioned this quickstarter

The quickstarter sets up two pods in OpenShift. The `ds-jupyter-lab` instance is routed through the https://github.com/openshift/oauth-proxy/[OpenShift OAuth proxy] instance.

The directory `/opt/app-root/src/work` is created where code can be organized using installed git. +
Please consider mounting a persistent volume claim for this path. +
New python requirements are specified using the `requirements.txt`. +

=== Setting up independent environments/kernels ===

One can setup specific and independent IPython kernels based on specific Python virtual environments:

* Open a new terminal session in your Jupyter Lab, then:

----
cd <PATH_WHERE_TO_LOCATE_NEW_VENV_OR_NONE>
python -m venv <YOUR NEW VENV NAME>
. <YOUR NEW VENV NAME>/bin/activate
pip install ipykernel pip --upgrade
python -m ipykernel install --user --name=<YOUR NEW VENV NAME>
jupyter kernelspec list # this is for validating installation
----

Now on a notebook you can select that new kernel by clicking on the name you see on the top right where you see the dot status.

=== Metadata

The following are typical xref:quickstarters:metadata.adoc[metadata] values that can be used for components based on this quickstarter:
Note that the xref:jenkins-shared-library:labelling.adoc[OpenShift resources will be labeled] based on this metadata.

```yaml
name: jupyterlab
description: "JupyterLab is a web-based interactive development environment for Jupyter notebooks, code, and data."
supplier: https://jupyter.org/
version: 3.0.14
type: ods-service
```

== How this quickstarter is built through jenkins

The build pipeline is defined in the `Jenkinsfile` in the project root. The main stages of the pipeline are:

. Start OpenShift build
. Deploy image to OpenShift

include::partial$secret-scanning-with-gitleaks.adoc

== Builder agent used

https://github.com/opendevstack/ods-core/tree/master/jenkins/agent-base[jenkins-agent-base]

== Known limitations

Consider if sufficient computing resources can be provided by the OpenShift cluster. +
You might require installing NodeJS if requiring specific JupyterLab extensions (nodejs >=12.0.0).
59 changes: 59 additions & 0 deletions docs/modules/quickstarters/pages/ds-rshiny.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
= Data Science R Shiny Application

== Purpose of this quickstarter

Provisions a R Shiny application within OpenShift using OpenShift OAuth.

== What files / architecture is generated?

----
.
├── Jenkinsfile - This file contains Jenkins build configuration settings
├── .pre-commit-config.yaml
├── docker - This folder contains Docker configuration settings and main R Shiny app
│ ├── Dockerfile
│ └── app.R
├── metadata.yml - Component metadata
└── release-manager.yml - Configuration file for the Release Manager
----

== Frameworks used

* https://www.tutorialspoint.com/r/index.htm[R]
* https://shiny.rstudio.com/tutorial[Shiny]

== Usage - how do you start after you provisioned this quickstarter

The quickstarter sets up two pods in OpenShift. The `ds-rshiny` application is routed through the https://github.com/openshift/oauth-proxy/[OpenShift OAuth proxy] instance.

=== Metadata

The following are typical xref:quickstarters:metadata.adoc[metadata] values that can be used for components based on this quickstarter:
Note that the xref:jenkins-shared-library:labelling.adoc[OpenShift resources will be labeled] based on this metadata.

```yaml
name: shiny
description: "Shiny is an R package that makes it easy to build interactive web apps straight from R."
supplier: https://www.rstudio.com/
version: 1.6.0
type: ods-service
runtime: r
runtimeVersion: 4.1.1
```

== How this quickstarter is built through jenkins

The build pipeline is defined in the `Jenkinsfile` in the project root. The main stages of the pipeline are:

. Start OpenShift build
. Deploy image to OpenShift

include::partial$secret-scanning-with-gitleaks.adoc

== Builder agent used

https://github.com/opendevstack/ods-core/tree/master/jenkins/agent-base[jenkins-agent-base]

== Known limitations

N/A
32 changes: 32 additions & 0 deletions ds-jupyter-lab/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def odsNamespace = ''
def odsGitRef = ''
def odsImageTag = ''
def sharedLibraryRef = ''
def agentImageTag = ''

node {
odsNamespace = env.ODS_NAMESPACE ?: 'ods'
odsGitRef = env.ODS_GIT_REF ?: 'master'
odsImageTag = env.ODS_IMAGE_TAG ?: 'latest'
sharedLibraryRef = env.SHARED_LIBRARY_REF ?: odsImageTag
agentImageTag = env.AGENT_IMAGE_TAG ?: odsImageTag
}

library("ods-jenkins-shared-library@${sharedLibraryRef}")

odsQuickstarterPipeline(
imageStreamTag: "${odsNamespace}/jenkins-agent-base:${agentImageTag}",
) { context ->

odsQuickstarterStageCopyFiles(context)

stage('Setup OpenShift resources') {
sh """sh common/scripts/create-component-with-oauth.sh \
--project ${context.projectId} \
--component ${context.componentId} \
--non-interactive"""
}

odsQuickstarterStageRenderJenkinsfile(context)

}
25 changes: 25 additions & 0 deletions ds-jupyter-lab/Jenkinsfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// See https://www.opendevstack.org/ods-documentation/ for usage and customization.

@Library('ods-jenkins-shared-library@@shared_library_ref@') _

odsComponentPipeline(
imageStreamTag: '@ods_namespace@/jenkins-agent-base:@agent_image_tag@',
branchToEnvironmentMapping: [
'master': 'dev',
// 'release/': 'test'
]
) { context ->

odsComponentStageBuildOpenShiftImage(
context, [
resourceName: "${context.componentId}",
dockerDir: "docker_jupyterlab",
buildArgs: [
nexusHostWithBasicAuth: context.nexusHostWithBasicAuth,
nexusHostWithoutScheme: context.nexusHostWithoutScheme
]])
odsComponentStageBuildOpenShiftImage(
context, [resourceName: "${context.componentId}-oauth", dockerDir: "docker_oauth"])

def deploymentInfo = odsComponentStageRolloutOpenShiftDeployment(context)
}
7 changes: 7 additions & 0 deletions ds-jupyter-lab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Jupyter Lab (ds-jupyter-lab)

Documentation is located in our [official documentation](https://www.opendevstack.org/ods-documentation/ods-quickstarters/latest/index.html)

Please update documentation in the [antora page directory](https://github.com/opendevstack/ods-quickstarters/tree/master/docs/modules/ROOT/pages)

Tested thru [automated tests](../tests/ds-jupyter-lab)
5 changes: 5 additions & 0 deletions ds-jupyter-lab/files/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
hooks:
- id: gitleaks
41 changes: 41 additions & 0 deletions ds-jupyter-lab/files/docker_jupyterlab/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM registry.access.redhat.com/ubi9/python-311

ARG nexusHostWithBasicAuth
ARG nexusHostWithoutScheme

WORKDIR /opt/app-root/src

ENV PYTHONPATH=$PYTHONPATH:/opt/app-root/src \
NPM_CONFIG_PREFIX=/opt/app-root \
NODE_OPTIONS=--max-old-space-size=4096

COPY requirements.txt /opt/app-root/src

USER 1001
# From load pip install for caching docker build layers
RUN if [ ! -z ${nexusHostWithBasicAuth} ]; \
then pip install -i ${nexusHostWithBasicAuth}/repository/pypi-all/simple --trusted-host ${nexusHostWithoutScheme} --upgrade pip && pip install -i ${nexusHostWithBasicAuth}/repository/pypi-all/simple --trusted-host ${nexusHostWithoutScheme} -r requirements.txt; \
else pip install --upgrade pip && pip install -r requirements.txt; \
fi && \
pip check

USER root

COPY run.sh /opt/app-root/run.sh
COPY jupyter_lab_config.json /opt/app-root/src/.jupyter/jupyter_lab_config.json

RUN chown -R 1001 /opt/app-root/src && \
chgrp -R 0 /opt/app-root/src && \
chmod -R g=u /opt/app-root/src && \
chmod +x /opt/app-root/run.sh && \
chmod g+w /etc/passwd && \
chmod -R g+w /opt/app-root/share && \
chmod -R g+w /opt/app-root/src

USER 1001

EXPOSE 8080

ENTRYPOINT [ "/opt/app-root/run.sh" ]

CMD [ "jupyter", "lab" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ServerApp": {
"token": "",
"ip": "0.0.0.0",
"root_dir": "/opt/app-root/src/work",
"port": 8080,
"open_browser": false
}
}
3 changes: 3 additions & 0 deletions ds-jupyter-lab/files/docker_jupyterlab/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jupyter==1.0.0
ipywidgets==8.0.6
jupyterlab==4.0.11
23 changes: 23 additions & 0 deletions ds-jupyter-lab/files/docker_jupyterlab/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
fi
fi

# create work directory
mkdir -p /opt/app-root/src/work

# set the home directories to a folder with read/write access
export XDG_DATA_HOME=/opt/app-root/src
export HOME=/opt/app-root/src

# link jupyter configs
export JUPYTER_CONFIG_DIR=/opt/app-root/src/.jupyter
export JUPYTER_PATH=/opt/app-root/src/work/.jupyter
export JUPYTER_RUNTIME_DIR=/opt/app-root/src/work/.jupyter/runtime

exec $@
1 change: 1 addition & 0 deletions ds-jupyter-lab/files/docker_oauth/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM registry.redhat.io/openshift4/ose-oauth-proxy:latest
6 changes: 6 additions & 0 deletions ds-jupyter-lab/files/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: Jupyter Lab
description: "The Jupyter Lab is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more. Technologies: JupyterLab 3, Python 3.9"
supplier: https://jupyter.org
version: 4.x
type: ods-service
2 changes: 2 additions & 0 deletions ds-jupyter-lab/files/release-manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
dependencies: []
18 changes: 18 additions & 0 deletions ds-jupyter-lab/testdata/golden/jenkins-build-stages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"stage": "odsPipeline start",
"status": "SUCCESS"
},
{
"stage": "Build OpenShift Image",
"status": "SUCCESS"
},
{
"stage": "Deploy to OpenShift",
"status": "SUCCESS"
},
{
"stage": "odsPipeline finished",
"status": "SUCCESS"
}
]
26 changes: 26 additions & 0 deletions ds-jupyter-lab/testdata/golden/jenkins-provision-stages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"stage": "Checkout quickstarter",
"status": "SUCCESS"
},
{
"stage": "Initialize output directory",
"status": "SUCCESS"
},
{
"stage": "Copy files from quickstarter",
"status": "SUCCESS"
},
{
"stage": "Setup OpenShift resources",
"status": "SUCCESS"
},
{
"stage": "Create Jenkinsfile",
"status": "SUCCESS"
},
{
"stage": "Push to remote",
"status": "SUCCESS"
}
]
22 changes: 22 additions & 0 deletions ds-jupyter-lab/testdata/steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
componentID: jupyter
steps:
- type: provision
provisionParams:
verify:
jenkinsStages: golden/jenkins-provision-stages.json
- type: build
buildParams:
verify:
jenkinsStages: golden/jenkins-build-stages.json
openShiftResources:
imageTags:
- name: "{{.ComponentID}}"
tag: latest
imageStreams:
- "{{.ComponentID}}"
deploymentConfigs:
- "{{.ComponentID}}"
- "{{.ComponentID}}-auth-proxy"
services:
- "{{.ComponentID}}"
- "{{.ComponentID}}-auth-proxy"
Loading