apiVersion: apps/v1
kind: Deployment
metadata:
  name: apigee-devportal-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      role: apigee-devportal-drupal-web-server
  template:
    metadata:
      labels:
        role: apigee-devportal-drupal-web-server
    spec:
      volumes:
        - name: nfs-drupal-files-vol
          persistentVolumeClaim:
            claimName: apigee-devportal-drupal-files
      containers:
        - name: apigee-devportal
          image: gcr.io/gkoli-workspace/apigee-devportal:latest
#          lifecycle:
#            postStart:
#              exec:
#                command: ["/bin/sh", "-c", "chown -R www-data:www-data /app && chmod -R 775 /app/drupal-files"]
          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: 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