# drupal-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal-deployment
  namespace: ${KUBERNETES_NAMESPACE}
  labels:
    app: drupal
    component: web
    environment: ${ENVIRONMENT_NAME}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drupal
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: drupal
        component: web
        environment: ${ENVIRONMENT_NAME}
    spec:
      hostAliases:
        - ip: ${SERVER_IP}
          hostnames:
          - "${HOSTNAME}"
      imagePullSecrets:
      - name: github-docker-secret
      containers:
      - name: drupal
        image: ${DOCKER_IMAGE}
        imagePullPolicy: Always
        ports:
        - name: http
          containerPort: 8080 
          protocol: TCP
        envFrom:
        - configMapRef:
            name: drupal-config
        env:
        - name: TZ
          value: "America/Montevideo"
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: drupal-secret
              key: db-password
        - name: DRUPAL_HASH_SALT
          valueFrom:
            secretKeyRef:
              name: drupal-secret
              key: drupal-hash-salt
        - name: DRUPAL_CONFIG_HASH
          valueFrom:
            secretKeyRef:
              name: drupal-secret
              key: drupal-config-hash
        volumeMounts:
        - name: drupal-files
          mountPath: /var/www/html/web/sites/default/files
        - name: drupal-private
          mountPath: /var/www/html/private
        - name: drupal-tmp
          mountPath: /var/www/html/tmp
        livenessProbe:
          httpGet:
            path: /robots.txt
            port: 8080
          initialDelaySeconds: 120
          periodSeconds: 30
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /robots.txt
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: false
          capabilities:
            drop:
            - ALL
      volumes:
      - name: drupal-files
        hostPath:
          path: /opt/drupal/files
      - name: drupal-private
        hostPath:
          path: /opt/drupal/private
      - name: drupal-tmp
        emptyDir: {}