---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hydra-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hydra-deployment
  template:
    metadata:
      labels:
        app: hydra-deployment
    spec:

      initContainers:
        - name: hydra-migrate-container
          image: oryd/hydra:v1.7.0
          args: ['migrate', 'sql', '--yes', '--read-from-env']
          env:
            - name: 'DSN'
              valueFrom:
                secretKeyRef:
                  name: hydra-db-secret
                  key: DATABASE_URI

      containers:
        - name: hydra-container
          image: oryd/hydra:v1.7.0
          args: ['serve', 'all', '--dangerous-force-http']
          ports:
            - containerPort: 4444
            - containerPort: 4445
          envFrom:
            - configMapRef:
                name: hydra-config
          env:
            - name: 'SECRETS_SYSTEM'
              valueFrom:
                secretKeyRef:
                  name: hydra-system-secret
                  key: SECRET
            - name: 'DSN'
              valueFrom:
                secretKeyRef:
                  name: hydra-db-secret
                  key: DATABASE_URI
          resources:
            requests:
              memory: "100Mi"
              cpu: "1000m"
            limits:
              memory: "500Mi"
              cpu: "2000m"
