{% macro load_file(filename) %}{% include filename %}{%- endmacro -%}
---
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: python-310-collectd
  labels:
    app: fmn
    build: python-310-collectd
spec:
  runPolicy: Serial
  source:
    type: Dockerfile
    dockerfile: |-
      {{ load_file('Dockerfile-builder-image') | indent(6) }}
  strategy:
    type: Docker
    dockerStrategy:
      from:
        kind: ImageStreamTag
        name: python-310:latest
  output:
    to:
      kind: ImageStreamTag
      name: python-310-collectd:latest
  triggers:
  - type: ImageChange
---
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: fmn
  labels:
    app: fmn
    build: fmn
spec:
  runPolicy: Serial
  source:
    type: Git
    git:
      uri: https://github.com/fedora-infra/fmn.git
      ref: {{ (env == 'production')|ternary('stable', 'staging') }}
    contextDir: /
  strategy:
    type: Source
    sourceStrategy:
      from:
        kind: ImageStreamTag
        # Our own ImageStream with collectd added to it
        name: python-310-collectd:latest
      env:
      # The .s2i/bin/assemble script uses this to build the frontend with the
      # correct API and Ipsilon addresses.
      - name: FEDORA_ENV
        value: "{{ env }}"
  output:
    to:
      kind: ImageStreamTag
      name: fmn:latest
  triggers:
  - type: ConfigChange
  - type: ImageChange
  - type: GitHub
    github:
      # Not sure why secretReference does not work, but it doesn't.
      # secretReference:
      #   name: fmn-github-webook
      secret: "{{ fmn_stg_github_secret }}"
---
# Sendria, to display email notifications in staging
{% if env == 'staging' %}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: sendria
  labels:
    app: fmn
    build: sendria
spec:
  runPolicy: Serial
  # We build the sendria image with a few fixes.
  source:
    type: Dockerfile
    dockerfile: |-
      {{ load_file('Dockerfile-sendria') | indent(6) }}
  strategy:
    type: Docker
  output:
    to:
      kind: ImageStreamTag
      name: sendria:latest
  triggers:
  - type: ConfigChange
  - type: ImageChange
{% endif %}
