apiVersion: v1
kind: Template
metadata:
  name: siibra-explorer-branch-deploy-2
  annotations:
    description: "Deploy branch of siibra-explorer"
    tags: "nodejs,siibra-explorer"
objects:
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    name: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
    labels:
      app: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
  spec:
    replicas: 3
    revisionHistoryLimit: 10
    selector:
      deploymentconfig: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
    template:
      metadata:
        labels:
          app: siibra-explorer-branch-deploy
          deploymentconfig: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
      spec:
          containers:
          - env:
            - name: SESSION_SECRET
              value: ${SESSION_SECRET}
            - name: HOSTNAME
              value: https://${ROUTE_HOST}
            - name: HOST_PATHNAME
              value: ${ROUTE_PATH}
              
            - name: BUILD_TEXT
              value: ${BUILD_TEXT}
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: database-password
                  name: redis-rate-limiting-db-ephemeral
            envFrom:
            - configMapRef:
                name: hbp-oauth-config-map
            - configMapRef:
                name: fluent-logging
            - configMapRef:
                name: plugins
            - configMapRef:
                name: other-deploy-config
            - configMapRef:
                name: obj-storage-cred

            image: "docker-registry.ebrains.eu/siibra/siibra-explorer:${BRANCH_NAME}"
            imagePullPolicy: Always
            livenessProbe:
              failureThreshold: 3
              httpGet:
                path: ${ROUTE_PATH}/ready
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 10
              periodSeconds: 10
              successThreshold: 1
              timeoutSeconds: 1
            readinessProbe:
              failureThreshold: 3
              httpGet:
                path: ${ROUTE_PATH}/ready
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 3
              periodSeconds: 10
              successThreshold: 1
              timeoutSeconds: 6
            name: siibra-explorer-2-${DEPLOY_ID}
            ports:
            - containerPort: 8080
              protocol: TCP
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
- apiVersion: v1
  kind: Service
  metadata:
    labels:
      app: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
    name: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
  spec:
    ports:
    - name: 8080-tcp
      port: 8080
      protocol: TCP
      targetPort: 8080
    selector:
      deploymentconfig: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
    type: ClusterIP
- apiVersion: v1
  kind: Route
  metadata:
    labels:
      app: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
    name: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
  spec:
    host: ${ROUTE_HOST}
    path: ${ROUTE_PATH}
    port:
      targetPort: 8080-tcp
    tls:
      insecureEdgeTerminationPolicy: Redirect
      termination: edge
    to:
      kind: Service
      name: siibra-explorer-branch-deploy-2-${DEPLOY_ID}
      weight: 100
    wildcardPolicy: None

parameters:
- description: Session secret
  from: '[A-Z0-9]{16}'
  generate: expression
  name: SESSION_SECRET

- name: BRANCH_NAME
  required: true
- name: DEPLOY_ID
  required: true
  description: |
    ID that distinguish deployments.
    Use only [a-z0-9]{4,}
- name: ROUTE_HOST
  description: route/host for the deployed service. Must be unique, or route may not be deployed. Must **NOT** end with with /.
  required: true
- name: ROUTE_PATH
  description: path for the deployed service. May be left empty. If set, must start with /.
  value: ''
- name: BUILD_TEXT
  description: 'UI displaying which build'
  value: 'dev build'
labels:
  template: siibra-explorer-branch-deploy-template-v2
