Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
# Running Jupyter notebook using Tekton
kind: Task
name: run-notebook
annotations: "false"
- name: notebook-path
type: string
description: Path to the notebook to run. This should be the relative path relative
to the root of the repository where the notebook lives.
- name: output
type: string
description: This should be the GCS path that the rendered notebook will be written
to. This should be a GCS path that is accessible from the KF cluster where the
notebook runs. This should be a directory.
- name: image
type: string
default: tensorflow/tensorflow:2.1.2-jupyter
description: The docker image to run the notebook in
- name: requirements
type: string
description: If supplied path to a requirements file to install
default: ""
# Repo containing the notebook code
- name: notebook-repo
type: git
- name: run
image: $(inputs.params.image)
# We use a script because if notebook execution fails we don't want to
# exit with nonzero exit code as that will prevent the subsequent steps
# from running which will prevent notebook output upload
script: "#!/usr/bin/env bash\nset -x\nmkdir -p /workspace/outputs\n\nfilename=$(basename
$(inputs.params.notebook-path))\n\n# pin jupyter-client to deal with\npip
install --upgrade --user papermill jupyter-client==6.1.2\n\n# If there is a
requirements.txt install it.\n# Even if the notebook will do this its good to
do it before invoking the notebook-path\n# as this ensure any changes to the
python path are properly applied\n\nrequirements_rpath=$(inputs.params.requirements)
\ \nif [ -n \"${requirements_rpath}\" ]; then\n requirements=/workspace/$(${requirements_rpath}\n
\ pip install --user -r ${requirements} \nfi\n\nrpath=$(dirname $(inputs.params.notebook-path))\nwork_dir=/workspace/$(${rpath}\ncd
${work_dir}\n\npython -m papermill.cli \\\n /workspace/$($(inputs.params.notebook-path)
\\\n /workspace/outputs/${filename} \\\n --request-save-on-cell-execute \n\necho
Done running notebook \n"
- name: convert
image: $(inputs.params.image)
script: |
#!/usr/bin/env bash
set -x
filename=$(basename $(inputs.params.notebook-path))
jupyter nbconvert --to html /workspace/outputs/${filename}
- name: upload
script: |
#!/usr/bin/env bash
set -x
now=$(date +%Y%m%d-%H%M%S)
gsutil cp -r /workspace/outputs/ $(inputs.params.output)/${now}