apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-webserver
  labels:
    project: sob
    app: api-webserver
    layer: api
spec:
  revisionHistoryLimit: 2
  replicas: 1
  selector:
    matchLabels:
      app: api-webserver
  template:
    metadata:
      labels:
        project: sob
        app: api-webserver
        layer: api
    spec:
      containers:
        - name: api-php
          image: eu.gcr.io/aperturedevs/sob-api-php:stable
          imagePullPolicy: Always
          env:
            - name: APP_SECRET
              valueFrom:
                secretKeyRef:
                  name: sob-secret
                  key: api-secret
            - name: EVENT_STORE_URL
              valueFrom:
                secretKeyRef:
                  name: sob-secret
                  key: api-event-store-url
            - name: RELATIONAL_DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: sob-secret
                  key: api-relational-database-url
            - name: MESSENGER_TRANSPORT_DSN
              valueFrom:
                secretKeyRef:
                  name: sob-secret
                  key: api-messenger-transport-dsn
            - name: MAILER_DSN
              valueFrom:
                secretKeyRef:
                  name: sob-secret
                  key: mailer-dsn
            - name: APP_ENV
              valueFrom:
                configMapKeyRef:
                  name: api-configmap
                  key: environment
            - name: CORS_ALLOW_ORIGIN
              valueFrom:
                configMapKeyRef:
                  name: api-configmap
                  key: cors
            - name: FRONTEND_URL
              valueFrom:
                configMapKeyRef:
                  name: api-configmap
                  key: frontend_url
          volumeMounts:
            - name: shared-files
              mountPath: /var/www/html
            - name: php-config-volume
              mountPath: /usr/local/etc/php/php.ini
              subPath: php.ini
          lifecycle:
            postStart:
              exec:
                command: ["/pod-start.sh"]
          resources:
            limits:
              cpu: "100m"
              memory: "256Mi"
            requests:
              cpu: "1m"
              memory: "128Mi"
        - name: api-nginx
          image: nginx:1
          ports:
            - containerPort: 80
          imagePullPolicy: Always
          volumeMounts:
            - name: shared-files
              mountPath: /var/www/html
            - name: nginx-config-volume
              mountPath: /etc/nginx/conf.d/default.conf
              subPath: nginx.conf
          resources:
            limits:
              cpu: "100m"
              memory: "128Mi"
            requests:
              cpu: "1m"
              memory: "128Mi"
      volumes:
        - name: shared-files
          emptyDir: {}
        - name: nginx-config-volume
          configMap:
            name: api-configmap
        - name: php-config-volume
          configMap:
            name: api-configmap
