---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: dataverse
  labels:
    app.kubernetes.io/name: dataverse
    app.kubernetes.io/version: "4.20"
    app.kubernetes.io/component: appserver
    app.kubernetes.io/part-of: dataverse
    app.kubernetes.io/managed-by: kubectl
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: dataverse
      app.kubernetes.io/part-of: dataverse
      app.kubernetes.io/component: appserver
  revisionHistoryLimit: 1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: dataverse
        app.kubernetes.io/part-of: dataverse
        app.kubernetes.io/component: appserver
    spec:
      securityContext:
        runAsUser: 1000
        runAsGroup: 1000
      containers:
        - name: dataverse
          image: iqss/dataverse-k8s
          resources:
            requests:
              memory: "2Gi"
            limits:
              memory: "4Gi"
          ports:
            - containerPort: 8080
          envFrom:
            - configMapRef:
                name: dataverse
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: dataverse-postgresql
                  key: username
                  optional: true
            - name: POSTGRES_DATABASE
              valueFrom:
                secretKeyRef:
                  name: dataverse-postgresql
                  key: database
                  optional: true
          volumeMounts:
            - name: home
              mountPath: /data
              subPath: 234/dataverse-data
            - name: home
              mountPath: /docroot
              subPath: 234/dataverse-docroot
            - name: heapdumps
              mountPath: /dumps
            - name: db-secret
              mountPath: "/secrets/db"
              readOnly: true
            - name: doi-secret
              mountPath: "/secrets/doi"
              readOnly: true
            # This is here because of IQSS/dataverse-kubernetes#177. TBR for #178
            - name: primefaces-upload
              mountPath: /opt/dataverse/appserver/glassfish/domains/domain1/generated/jsp/dataverse
          readinessProbe:
            httpGet:
              path: /robots.txt
              port: 8080
      initContainers:
        - name: volume-mount-hack
          image: giantswarm/tiny-tools
          command: ["echo", "sh", "-c", "chown -c 1000:1000 /data /docroot /uploads"]
          volumeMounts:
            - name: home
              mountPath: /data
              subPath: 234/dataverse-data
            - name: home
              mountPath: /docroot
              subPath: 234/dataverse-docroot
            # This is here because of IQSS/dataverse-kubernetes#177. TBR for #178
            - name: primefaces-upload
              mountPath: /uploads
        - name: check-db-ready
          image: postgres:9.6
          command: ['sh', '-c',
            'until pg_isready -h "${POSTGRESQL_SERVICE_HOST}" -p "${POSTGRESQL_SERVICE_PORT}" -U "${POSTGRES_USER}";
            do echo waiting for database; sleep 3; done;']
          env:
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                key: username
                name: dataverse-postgresql
                optional: true
        - name: check-solr-ready
          image: giantswarm/tiny-tools
          command: ['sh', '-c',
            'until curl -sS -f "http://${SOLR_SERVICE_HOST}:${SOLR_SERVICE_PORT}/solr/collection1/admin/ping" 2>&1 | grep "status.:.OK";
            do echo waiting for solr; sleep 3; done;']
      volumes:
        - name: home
          persistentVolumeClaim:
            claimName: home
        - name: db-secret
          secret:
            secretName: dataverse-postgresql
        - name: doi-secret
          secret:
            secretName: dataverse-doi
        - name: heapdumps
          emptyDir: {}
        # This is here because of IQSS/dataverse-kubernetes#177. TBR for #178
        - name: primefaces-upload
          emptyDir: {}
