apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal
  labels:
    app: drupal
spec:
  selector:
    matchLabels:
      app: drupal
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: drupal
    spec:
      initContainers:
        - name: init-volumes
          image: drupal
          command: ["/bin/bash", "-c"]
          args:
            [
              "mkdir -p /web/{modules/patches,profiles,themes,sites/default}; chown -R www-data:www-data /web/{sites,modules,profiles,themes}; touch /web/modules/composer.json; echo done.",
            ]
          volumeMounts:
            - mountPath: /web
              name: drupal
      containers:
        - name: drupal
          image: drupal
          ports:
            - containerPort: 80
              name: http
              protocol: TCP
          env:
            - name: BASE_URL
              value: https://fornix.hel1.oceanbox.io
            - name: DRUPAL_DATABASE_HOST
              value: drupal-db-rw
            - name: DRUPAL_DATABASE_PREFIX
              value: ""
            - name: DRUPAL_DATABASE_NAME
              value: app
            - name: DRUPAL_DATABASE_USERNAME
              valueFrom:
                secretKeyRef:
                  name: drupal-db-app
                  key: username
            - name: DRUPAL_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: drupal-db-app
                  key: password
          volumeMounts:
            - mountPath: /opt/drupal/web/modules
              name: drupal
              subPath: modules
            - mountPath: /opt/drupal/web/profiles
              name: drupal
              subPath: profiles
            - mountPath: /opt/drupal/web/themes
              name: drupal
              subPath: themes
            - mountPath: /opt/drupal/web/sites
              name: drupal
              subPath: sites
            - mountPath: /opt/drupal/patches
              name: drupal
              subPath: modules/patches
            - mountPath: /opt/drupal/composer.json
              name: drupal
              subPath: modules/composer.json
            - mountPath: /opt/drupal/composer.lock
              name: drupal
              subPath: modules/composer.lock
      volumes:
        - name: drupal
          persistentVolumeClaim:
            claimName: drupal
