apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: apigee-portal-drupal-cronjob
  namespace: apigee-devportal
spec:
  schedule: "*/15 * * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          volumes:
            - name: nfs-drupal-files-vol
              persistentVolumeClaim:
                claimName: apigee-devportal-drupal-files
          containers:
            - name: apigee-devportal-cronjob
              image: gcr.io/gkoli-workspace/apigee-devportal:latest
              args:
                - /bin/sh
                - -c
                - chmod -R 777 /app/drupal-files /app/code/web/sites/default/files && drush cron
#              ports:
#                - name: drupal-app-port
#                  containerPort: 8080
#              livenessProbe:
#                httpGet:
#                  path: /liveness_check
#                  port: drupal-app-port
#                initialDelaySeconds: 120
#                failureThreshold: 5
#                periodSeconds: 30
#                timeoutSeconds: 5
#              readinessProbe:
#                httpGet:
#                  path: /readiness_check
#                  port: drupal-app-port
#                initialDelaySeconds: 120
#                failureThreshold: 5
#                periodSeconds: 30
#                timeoutSeconds: 5
              env:
                - name: SKIP_LOCKDOWN_DOCUMENT_ROOT
                  value: "true"
                - name: DRUPAL_DATABASE_HOST
                  valueFrom:
                    configMapKeyRef:
                      name: apigee-devportal-configuration
                      key: database-host
                - name: DRUPAL_DATABASE_PORT
                  valueFrom:
                    configMapKeyRef:
                      name: apigee-devportal-configuration
                      key: database-port
                - name: DRUPAL_DATABASE_USER
                  valueFrom:
                    secretKeyRef:
                      name: apigee-devportal-credentials
                      key: dbusername
                - name: DRUPAL_DATABASE_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: apigee-devportal-credentials
                      key: dbpassword
                - name: DRUPAL_DATABASE_NAME
                  valueFrom:
                    configMapKeyRef:
                      name: apigee-devportal-configuration
                      key: database-name
                - name: DRUPAL_DATABASE_DRIVER
                  valueFrom:
                    configMapKeyRef:
                      name: apigee-devportal-configuration
                      key: database-driver
                - name: DRUPAL_FILE_PUBLIC_PATH
                  value: sites/default/files
                - name: DRUPAL_FILE_PRIVATE_PATH
                  value: /app/drupal-files/private
                - name: DRUPAL_FILE_TEMP_PATH
                  value: /app/drupal-files/temp
                - name: DRUPAL_CONFIG_SYNC_DIR
                  value: /app/drupal-files/config
              volumeMounts:
                - mountPath: /app/code/web/sites/default/files
                  name: nfs-drupal-files-vol
                  subPath: public
                - mountPath: /app/drupal-files/private
                  name: nfs-drupal-files-vol
                  subPath: private
                - mountPath: /app/drupal-files/temp
                  name: nfs-drupal-files-vol
                  subPath: temp
                - mountPath: /app/drupal-files/config
                  name: nfs-drupal-files-vol
                  subPath: config
