apiVersion: apps/v1
kind: Deployment
metadata:
  name:  todo-app
  namespace: todo-app
  labels:
    app:  todo-app
  annotations:
    configmap.reloader.stakater.com/reload: todo-app
spec:
  selector:
    matchLabels:
      app: todo-app
  replicas: 1
  template:
    metadata:
      labels:
        app:  todo-app
    spec:
      imagePullSecrets:
        - name: docker-credentials
      initContainers:
        - name: migrations
          image: ghcr.io/rendyananta/sample-todo-app/fpm
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 200m
              memory: 100Mi
          envFrom:
            - configMapRef:
                name: todo-app
            - secretRef:
                name: todo-app
          command:
            - "php"
          args:
            - "artisan"
            - "migrate"
            - "--force"
      volumes:
        - name: cache
          emptyDir: {}
        - name: testing
          emptyDir: {}
        - name: views
          emptyDir: {}
      securityContext:
        fsGroup: 1000
      containers:
      - name: fpm
        image: ghcr.io/rendyananta/sample-todo-app/fpm
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 500m
            memory: 300Mi
        ports:
        - containerPort: 9000
          name: fpm
        volumeMounts:
          - name: cache
            mountPath: /var/www/html/storage/framework/cache
          - name: views
            mountPath: /var/www/html/storage/framework/views
          - name: testing
            mountPath: /var/www/html/storage/framework/testing 
        envFrom:
          - configMapRef:
              name: todo-app
          - secretRef:
              name: todo-app
      - name: nginx
        image: ghcr.io/rendyananta/sample-todo-app/nginx
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 500m
            memory: 100Mi
        ports:
        - containerPort:  8000
          name: nginx