diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9567ca7dad90056d2a39f29d04b749712457086f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Drupal operations + +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. diff --git a/examples/clear-cache-taskrun.yaml b/examples/clear-cache-taskrun.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0c5275a7dbebb6c8cfb418f16889feb5c1575d81 --- /dev/null +++ b/examples/clear-cache-taskrun.yaml @@ -0,0 +1,13 @@ +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: clear-cache +spec: + taskRef: + name: clear-cache + params: + - name: drupalSite + value: test-dimitra-drupalsite + - name: namespace + value: test-dimitra + serviceAccountName: tektoncd diff --git a/examples/database-backup-taskrun.yaml b/examples/database-backup-taskrun.yaml new file mode 100644 index 0000000000000000000000000000000000000000..84dab7438a049118e8e5906aa1a50371ba338ea8 --- /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/examples/database-restore-taskrun.yaml b/examples/database-restore-taskrun.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5c8f1c318151be8b8060b67d01c11a219b17b239 --- /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/examples/publish-unpublish-taskrun.yaml b/examples/publish-unpublish-taskrun.yaml new file mode 100644 index 0000000000000000000000000000000000000000..139fcf428f686b12c5faa6adeafd3f1a4926e9e0 --- /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/roles/role.yaml b/roles/role.yaml new file mode 100644 index 0000000000000000000000000000000000000000..40505eb72f70681b06725fbe8cd06ba837f3135f --- /dev/null +++ b/roles/role.yaml @@ -0,0 +1,41 @@ + +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 + - 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 diff --git a/tasks/clear-cache.yaml b/tasks/clear-cache.yaml new file mode 100644 index 0000000000000000000000000000000000000000..700104d3d79a1df26d9731ef27fbb3078403b640 --- /dev/null +++ b/tasks/clear-cache.yaml @@ -0,0 +1,25 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: clear-cache +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: 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.drupalSite)" + 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 new file mode 100644 index 0000000000000000000000000000000000000000..387f8144feae3e2d99be17c0612926a8e15901e3 --- /dev/null +++ b/tasks/database-backup.yaml @@ -0,0 +1,25 @@ +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)" + 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 -- /bin/sh '-c' 'drush sql-dump > /drupal-data/dbdump.sql' diff --git a/tasks/database-restore.yaml b/tasks/database-restore.yaml new file mode 100644 index 0000000000000000000000000000000000000000..74c3f8735abb840f781405b6ba56a6b3fc6cd26f --- /dev/null +++ b/tasks/database-restore.yaml @@ -0,0 +1,25 @@ +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) + 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' diff --git a/tasks/publish-unpublish.yaml b/tasks/publish-unpublish.yaml new file mode 100644 index 0000000000000000000000000000000000000000..824d722f08ee609e891cc39f488c79430856e08b --- /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)