apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-go{{ENV}}-deployment
  labels:
    app: auth-go
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth-go
  template:
    metadata:
      labels:
        app: auth-go
    spec:
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
      containers:
        - name: auth-go{{ENV}}
          image: gcr.io/obedt-dev/auth-go:{{IMAGE_TAG}}
          envFrom:
            - configMapRef:
                name: auth-go{{ENV}}-env
            - secretRef:
                name: auth-go{{ENV}}-env
          readinessProbe:
            httpGet:
              path: "/health"
              port: 3000
            initialDelaySeconds: 2
            timeoutSeconds: 5
            periodSeconds: 6
            successThreshold: 2
            failureThreshold: 3
          resources:
            requests:
              cpu: 150m
              memory: 200Mi
            limits:
              cpu: 200m
              memory: 220Mi
          ports:
            - containerPort: 3000
        - name: cloudsql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:1.11
          command: ["/cloud_sql_proxy",
          "-instances=obedt-dev:asia-southeast1:auth-go=tcp:3306",
          "-credential_file=/secrets/cloudsql/credentials.json"]
          securityContext:
            runAsUser: 2  # non-root user
            allowPrivilegeEscalation: false
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
