---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: strapi-blog
  namespace: ucandoit
  labels:
    app: strapi-blog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: strapi-blog
  template:
    metadata:
      labels:
        app: strapi-blog
    spec:
      imagePullSecrets:
        - name: docker-registry
      volumes:
        - name: uploads
          persistentVolumeClaim:
            claimName: uploads-volume-claim
      containers:
      - name: strapi-blog
        image: registry.ucandoit.io/strapi-blog:0.0.2
        imagePullPolicy: Always
        ports:
        - name: http-entry
          protocol: TCP
          containerPort: 1337
        env:
          - name: NODE_ENV
            value: production
          - name: DATABASE_HOST
            valueFrom:
                configMapKeyRef:
                  name: dbconfig
                  key: PG_HOST
          - name: DATABASE_PORT
            value: '5432'
          - name: DATABASE_NAME
            valueFrom:
                configMapKeyRef:
                  name: dbconfig
                  key: PG_DBNAME
          - name: DATABASE_USERNAME
            valueFrom:
                configMapKeyRef:
                  name: dbconfig
                  key: PG_USER
          - name: DATABASE_PASSWORD
            valueFrom:
                secretKeyRef:
                  name: dbconfig-secret
                  key: PG_PASSWORD
        livenessProbe:
          httpGet:
            path: /_health
            port: 1337
          initialDelaySeconds: 3
          timeoutSeconds: 3
        readinessProbe:
          httpGet:
            path: /_health
            port: 1337
          initialDelaySeconds: 3
          timeoutSeconds: 3
        volumeMounts:
          - name: uploads
            mountPath: '/app/public/uploads'
      initContainers:
      - name: wait-for-postgres
        image: registry.ucandoit.io/busybox:1
        command:
        - /bin/sh
        - -c
        - until nc -zv $PG_HOST $PG_PORT -w1; do echo 'waiting for db';
          sleep 1; done
        env:
        - name: PG_HOST
          valueFrom:
            configMapKeyRef:
              name: dbconfig
              key: PG_HOST
        - name: PG_PORT
          value: '5432'
        
