apiVersion: apps/v1
kind: Deployment
metadata:
  name: farmdb-django-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: farmdb-django-deployment
  template:
    metadata:
      labels:
        app: farmdb-django-deployment
    spec:
      containers:
      - name: farmdb-django
        image: climatefarmers/farmdb-django:sha-7ba133f
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /health/
            port: 8000
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 10
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /health/
            port: 8000
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 10
        command: ['sh']
        args: ['entrypoint.sh']
        imagePullPolicy: Always
        env:
        - name: PGUSER
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: username
        - name: PGPASS
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: password
        - name: PGNAME
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: database
        - name: PGHOST
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: private_ip
        - name: PGPORT
          value: "5432"
        - name: DJANGO_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: django-secret
              key: django_secret_key
        - name: GOOGLE_API_KEY
          valueFrom:
            secretKeyRef:
              name: django-secret
              key: google_api_key
        - name: TYPEFORM_SECRET
          valueFrom:
            secretKeyRef:
              name: django-secret
              key: typeform_secret
        - name: ADDRESS_SVC_ENDPOINT
          value: http://localhost:8080/parse/
        - name: MONITORING_SVC_URL
          value: http://soil-monitoring-service.farmdb.svc.cluster.local
        - name: STATIC_BUCKET
          value: cfcommon-static-dev
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: "/etc/static/credentials.json"
        volumeMounts:
        - name: static-secret
          mountPath: "/etc/static"
      
        ports:
        - name: http
          containerPort: 8000
          protocol: TCP

      - name: address-parser
        image: climatefarmers/address-parser
        imagePullPolicy: Always
      
      volumes:
      - name: static-secret
        secret:
          secretName: static-gsa-credentials