diff --git a/chart/cluster-tasks/Chart.yaml b/chart/cluster-tasks/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9d8e2d414a485a3eec8b823c4800e13202de058 --- /dev/null +++ b/chart/cluster-tasks/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: drupal-operations +home: https://gitlab.cern.ch/drupal/paas/drupal-operations +description: A Helm chart for Deployment of Cluster Tasks +version: 0.1.0 +icon: https://raw.githubusercontent.com/cdfoundation/artwork/main/tekton/horizontal/color/tekton-horizontal-color.png +keywords: +- drupal +- tekton +- clustertasks +maintainers: +- name: CERN IT-CDA-WF + email: drupal-admins@cern.ch diff --git a/chart/cluster-tasks/templates/clear-cache.yaml b/chart/cluster-tasks/templates/clear-cache.yaml new file mode 100644 index 0000000000000000000000000000000000000000..73ad5108ed8b125ba4ab0125904d5d1441298930 --- /dev/null +++ b/chart/cluster-tasks/templates/clear-cache.yaml @@ -0,0 +1,34 @@ +apiVersion: tekton.dev/v1beta1 +kind: ClusterTask +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 + workspaces: + - name: job + steps: + - name: clear-cache + image: {{ .Values.openshiftCli.image }} + command: + - /bin/sh + - '-c' + args: + - |- + echo "--------------------------- Clear cache ---------------------------" + echo "Drupal site name: $(params.drupalSite)" + export TASK=clear-cache + export DRUPALSITE=$(params.drupalSite) + export NAMESPACE=$(params.namespace) + export SERVING_POD_IMAGE=$(oc get -n $(params.namespace) drupalsite/$(params.drupalSite) -o=jsonpath='{.status.servingPodImage}') + envsubst < $(workspaces.job.path)/{{ .Values.jobTemplateFile }} | oc create -n $(params.namespace) -f - + oc wait --for=condition=complete job/$TASK-$(params.drupalSite) + jobStatus=$(oc get job/$TASK-$(params.drupalSite) -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo "Failed") + echo "Job status: $jobStatus" + echo "Job logs:" + oc logs job/$TASK-$DRUPALSITE -n $(params.namespace) diff --git a/chart/cluster-tasks/templates/database-backup.yaml b/chart/cluster-tasks/templates/database-backup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b6003d40121265862c4832359652f957e33df9e8 --- /dev/null +++ b/chart/cluster-tasks/templates/database-backup.yaml @@ -0,0 +1,35 @@ +apiVersion: tekton.dev/v1beta1 +kind: ClusterTask +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 + workspaces: + - name: job + steps: + - name: database-backup + image: {{ .Values.openshiftCli.image }} + command: + - /bin/sh + - '-c' + args: + - |- + echo "--------------------------- Database backup ---------------------------" + echo "Drupal site name: $(params.drupalSite)" + export TASK=database-backup + export DRUPALSITE=$(params.drupalSite) + export NAMESPACE=$(params.namespace) + export SERVING_POD_IMAGE=$(oc get -n $(params.namespace) drupalsite/$(params.drupalSite) -o=jsonpath='{.status.servingPodImage}') + export ARGS="-f dbBackUp.sql" + envsubst < $(workspaces.job.path)/{{ .Values.jobTemplateFile }} | oc create -n $(params.namespace) -f - + oc wait --for=condition=complete job/$TASK-$(params.drupalSite) + jobStatus=$(oc get job/$TASK-$(params.drupalSite) -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo "Failed") + echo "Job status: $jobStatus" + echo "Job logs:" + oc logs job/$TASK-$DRUPALSITE -n $(params.namespace) diff --git a/chart/cluster-tasks/templates/database-restore.yaml b/chart/cluster-tasks/templates/database-restore.yaml new file mode 100644 index 0000000000000000000000000000000000000000..45c44baa7c39cf5279e2491909eb3471bb8da70f --- /dev/null +++ b/chart/cluster-tasks/templates/database-restore.yaml @@ -0,0 +1,35 @@ +apiVersion: tekton.dev/v1beta1 +kind: ClusterTask +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 + workspaces: + - name: job + steps: + - name: database-restore + image: {{ .Values.openshiftCli.image }} + command: + - /bin/sh + - '-c' + args: + - |- + echo "--------------------------- Database restore ---------------------------" + echo "Drupal site name: $(params.drupalSite)" + export TASK=database-restore + export DRUPALSITE=$(params.drupalSite) + export NAMESPACE=$(params.namespace) + export SERVING_POD_IMAGE=$(oc get -n $(params.namespace) drupalsite/$(params.drupalSite) -o=jsonpath='{.status.servingPodImage}') + export ARGS="-f dbBackUp.sql" + envsubst < $(workspaces.job.path)/{{ .Values.jobTemplateFile }} | oc create -n $(params.namespace) -f - + oc wait --for=condition=complete job/$TASK-$(params.drupalSite) + jobStatus=$(oc get job/$TASK-$(params.drupalSite) -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo "Failed") + echo "Job status: $jobStatus" + echo "Job logs:" + oc logs job/$TASK-$DRUPALSITE -n $(params.namespace) diff --git a/chart/cluster-tasks/values.yaml b/chart/cluster-tasks/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..aa18145e5429760da681202c342bde6c4afc231a --- /dev/null +++ b/chart/cluster-tasks/values.yaml @@ -0,0 +1,4 @@ +openshiftCli: + image: gitlab-registry.cern.ch/drupal/paas/drupal-operations/openshift-cli:latest + +jobTemplateFile: job-operations-template.yaml diff --git a/examples/clear-cache-taskrun.yaml b/examples/clear-cache-taskrun.yaml index 4ba9e0f5bb319091752a0a11fdeab620aa937acb..3adb40c75a6f73142c09e99614edfbd1a1faf060 100644 --- a/examples/clear-cache-taskrun.yaml +++ b/examples/clear-cache-taskrun.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: - name: clear-cache + generateName: clear-cache- spec: taskRef: name: clear-cache @@ -11,4 +11,8 @@ spec: value: test-dimitra-drupalsite - name: namespace value: test-dimitra + workspaces: + - name: job + configmap: + name: job-operations-template-configmap serviceAccountName: tektoncd diff --git a/examples/database-backup-taskrun.yaml b/examples/database-backup-taskrun.yaml index eff876479176861fea62b0a04b3ea9067ae4e77d..266e50edcd90f6588e5db01d9f2563ff68ea9a68 100644 --- a/examples/database-backup-taskrun.yaml +++ b/examples/database-backup-taskrun.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: - name: database-backup + generateName: database-backup- spec: taskRef: name: database-backup @@ -11,4 +11,8 @@ spec: value: test-dimitra-drupalsite - name: namespace value: test-dimitra + workspaces: + - name: job + configmap: + name: job-operations-template-configmap serviceAccountName: tektoncd diff --git a/examples/database-restore-taskrun.yaml b/examples/database-restore-taskrun.yaml index 0fcc44a7caf93ebcd8b3e9c3f7f5ed73833c7c37..ab0b9ae947ba1e9fc90b594daf1453cfd4d91848 100644 --- a/examples/database-restore-taskrun.yaml +++ b/examples/database-restore-taskrun.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: - name: database-restore + generateName: database-restore- spec: taskRef: name: database-restore @@ -11,4 +11,8 @@ spec: value: test-dimitra-drupalsite - name: namespace value: test-dimitra + workspaces: + - name: job + configmap: + name: job-operations-template-configmap serviceAccountName: tektoncd diff --git a/examples/publish-unpublish-taskrun.yaml b/examples/publish-unpublish-taskrun.yaml deleted file mode 100644 index ed775b6298bfafa2803b6cee5c10916137ca8b5f..0000000000000000000000000000000000000000 --- a/examples/publish-unpublish-taskrun.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: TaskRun -metadata: - name: publish-unpublish -spec: - taskRef: - name: publish-unpublish - kind: ClusterTask - 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 deleted file mode 100644 index 40505eb72f70681b06725fbe8cd06ba837f3135f..0000000000000000000000000000000000000000 --- a/roles/role.yaml +++ /dev/null @@ -1,41 +0,0 @@ - -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 deleted file mode 100644 index 80df1fa21319932180e820ba44ee690773d4a2f4..0000000000000000000000000000000000000000 --- a/tasks/clear-cache.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -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 deleted file mode 100644 index e2891745f2b69ed2e5b0a5b16dfb42c9bc41ffd9..0000000000000000000000000000000000000000 --- a/tasks/database-backup.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -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 deleted file mode 100644 index 406a161afbf63f873eb6136b1eb2e1d362d35954..0000000000000000000000000000000000000000 --- a/tasks/database-restore.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -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 deleted file mode 100644 index 0edd041816fa45539c5d79d9f3fb2c98be2eaab9..0000000000000000000000000000000000000000 --- a/tasks/publish-unpublish.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: ClusterTask -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)