# The PersistentVolumeClaim is used to pass on to the
# spotfire-pythonserivce Helm chart during installation.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: packages-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-client
  resources:
    requests:
      storage: 1Gi
---
# A configmap contains your requirements.txt file containing the list of your
# packages.
apiVersion: v1
kind: ConfigMap
metadata:
  name: requirements-txt
data:
  requirements.txt: |
    contourpy
    cycler
    fonttools
    kiwisolver
    matplotlib
    packaging
    pillow
    pyparsing
    scipy
    seaborn
---
# The Job starts a Python container and runs 'pip', which reads
# 'requirements.txt' and installs the packages onto the PersistentVolume pointed
# to by the PersistentVolumeClaim 'packages-pvc'.
apiVersion: batch/v1
kind: Job
metadata:
  name: populate-packages-job
spec:
  ttlSecondsAfterFinished: 600
  template:
    spec:
      containers:
        - name: populate-packages
          image: spotfire/spotfire-pythonservice:1.23.0
          command: ['sh', '-c', 'python -m pip install -t /packages -r /requirements.txt']
          imagePullPolicy: Always
          volumeMounts:
          - name: packages-volume
            mountPath: /packages
          - name: requirements-txt
            mountPath: /requirements.txt
            subPath: requirements.txt
      volumes:
        - name: packages-volume
          persistentVolumeClaim:
            claimName: packages-pvc
        - name: requirements-txt
          configMap:
            name: requirements-txt
      restartPolicy: Never
