---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
    service: oraculum-api-endpoint
  name: oraculum-api-endpoint
spec:
  replicas: 1
  selector:
    app: oraculum
    deploymentconfig: oraculum
  strategy:
    type: Recreate
    recreateParams:
      mid:
        failurePolicy: Abort
        execNewPod:
          containerName: oraculum-api-endpoint
          # Oraculum would automatically proceed with upgrade_db if necessary
          # init_db isn't dropping anything, so it's safe to call every time the pod starts
          command: ["python", "/opt/app-root/src/oraculum/cli.py", "init_db"]
          # and then just the gunicorn for the frontend part of the backend :)
          volumes:
           - oraculum-secret-volume
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum
    spec:
      containers:
      - name: oraculum-api-endpoint
        image: packager-dashboard:latest
        ports:
        - containerPort: 8080
        resources: {}
        env:
        # Database
        - name: POSTGRESQL_USER
          value: "{{ oraculum_db_user }}"
        - name: POSTGRESQL_PASSWORD
          value: "{{ oraculum_db_pass }}"
        - name: POSTGRESQL_DATABASE
          value: "{{ oraculum_db_name }}"
        - name: POSTGRESQL_SERVICE_HOST
          value: "db01{{ env_suffix }}.iad2.fedoraproject.org"
        - name: POSTGRESQL_SERVICE_PORT
          value: "5432"
        # Redis
        - name: REDIS_PASSWORD
          value: "{{ oraculum_redis_pass }}"
        - name: REDIS_SERVICE_HOST
          value: "oraculum-redis.oraculum.svc.cluster.local"
        - name: REDIS_SERVICE_PORT_REDIS
          value: "6379"
        # Misc
        - name: SECRET_KEY
          value: "{{ oraculum_secret_key }}"
        - name: OPENSHIFT_PROD
{% if env == 'staging' %}
          value: "0"
{% else %}
          value: "1"
{% endif %}
        - name: MOTD_PASSWORD
          value: "{{ oraculum_motd_pass }}"
        # WatchDog emails
        - name: SEND_ERROR_EMAILS
          value: "true"
        - name: ADMIN_EMAILS
          value: "fzatlouk@redhat.com"
        - name: SMTP_CONFIG
          value: "bastion.iad2.fedoraproject.org;;;watchdog@packager-dashboard{{ env_suffix }}.fedoraproject.org;"
        - name: BZ_API_KEY
          value: "{{ oraculum_bz_api_key }}"
        volumeMounts:
        - name: oraculum-secret-volume
          mountPath: /opt/app-root/secret/
          readOnly: true
        readinessProbe:
          timeoutSeconds: 5
          initialDelaySeconds: 5
          httpGet:
            path: /
            port: 8080
        livenessProbe:
          timeoutSeconds: 15
          initialDelaySeconds: 30
          httpGet:
            path: /
            port: 8080
      volumes:
      - name: oraculum-secret-volume
        secret:
          secretName: oraculum-secret

  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-api-endpoint
      from:
        kind: ImageStreamTag
        name: packager-dashboard:latest
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
  name: oraculum-worker
spec:
{% if env == 'staging' %}
  replicas: 2
{% else %}
  replicas: 4 # Change me to some biiig numba after you got me working
{% endif %}
  selector:
    app: oraculum
    deploymentconfig: oraculum
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum
    spec:
      containers:
      - name: oraculum-worker
        image: packager-dashboard:latest
        command: ["celery", "-A", "oraculum.celery_app", "worker", "-c", "8", "--loglevel=INFO"]
        resources: {}
        env:
        # Database
        - name: POSTGRESQL_USER
          value: "{{ oraculum_db_user }}"
        - name: POSTGRESQL_PASSWORD
          value: "{{ oraculum_db_pass }}"
        - name: POSTGRESQL_DATABASE
          value: "{{ oraculum_db_name }}"
        - name: POSTGRESQL_SERVICE_HOST
          value: "db01{{ env_suffix }}.iad2.fedoraproject.org"
        - name: POSTGRESQL_SERVICE_PORT
          value: "5432"
        # Redis
        - name: REDIS_PASSWORD
          value: "{{ oraculum_redis_pass }}"
        - name: REDIS_SERVICE_HOST
          value: "oraculum-redis.oraculum.svc.cluster.local"
        - name: REDIS_SERVICE_PORT_REDIS
          value: "6379"
        # Misc
        - name: SECRET_KEY
          value: "{{ oraculum_secret_key }}"
        - name: OPENSHIFT_PROD
{% if env == 'staging' %}
          value: "0"
{% else %}
          value: "1"
{% endif %}
        - name: MOTD_PASSWORD
          value: "{{ oraculum_motd_pass }}"
        # WatchDog emails
        - name: SEND_ERROR_EMAILS
          value: "true"
        - name: ADMIN_EMAILS
          value: "fzatlouk@redhat.com"
        - name: SMTP_CONFIG
          value: "bastion.iad2.fedoraproject.org;;;watchdog@packager-dashboard{{ env_suffix }}.fedoraproject.org;"
        - name: BZ_API_KEY
          value: "{{ oraculum_bz_api_key }}"
        volumeMounts:
        - name: oraculum-secret-volume
          mountPath: /opt/app-root/secret/
          readOnly: true
      volumes:
      - name: oraculum-secret-volume
        secret:
          secretName: oraculum-secret

  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-worker
      from:
        kind: ImageStreamTag
        name: packager-dashboard:latest
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
  name: oraculum-beat
spec:
  replicas: 1 # Never change this to more or less than ONE!
  selector:
    app: oraculum
    deploymentconfig: oraculum
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum
    spec:
      containers:
      - name: oraculum-beat
        image: packager-dashboard:latest
        command: ["celery", "-A", "oraculum.celery_app", "beat", "--loglevel=INFO"]
        resources: {}
        env:
        # Database
        - name: POSTGRESQL_USER
          value: "{{ oraculum_db_user }}"
        - name: POSTGRESQL_PASSWORD
          value: "{{ oraculum_db_pass }}"
        - name: POSTGRESQL_DATABASE
          value: "{{ oraculum_db_name }}"
        - name: POSTGRESQL_SERVICE_HOST
          value: "db01{{ env_suffix }}.iad2.fedoraproject.org"
        - name: POSTGRESQL_SERVICE_PORT
          value: "5432"
        # Redis
        - name: REDIS_PASSWORD
          value: "{{ oraculum_redis_pass }}"
        - name: REDIS_SERVICE_HOST
          value: "oraculum-redis.oraculum.svc.cluster.local"
        - name: REDIS_SERVICE_PORT_REDIS
          value: "6379"
        # Misc
        - name: SECRET_KEY
          value: "{{ oraculum_secret_key }}"
        - name: OPENSHIFT_PROD
{% if env == 'staging' %}
          value: "0"
{% else %}
          value: "1"
{% endif %}
        - name: MOTD_PASSWORD
          value: "{{ oraculum_motd_pass }}"
        # WatchDog emails
        - name: SEND_ERROR_EMAILS
          value: "true"
        - name: ADMIN_EMAILS
          value: "fzatlouk@redhat.com"
        - name: SMTP_CONFIG
          value: "bastion.iad2.fedoraproject.org;;;watchdog@packager-dashboard{{ env_suffix }}.fedoraproject.org;"
        - name: BZ_API_KEY
          value: "{{ oraculum_bz_api_key }}"
        volumeMounts:
        - name: oraculum-secret-volume
          mountPath: /opt/app-root/secret/
          readOnly: true
      volumes:
      - name: oraculum-secret-volume
        secret:
          secretName: oraculum-secret

  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-beat
      from:
        kind: ImageStreamTag
        name: packager-dashboard:latest
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
  name: oraculum-flower
spec:
  replicas: 1 # Never change this to more or less than ONE!
  selector:
    app: oraculum
    deploymentconfig: oraculum
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum
    spec:
      containers:
      - name: oraculum-flower
        image: packager-dashboard:latest
        ports:
        - containerPort: 8080
        command: ["celery", "-A", "oraculum.celery_app", "flower", "--url_prefix=_flower", "--port=8080", "--address=0.0.0.0", "--basic_auth=frantisekz:{{ oraculum_flower_password }}"]
        resources: {}
        env:
        # Database
        - name: POSTGRESQL_USER
          value: "{{ oraculum_db_user }}"
        - name: POSTGRESQL_PASSWORD
          value: "{{ oraculum_db_pass }}"
        - name: POSTGRESQL_DATABASE
          value: "{{ oraculum_db_name }}"
        - name: POSTGRESQL_SERVICE_HOST
          value: "db01{{ env_suffix }}.iad2.fedoraproject.org"
        - name: POSTGRESQL_SERVICE_PORT
          value: "5432"
        # Redis
        - name: REDIS_PASSWORD
          value: "{{ oraculum_redis_pass }}"
        - name: REDIS_SERVICE_HOST
          value: "oraculum-redis.oraculum.svc.cluster.local"
        - name: REDIS_SERVICE_PORT_REDIS
          value: "6379"
        # Misc
        - name: SECRET_KEY
          value: "{{ oraculum_secret_key }}"
        - name: OPENSHIFT_PROD
{% if env == 'staging' %}
          value: "0"
{% else %}
          value: "1"
{% endif %}
        - name: MOTD_PASSWORD
          value: "{{ oraculum_motd_pass }}"
        # WatchDog emails
        - name: SEND_ERROR_EMAILS
          value: "true"
        - name: ADMIN_EMAILS
          value: "fzatlouk@redhat.com"
        - name: SMTP_CONFIG
          value: "bastion.iad2.fedoraproject.org;;;watchdog@packager-dashboard{{ env_suffix }}.fedoraproject.org;"
        - name: BZ_API_KEY
          value: "{{ oraculum_bz_api_key }}"
        volumeMounts:
        - name: oraculum-secret-volume
          mountPath: /opt/app-root/secret/
          readOnly: true
      volumes:
      - name: oraculum-secret-volume
        secret:
          secretName: oraculum-secret
  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-flower
      from:
        kind: ImageStreamTag
        name: packager-dashboard:latest
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
    service: oraculum-redis
  name: oraculum-redis
spec:
  replicas: 1 # Never change this to more or less than ONE!
  selector:
    app: oraculum
    deploymentconfig: oraculum-redis
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum-redis
    spec:
      containers:
      - name: oraculum-redis
        image: packager-dashboard-redis:latest
        resources: {}
        env:
        - name: REDIS_PASSWORD
          value: "{{ oraculum_redis_pass }}"
  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-redis
      from:
        kind: ImageStreamTag
        name: packager-dashboard-redis:latest
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: oraculum
    service: oraculum-frontend
  name: oraculum-frontend
spec:
  replicas: 1 # Never change this to more or less than ONE!
  selector:
    app: oraculum
    deploymentconfig: oraculum-frontend
  template:
    metadata:
      labels:
        app: oraculum
        deploymentconfig: oraculum-frontend
    spec:
      containers:
      - name: oraculum-frontend
        image: oraculum-frontend:latest
        resources: {}
        env:
        - name: SUBDIR
          value: "/"
        - name: API
          value: "https://packager-dashboard{{ env_suffix }}.fedoraproject.org/api/v1/"
        - name: "APIv2"
          value: "https://packager-dashboard{{ env_suffix }}.fedoraproject.org/api/v2/"
  triggers:
  - type: ConfigChange
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
      - oraculum-frontend
      from:
        kind: ImageStreamTag
        name: oraculum-frontend:latest
