From a98fa36d454b86574f2ee3fbd3e90f585db77908 Mon Sep 17 00:00:00 2001
From: Tomas Hrcka <thrcka@redhat.com>
Date: Thu, 23 Apr 2020 14:51:29 +0200
Subject: [PATCH] Add Fedora Minimal Compose

---
 playbooks/openshift-apps/fmc.yml              | 57 +++++++++++++++++++
 .../fmc/templates/buildconfig.yml             | 33 +++++++++++
 .../fmc/templates/deploymentconfig.yml        | 40 +++++++++++++
 .../fmc/templates/imagestream.yml             | 29 ++++++++++
 4 files changed, 159 insertions(+)
 create mode 100644 playbooks/openshift-apps/fmc.yml
 create mode 100644 roles/openshift-apps/fmc/templates/buildconfig.yml
 create mode 100644 roles/openshift-apps/fmc/templates/deploymentconfig.yml
 create mode 100644 roles/openshift-apps/fmc/templates/imagestream.yml

diff --git a/playbooks/openshift-apps/fmc.yml b/playbooks/openshift-apps/fmc.yml
new file mode 100644
index 000000000..dbf7aef73
--- /dev/null
+++ b/playbooks/openshift-apps/fmc.yml
@@ -0,0 +1,57 @@
+- name: make the app be real
+  hosts: os_masters[0]:os_masters_stg[0]
+  user: root
+  gather_facts: False
+
+  vars_files:
+    - /srv/web/infra/ansible/vars/global.yml
+    - "/srv/private/ansible/vars.yml"
+    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
+
+  roles:
+  - role: openshift/project
+    app: fmc
+    description: Creates composes using ODCS
+    appowners:
+    - mohanboddu
+    - humaton
+    - cverna
+
+  - role: openshift/object
+    app: fmc
+    template: secret.yml
+    objectname: secret.yml
+
+  - role: openshift/object
+    app: fmc
+    template: imagestream.yml
+    objectname: imagestream.yml
+
+  - role: openshift/object
+    app: fmc
+    template: buildconfig.yml
+    objectname: buildconfig.yml
+
+  - role: openshift/start-build
+    app: fmc
+    buildname: fmc-build
+    objectname: fmc-build
+
+  - role: openshift/object
+    app: fmc
+    template: deploymentconfig.yml
+    objectname: deploymentconfig.yml
+
+  - role: openshift/rollout
+    app: fmc
+    dcname: fmc
+
+###############################################
+# actions to delete the project from OpenShift
+###############################################
+# to run: sudo rbac-playbook -l os_masters_stg[0] -t delete openshift-apps/fmc.yml
+  - role: openshift/object-delete
+    app: fmc
+    objecttype: project
+    objectname: fmc
+    tags: [ never, delete ]
diff --git a/roles/openshift-apps/fmc/templates/buildconfig.yml b/roles/openshift-apps/fmc/templates/buildconfig.yml
new file mode 100644
index 000000000..b424c73aa
--- /dev/null
+++ b/roles/openshift-apps/fmc/templates/buildconfig.yml
@@ -0,0 +1,33 @@
+apiVersion: build.openshift.io/v1
+kind: BuildConfig
+metadata:
+  name: fmc-build
+  labels:
+    build: fmc
+spec:
+  source:
+    git:
+{% if env == "staging" %}
+      ref: staging
+{% else %}
+      ref: master
+{% endif %}
+      uri: https://pagure.io/releng/fmc.git
+    type: Git
+  strategy:
+    type: Docker
+    dockerStrategy:
+      from:
+        kind: ImageStreamTag
+        name: fedora:30
+  output:
+    to:
+      kind: ImageStreamTag
+      name: fmc-img:latest
+  triggers:
+  - type: ConfigChange
+{% if compose_tracker_webhook_secret is defined %}
+  - type: Generic
+    generic:
+      secret: "{{ compose_tracker_webhook_secret }}"
+{% endif %}
diff --git a/roles/openshift-apps/fmc/templates/deploymentconfig.yml b/roles/openshift-apps/fmc/templates/deploymentconfig.yml
new file mode 100644
index 000000000..60ab6640b
--- /dev/null
+++ b/roles/openshift-apps/fmc/templates/deploymentconfig.yml
@@ -0,0 +1,40 @@
+apiVersion: apps.openshift.io/v1
+kind: DeploymentConfig
+metadata:
+  labels:
+    app: fmc
+  name: fmc
+spec:
+  replicas: 1
+  selector:
+    app: fmc
+  strategy:
+    resources: {}
+  template:
+    metadata:
+      labels:
+        app: fmc
+      name: fmc
+    spec:
+      containers:
+      - envFrom:
+        # sleep infinity is useful for debugging environment issues
+        # comment out when not debugging
+#       args: ['infinity']
+#       command: ['/usr/bin/sleep']
+        image: ""
+        imagePullPolicy: IfNotPresent
+        name: fmc
+        resources: {}
+      restartPolicy: Always
+  test: false
+  triggers:
+  - type: ConfigChange
+  - type: ImageChange
+    imageChangeParams:
+      automatic: true
+      containerNames:
+      - fmc
+      from:
+        kind: ImageStreamTag
+        name: fmc-img:latest
diff --git a/roles/openshift-apps/fmc/templates/imagestream.yml b/roles/openshift-apps/fmc/templates/imagestream.yml
new file mode 100644
index 000000000..9ac3fc24e
--- /dev/null
+++ b/roles/openshift-apps/fmc/templates/imagestream.yml
@@ -0,0 +1,29 @@
+apiVersion: v1
+kind: List
+items:
+# ImageStream for Fedora 31 image
+- apiVersion: image.openshift.io/v1
+  kind: ImageStream
+  metadata:
+    labels:
+      build: fmc
+    name: fedora
+  spec:
+    lookupPolicy:
+      local: false
+    tags:
+    - name: "30"
+      from:
+        kind: DockerImage
+        name: registry.fedoraproject.org/fedora:31
+      importPolicy:
+        scheduled: true
+      referencePolicy:
+        type: Source
+# ImageStream for resulting built fmc-img
+- apiVersion: image.openshift.io/v1
+  kind: ImageStream
+  metadata:
+    labels:
+      build: fmc
+    name: fmc-img
-- 
2.26.2

