From 7f8877d83e2be3e563511386f12a4c34d26128d4 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Tue, 16 Mar 2021 16:47:51 +0100
Subject: [PATCH 01/10] Add task to clean cache of drupal site

---
 README.md                         |  3 +++
 taskruns/clear-cache-taskrun.yaml | 11 +++++++++++
 tasks/clear-cache.yaml            | 22 ++++++++++++++++++++++
 3 files changed, 36 insertions(+)
 create mode 100644 README.md
 create mode 100644 taskruns/clear-cache-taskrun.yaml
 create mode 100644 tasks/clear-cache.yaml

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d1dd2a0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Drupal operations
+
+This projects includes operations on Drupal sites or across infrastructure that are not part of the drupalSite-operator, such as Tekton tasks.
diff --git a/taskruns/clear-cache-taskrun.yaml b/taskruns/clear-cache-taskrun.yaml
new file mode 100644
index 0000000..9cfd358
--- /dev/null
+++ b/taskruns/clear-cache-taskrun.yaml
@@ -0,0 +1,11 @@
+apiVersion: tekton.dev/v1beta1
+kind: TaskRun
+metadata:
+  name: clear-cache
+spec:
+  taskRef:
+    name: clear-cache
+  params:
+    - name: drupalSiteName
+      value: test-dimitra-drupalsite
+  serviceAccountName: tektoncd
diff --git a/tasks/clear-cache.yaml b/tasks/clear-cache.yaml
new file mode 100644
index 0000000..c5aa79a
--- /dev/null
+++ b/tasks/clear-cache.yaml
@@ -0,0 +1,22 @@
+apiVersion: tekton.dev/v1beta1
+kind: Task
+metadata:
+  name: clear-cache
+spec:
+  params:
+    - name: drupalSiteName
+      type: string
+      description: The name of the drupal site
+  steps:
+    - name: clear-cache
+      image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
+      command:
+        - /bin/sh
+        - '-c'
+      args:
+      - |-
+        echo "--------------------------- Clear cache ---------------------------"
+        echo "Drupal site name: $(params.drupalSiteName)"
+        depolymentPod=$(oc get pods -l drupalSite=$(params.drupalSiteName) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        echo "Deployment pod: $depolymentPod"
+        oc exec $depolymentPod -c php-fpm drush cr
-- 
GitLab


From 12125c4c9afc60819ea3f8d9dbd8a8aa8db8b761 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 10:09:16 +0100
Subject: [PATCH 02/10] Move task run to examples and add namespace param

---
 {taskruns => examples}/clear-cache-taskrun.yaml | 4 +++-
 tasks/clear-cache.yaml                          | 9 ++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)
 rename {taskruns => examples}/clear-cache-taskrun.yaml (73%)

diff --git a/taskruns/clear-cache-taskrun.yaml b/examples/clear-cache-taskrun.yaml
similarity index 73%
rename from taskruns/clear-cache-taskrun.yaml
rename to examples/clear-cache-taskrun.yaml
index 9cfd358..0c5275a 100644
--- a/taskruns/clear-cache-taskrun.yaml
+++ b/examples/clear-cache-taskrun.yaml
@@ -6,6 +6,8 @@ spec:
   taskRef:
     name: clear-cache
   params:
-    - name: drupalSiteName
+    - name: drupalSite
       value: test-dimitra-drupalsite
+    - name: namespace
+      value: test-dimitra
   serviceAccountName: tektoncd
diff --git a/tasks/clear-cache.yaml b/tasks/clear-cache.yaml
index c5aa79a..e3b59bb 100644
--- a/tasks/clear-cache.yaml
+++ b/tasks/clear-cache.yaml
@@ -4,9 +4,12 @@ metadata:
   name: clear-cache
 spec:
   params:
-    - name: drupalSiteName
+    - name: drupalSite
       type: string
       description: The name of the drupal site
+    - name: namespace
+      type: string
+      description: The namespace of the drupal site
   steps:
     - name: clear-cache
       image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
@@ -16,7 +19,7 @@ spec:
       args:
       - |-
         echo "--------------------------- Clear cache ---------------------------"
-        echo "Drupal site name: $(params.drupalSiteName)"
-        depolymentPod=$(oc get pods -l drupalSite=$(params.drupalSiteName) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        echo "Drupal site name: $(params.drupalSite)"
+        depolymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
         echo "Deployment pod: $depolymentPod"
         oc exec $depolymentPod -c php-fpm drush cr
-- 
GitLab


From 072fcce6e7f5f2f28e7c1ea17503b0772433c444 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 11:52:11 +0100
Subject: [PATCH 03/10] Added roles

---
 roles/role.yaml | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 roles/role.yaml

diff --git a/roles/role.yaml b/roles/role.yaml
new file mode 100644
index 0000000..98d8ab6
--- /dev/null
+++ b/roles/role.yaml
@@ -0,0 +1,24 @@
+
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
+  name: tektoncd-role
+  namespace: test-dimitra
+  annotations:
+    tekton.cern.ch/requiredForTask: clear-cache
+rules:
+- apiGroups:
+  - ""
+  resources:
+  - pods
+  - services
+  - endpoints
+  - persistentvolumeclaims
+  - events
+  - configmaps
+  - secrets
+  - pods/log
+  - pods/exec
+  - limitranges
+  verbs:
+  - '*'
\ No newline at end of file
-- 
GitLab


From 790bb7b8c7dcd60e0b8bf633e99324c246337a98 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 14:07:57 +0100
Subject: [PATCH 04/10] Add task for database backup of a drupal site

---
 examples/database-backup-taskrun.yaml | 13 +++++++++++++
 tasks/database-backup.yaml            | 26 ++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 examples/database-backup-taskrun.yaml
 create mode 100644 tasks/database-backup.yaml

diff --git a/examples/database-backup-taskrun.yaml b/examples/database-backup-taskrun.yaml
new file mode 100644
index 0000000..84dab74
--- /dev/null
+++ b/examples/database-backup-taskrun.yaml
@@ -0,0 +1,13 @@
+apiVersion: tekton.dev/v1beta1
+kind: TaskRun
+metadata:
+  name: database-backup
+spec:
+  taskRef:
+    name: database-backup
+  params:
+    - name: drupalSite
+      value: test-dimitra-drupalsite
+    - name: namespace
+      value: test-dimitra
+  serviceAccountName: tektoncd
diff --git a/tasks/database-backup.yaml b/tasks/database-backup.yaml
new file mode 100644
index 0000000..96f5a76
--- /dev/null
+++ b/tasks/database-backup.yaml
@@ -0,0 +1,26 @@
+apiVersion: tekton.dev/v1beta1
+kind: Task
+metadata:
+  name: database-backup
+spec:
+  params:
+    - name: drupalSite
+      type: string
+      description: The name of the drupal site
+    - name: namespace
+      type: string
+      description: The namespace of the drupal site
+  steps:
+    - name: database-backup
+      image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
+      command:
+        - /bin/sh
+        - '-c'
+      args:
+      - |-
+        echo "--------------------------- Database backup ---------------------------"
+        echo "Drupal site name: $(params.drupalSite)"
+        depolymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        mkdir /tmp/db_backups
+        echo "Deployment pod: $depolymentPod"
+        oc exec $depolymentPod -c php-fpm -- /bin/sh '-c' 'drush sql-dump > /drupal-data/dbdump.sql'
-- 
GitLab


From 834152ca3e6b80af335f819b3ae32ed1967c41a5 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 14:09:20 +0100
Subject: [PATCH 05/10] Fix typo

---
 tasks/clear-cache.yaml     | 6 +++---
 tasks/database-backup.yaml | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tasks/clear-cache.yaml b/tasks/clear-cache.yaml
index e3b59bb..700104d 100644
--- a/tasks/clear-cache.yaml
+++ b/tasks/clear-cache.yaml
@@ -20,6 +20,6 @@ spec:
       - |-
         echo "--------------------------- Clear cache ---------------------------"
         echo "Drupal site name: $(params.drupalSite)"
-        depolymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
-        echo "Deployment pod: $depolymentPod"
-        oc exec $depolymentPod -c php-fpm drush cr
+        deploymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        echo "Deployment pod: $deploymentPod"
+        oc exec $deploymentPod -c php-fpm drush cr
diff --git a/tasks/database-backup.yaml b/tasks/database-backup.yaml
index 96f5a76..1100939 100644
--- a/tasks/database-backup.yaml
+++ b/tasks/database-backup.yaml
@@ -20,7 +20,7 @@ spec:
       - |-
         echo "--------------------------- Database backup ---------------------------"
         echo "Drupal site name: $(params.drupalSite)"
-        depolymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        deploymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
         mkdir /tmp/db_backups
-        echo "Deployment pod: $depolymentPod"
-        oc exec $depolymentPod -c php-fpm -- /bin/sh '-c' 'drush sql-dump > /drupal-data/dbdump.sql'
+        echo "Deployment pod: $deploymentPod"
+        oc exec $deploymentPod -c php-fpm -- /bin/sh '-c' 'drush sql-dump > /drupal-data/dbdump.sql'
-- 
GitLab


From 37fa9dcd9f6b44867c6c86b746afb7b54f1c156b Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 14:23:24 +0100
Subject: [PATCH 06/10] Add task for database restore of drupal site

---
 examples/database-restore-taskrun.yaml | 13 +++++++++++++
 tasks/database-restore.yaml            | 26 ++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 examples/database-restore-taskrun.yaml
 create mode 100644 tasks/database-restore.yaml

diff --git a/examples/database-restore-taskrun.yaml b/examples/database-restore-taskrun.yaml
new file mode 100644
index 0000000..5c8f1c3
--- /dev/null
+++ b/examples/database-restore-taskrun.yaml
@@ -0,0 +1,13 @@
+apiVersion: tekton.dev/v1beta1
+kind: TaskRun
+metadata:
+  name: database-restore
+spec:
+  taskRef:
+    name: database-restore
+  params:
+    - name: drupalSite
+      value: test-dimitra-drupalsite
+    - name: namespace
+      value: test-dimitra
+  serviceAccountName: tektoncd
diff --git a/tasks/database-restore.yaml b/tasks/database-restore.yaml
new file mode 100644
index 0000000..811ea2d
--- /dev/null
+++ b/tasks/database-restore.yaml
@@ -0,0 +1,26 @@
+apiVersion: tekton.dev/v1beta1
+kind: Task
+metadata:
+  name: database-restore
+spec:
+  params:
+    - name: drupalSite
+      type: string
+      description: The name of the drupal site
+    - name: namespace
+      type: string
+      description: The namespace of the drupal site
+  steps:
+    - name: database-restore
+      image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
+      command:
+        - /bin/sh
+        - '-c'
+      args:
+      - |-
+        echo "--------------------------- Database restore ---------------------------"
+        echo "Drupal site name: $(params.drupalSite)"
+        deploymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
+        mkdir /tmp/db_backups
+        echo "Deployment pod: $deploymentPod"
+        oc exec drupal-test-dimitra-drupalsite-8f5478886-d79s6 -c php-fpm -- /bin/sh '-c' 'drush sql-drop -y; drush sql-connect < /drupal-data/dbdump.sql'
-- 
GitLab


From 1eb9a10dda26a1a76e096a666a6a119910115304 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 14:48:02 +0100
Subject: [PATCH 07/10] Remove unneeded command

---
 tasks/database-backup.yaml  | 1 -
 tasks/database-restore.yaml | 1 -
 2 files changed, 2 deletions(-)

diff --git a/tasks/database-backup.yaml b/tasks/database-backup.yaml
index 1100939..387f814 100644
--- a/tasks/database-backup.yaml
+++ b/tasks/database-backup.yaml
@@ -21,6 +21,5 @@ spec:
         echo "--------------------------- Database backup ---------------------------"
         echo "Drupal site name: $(params.drupalSite)"
         deploymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
-        mkdir /tmp/db_backups
         echo "Deployment pod: $deploymentPod"
         oc exec $deploymentPod -c php-fpm -- /bin/sh '-c' 'drush sql-dump > /drupal-data/dbdump.sql'
diff --git a/tasks/database-restore.yaml b/tasks/database-restore.yaml
index 811ea2d..74c3f87 100644
--- a/tasks/database-restore.yaml
+++ b/tasks/database-restore.yaml
@@ -21,6 +21,5 @@ spec:
         echo "--------------------------- Database restore ---------------------------"
         echo "Drupal site name: $(params.drupalSite)"
         deploymentPod=$(oc get pods -n $(params.namespace) -l drupalSite=$(params.drupalSite) -l app=drupal -o custom-columns=POD:.metadata.name --no-headers)
-        mkdir /tmp/db_backups
         echo "Deployment pod: $deploymentPod"
         oc exec drupal-test-dimitra-drupalsite-8f5478886-d79s6 -c php-fpm -- /bin/sh '-c' 'drush sql-drop -y; drush sql-connect < /drupal-data/dbdump.sql'
-- 
GitLab


From fa9020bab644a183d1cb8d804c49313bd04208b0 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 15:06:31 +0100
Subject: [PATCH 08/10] Add drupal.webservices.cern.ch api group

---
 roles/role.yaml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/roles/role.yaml b/roles/role.yaml
index 98d8ab6..40505eb 100644
--- a/roles/role.yaml
+++ b/roles/role.yaml
@@ -20,5 +20,22 @@ rules:
   - pods/log
   - pods/exec
   - limitranges
+  - drupalsites
+  verbs:
+  - '*'
+- apiGroups:
+  - "drupal.webservices.cern.ch"
+  resources:
+  - pods
+  - services
+  - endpoints
+  - persistentvolumeclaims
+  - events
+  - configmaps
+  - secrets
+  - pods/log
+  - pods/exec
+  - limitranges
+  - drupalsites
   verbs:
   - '*'
\ No newline at end of file
-- 
GitLab


From 0385b283182df9d42aa9523f62e8997e5d5f4e20 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 15:07:26 +0100
Subject: [PATCH 09/10] Add task for editing DrupalSite.spec.publish

---
 examples/publish-unpublish-taskrun.yaml | 15 ++++++++++++++
 tasks/publish-unpublish.yaml            | 26 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 examples/publish-unpublish-taskrun.yaml
 create mode 100644 tasks/publish-unpublish.yaml

diff --git a/examples/publish-unpublish-taskrun.yaml b/examples/publish-unpublish-taskrun.yaml
new file mode 100644
index 0000000..139fcf4
--- /dev/null
+++ b/examples/publish-unpublish-taskrun.yaml
@@ -0,0 +1,15 @@
+apiVersion: tekton.dev/v1beta1
+kind: TaskRun
+metadata:
+  name: publish-unpublish
+spec:
+  taskRef:
+    name: publish-unpublish
+  params:
+    - name: drupalSite
+      value: test-dimitra-drupalsite
+    - name: namespace
+      value: test-dimitra
+    - name: publish
+      value: "true"
+  serviceAccountName: tektoncd
diff --git a/tasks/publish-unpublish.yaml b/tasks/publish-unpublish.yaml
new file mode 100644
index 0000000..824d722
--- /dev/null
+++ b/tasks/publish-unpublish.yaml
@@ -0,0 +1,26 @@
+apiVersion: tekton.dev/v1beta1
+kind: Task
+metadata:
+  name: publish-unpublish
+spec:
+  params:
+    - name: drupalSite
+      type: string
+      description: The name of the drupal site
+    - name: namespace
+      type: string
+      description: The namespace of the drupal site
+    - name: publish
+      type: string
+      description: Publish a drupal site or not
+  steps:
+    - name: publish-unpublish
+      image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
+      command:
+        - /bin/sh
+        - '-c'
+      args:
+      - |-
+        echo "--------------------------- Publsih/Unpublish ---------------------------"
+        echo "Drupal site name: $(params.drupalSite)"
+        oc patch --type=merge drupalsites.drupal.webservices.cern.ch/$(params.drupalSite) -p '{"spec":{"publish":$(params.publish)}}' -n $(params.namespace)
-- 
GitLab


From d5ad2f07c0b9336419e1d6c8c249f048ffcc6e86 Mon Sep 17 00:00:00 2001
From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch>
Date: Fri, 19 Mar 2021 16:49:19 +0100
Subject: [PATCH 10/10] Update README.md

---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d1dd2a0..9567ca7 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
 # Drupal operations
 
-This projects includes operations on Drupal sites or across infrastructure that are not part of the drupalSite-operator, such as Tekton tasks.
+This project includes operations on Drupal sites or across infrastructure that are not part of the drupalSite-operator, such as Tekton tasks.
+
+We implement actions that the infrastructure users can apply ad-hoc to their websites, and also other infrastructure components can use to perform their tasks.
-- 
GitLab