apiVersion: v1
kind: ConfigMap
metadata:
  name: "@(Model.Name)"
  namespace: "@(Model.NameSpace)"
data:
  prepare: |
    bash /kqi/scripts/common/show-logo
    bash /kqi/scripts/common/prepare-kqi-conf

    if [ -n "$MODEL_REPOSITORY" ] || [ -n "$MODEL_REPOSITORY_URL" ] || [ -n "$COMMIT_ID" ]; then
        bash /kqi/scripts/common/prepare-git
    fi
    
    if [ -n "$DATASET_ID" ]; then
        echo "------------------------- [KAMONOHASHI Prepare] deploy dataset $DATASET_ID into /kqi/input . -------------------------"
        kqi dataset download-files -d /kqi/input $DATASET_ID && kqi dataset get -d /kqi/input/meta.json $DATASET_ID
        if [ $? -ne 0 ]; then
            echo "dataset download-files failed"
        fi
    fi
  main: |
    if which pip3 > /dev/null 2>&1; then
      pip3 install jupyterlab==1.0.4
    else
      pip install jupyterlab==1.0.4
    fi
    jupyter lab --ip=0.0.0.0 --allow-root --notebook-dir=/kqi/ --no-browser > /kqi/attach/.notebook.log 2>&1 &
    bash /kqi/scripts/common/wait-ready
  finish: |
    bash /kqi/scripts/common/prepare-kqi-conf
    sleep $EXPIRES_IN
    echo "------------------------- [KAMONOHASHI Finish] -------------------------"
    kqi notebook halt $NOTEBOOK_ID