apiVersion: v1
kind: Service
metadata:
  name: <<appenv>>gallery-be
  namespace: <<appenv>>gallery-be
  labels:
    app: <<appenv>>gallery-be
    service: <<appenv>>gallery-be
spec:
  ports:
    - port: 80
      name: http-<<appenv>>gallery-be
      targetPort: 4300
  selector:
    app: <<appenv>>gallery-be
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: <<appenv>>gallery-be-sync-role-bd
  namespace: <<appenv>>gallery-be
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: <<appenv>>gallery-be-sync-role
subjects:
  - kind: ServiceAccount
    name: default
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ovh-vars
  namespace: <<appenv>>gallery-be
data:
  OVH_OBJECT_STORAGE: '<<appenv>>OvhObjectStorageS3:<<appenv>>media-cdn'
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: <<appenv>>rclone-config
  namespace: <<appenv>>gallery-be
data:
  rclone.conf: |
    [OvhObjectStorageS3]
    type = s3
    provider = Other
    env_auth = false
    access_key_id = d5f3fe92739c4eabbaa03361d7aeb8a3
    secret_access_key = c6227982b53441c493ba6b35c6fbabe7
    acl = private
    region = sbg
    location_constraint = sbg
    endpoint = https://s3.sbg.io.cloud.ovh.net
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: <<appenv>>gallery-be
  namespace: <<appenv>>gallery-be
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: <<appenv>>gallery-be
      version: v1
      ada-ver: v1
  template:
    metadata:
      name: <<appenv>>gallery-be
      labels:
        app: <<appenv>>gallery-be
        version: v1
        ada-ver: v1
    spec:
      containers:
        - name: gallery-be
          image: docker.adaoncloud.com/ada/<<appenv>>gallery-be:<<imagetag>>
          env:
            - name: X_ADA_DESTINATION
              value: ADA_V1
            - name: ADA_APP_ENV
              value: <<appenv>>
            - name: ADA_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: TDB_BO_GATEWAY_URL
              value: https://bo-gateway.adaoncloud.com
            - name: ADA_CDN_URL
              value: https://media.adaoncloud.com
            - name: ADA_CDN_UPDATE_URL
              value: /events/fe-static-update
            - name: TDB_OAUTH_URL
              value: https://tdb-oauth.adaoncloud.com
            - name: TDB_OAUTH_DISABLE
              value: '0'
            - name: OVH_OBJECT_ENABLE
              value: '1'
            - name: REDIS_SENTINEL_HOST
              value: ada-redis.ada-redis.svc.cluster.local
            - name: REDIS_SENTINEL_PORT
              value: '26379'
            - name: REDIS_SENTINEL_NAME
              value: ada-master
            - name: REDIS_SENTINEL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: ada-redis
                  key: redis-password
                  optional: false
            - name: REDIS_SENTINEL_DB
              value: '1'
            - name: MONGO_DB_URL
              value: mongodb://node1-2f76db0a4964324f.database.cloud.ovh.net
            - name: MONGO_DB_NAME
              value: ada-gallery-be
            - name: MONGO_DB_USER
              value: ada-gallery-be
            - name: MONGO_DB_PASS
              value: CUsrEpY5RX019GTwi3be
            - name: ELASTIC_HOST
              value: 'https://elastic.adaoncloud.com:9200'
            - name: ELASTIC_REJECTUNAUTHORIZED
              value: 'true'
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: tdb-logs-es-user-rw
                  key: username
                  optional: false
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: tdb-logs-es-user-rw
                  key: password
                  optional: false
            - name: FSTLOGLEVEL
              value: info
            - name: NODE_ENV
              value: prod
            - name: OVH_OBJECT_STORAGE
              valueFrom:
                configMapKeyRef:
                  name: ovh-vars
                  key: OVH_OBJECT_STORAGE
          ports:
            - containerPort: 80
          volumeMounts:
            - name: config
              mountPath: 'root/.config/rclone'
              readOnly: true
          imagePullPolicy: Always
      restartPolicy: Always
      imagePullSecrets:
        - name: ada-registry
      volumes:
        - name: config
          configMap:
            name: <<appenv>>rclone-config
