This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathrun-notebook-task.yaml
62 lines (62 loc) · 2.8 KB
/
run-notebook-task.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Running Jupyter notebook using Tekton
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: run-notebook
annotations:
sidecar.istio.io/inject: "false"
spec:
params:
- 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: ""
resources:
inputs:
# Repo containing the notebook code
- name: notebook-repo
type: git
steps:
- 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 https://github.com/nteract/papermill/issues/486\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/$(inputs.resources.notebook-repo.name)/${requirements_rpath}\n
\ pip install --user -r ${requirements} \nfi\n\nrpath=$(dirname $(inputs.params.notebook-path))\nwork_dir=/workspace/$(inputs.resources.notebook-repo.name)/${rpath}\ncd
${work_dir}\n\npython -m papermill.cli \\\n /workspace/$(inputs.resources.notebook-repo.name)/$(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
image: gcr.io/google.com/cloudsdktool/cloud-sdk
script: |
#!/usr/bin/env bash
set -x
now=$(date +%Y%m%d-%H%M%S)
gsutil cp -r /workspace/outputs/ $(inputs.params.output)/${now}