apiVersion: apps/v1
kind: Deployment
metadata:
  name: golinks
spec:
  replicas: 1
  selector:
    matchLabels:
      app: golinks
      version: v1
  template:
    metadata:
      labels:
        app: golinks
        version: v1
    spec:
      volumes:
      - name: cloudsql-service-account
        secret:
          secretName: cloudsql-service-account
      containers:
      - name: cloud-sql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        command:
          - "/cloud_sql_proxy"
          - "-instances=${GOOGLE_CLOUD_PROJECT}:${GOOGLE_CLOUD_REGION}:${CLOUDSQL_INSTANCE_NAME}=tcp:0.0.0.0:5432"
          - "-credential_file=/secrets/service-account.json"
        securityContext:
          runAsNonRoot: true
        volumeMounts:
        - name: cloudsql-service-account
          mountPath: /secrets/
          readOnly: true
      - image: armand1m/golinks:latest
        imagePullPolicy: IfNotPresent
        name: golinks 
        ports:
        - containerPort: 3000
        env:
        - name: PROTO
          value: ${PROTO}
        - name: HOSTNAME
          value: ${HOSTNAME}
        - name: LOGONAME
          value: ${LOGONAME}
        - name: AUTH0_ENABLED
          value: ${AUTH0_ENABLED}
        - name: AUTH0_DOMAIN
          value: ${AUTH0_DOMAIN}
        - name: AUTH0_AUDIENCE
          value: ${AUTH0_AUDIENCE}
        - name: AUTH0_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: auth0-properties
              key: client_id
        - name: AUTH0_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: auth0-properties
              key: client_secret
        - name: AUTH0_COOKIE_SECRET
          valueFrom:
            secretKeyRef:
              name: auth0-properties
              key: cookie_secret
        - name: AUTH0_COOKIE_DOMAIN
          value: ${AUTH0_COOKIE_DOMAIN}
        - name: AUTH0_REDIRECT_URL
          value: ${AUTH0_REDIRECT_URL}
        - name: AUTH0_POST_LOGOUT_REDIRECT_URL
          value: ${AUTH0_POST_LOGOUT_REDIRECT_URL}
        - name: NODE_ENV
          value: production
        - name: DATABASE_SCHEMA
          value: public
        - name: DATABASE_CONNECTION_STRING
          valueFrom:
            secretKeyRef:
              name: golinks-database
              key: connectionstring
        resources:
          requests:
            cpu: 15m
            memory: 100Mi