From 6f5eb808370cc14aafe28dcb8a4c3bb9ff79fad7 Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Tue, 27 Jul 2021 10:23:34 +0200
Subject: [PATCH] Use generic script to install optional apps

---
 .gitlab-ci.yml                     |  8 ++++----
 docs/installation_instructions.rst | 10 +++++-----
 install/install-app.sh             | 18 ++++++++++++++++++
 install/install-nextcloud.sh       | 15 ---------------
 install/install-rocketchat.sh      | 15 ---------------
 install/install-velero.sh          | 15 ---------------
 install/install-wordpress.sh       | 15 ---------------
 7 files changed, 27 insertions(+), 69 deletions(-)
 create mode 100755 install/install-app.sh
 delete mode 100755 install/install-nextcloud.sh
 delete mode 100755 install/install-rocketchat.sh
 delete mode 100755 install/install-velero.sh
 delete mode 100755 install/install-wordpress.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0e4bcfec4..99115fd5e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -93,7 +93,7 @@ include:
     - changes:
         - flux2/apps/$APP/*.yaml
         - flux2/cluster/optional/$APP/*.yaml
-        - install/install-${APP}.sh
+        - install/install-app.sh
         - test/taiko/*
     - if: '$TRIGGER_JOBS =~ /enable-nextcloud/'
     - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*enable-nextcloud/'
@@ -116,7 +116,7 @@ include:
     - changes:
         - flux2/apps/$APP/*.yaml
         - flux2/cluster/optional/$APP/*.yaml
-        - install/install-${APP}.sh
+        - install/install-app.sh
         - test/taiko/*
     - if: '$TRIGGER_JOBS =~ /enable-rocketchat/'
     - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*enable-rocketchat/'
@@ -138,7 +138,7 @@ include:
         - flux2/apps/$APP/*.yaml
         - flux2/cluster/optional/$APP/*.yaml
         - flux2/infrastructure/sources/wordpress.yaml
-        - install/install-${APP}.sh
+        - install/install-app.sh
         - test/taiko/*
     - if: '$TRIGGER_JOBS =~ /enable-wordpress/'
     - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*enable-wordpress/'
@@ -434,7 +434,7 @@ single-sign-on-helm-release:
     - *debug_information
     # Add optional override values we need for the CI pipeline only
     - '[ -f ./install/overrides/oas-${APP}-override.yaml ] && kubectl apply -n oas-apps -f ./install/overrides/oas-${APP}-override.yaml'
-    - bash ./install/install-${APP}.sh
+    - bash ./install/install-app.sh ${APP}
   extends:
     - .ssh_setup
   interruptible: true
diff --git a/docs/installation_instructions.rst b/docs/installation_instructions.rst
index d74ad4a37..c0f61ccba 100644
--- a/docs/installation_instructions.rst
+++ b/docs/installation_instructions.rst
@@ -352,7 +352,7 @@ directory **on your provisioning machine**. Don't forget to replace
    # This inserts the configuration from .flux.env into your cluster as a "secret"
    kubectl apply -k $CLUSTER_DIR
 
-After you have executed that code, your terminal should show: 
+After you have executed that code, your terminal should show:
 
 .. code:: bash
 
@@ -372,10 +372,10 @@ After the script completes, you can install applications by running the other
 installation scripts in the ``install`` folder. At the moment, we have scripts
 to install:
 
-- Nextcloud and Onlyoffice with ``install-nextcloud.sh``
-- Rocket.Chat with ``install-rocketchat.sh``
-- WordPress with ``install-wordpress.sh``
-- Velero with ``install-velero.sh`` (only if you have configured it in
+- Nextcloud and Onlyoffice with ``install-app.sh nextcloud``
+- Rocket.Chat with ``install-app.sh rocketchat``
+- WordPress with ``install-app.sh wordpress``
+- Velero with ``install-app.sh velero`` (only if you have configured it in
   :ref:`backups-with-velero`).
 
 When the installation scripts complete, the application installation may still
diff --git a/install/install-app.sh b/install/install-app.sh
new file mode 100755
index 000000000..a3f7b47cf
--- /dev/null
+++ b/install/install-app.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+app=$1
+
+# shellcheck disable=SC1090
+. "$(dirname "$0")/flux-version-check.sh"
+
+# This kustomization's only purpose is to add the kustomization that is in the
+# flxu2/cluster/optional/$app folder. After this kustomization is applied
+# an `add-$app` kustomization will be present on the cluster, as well as a
+# `$app` kustomization that adds the actual app
+flux create kustomization "add-${app}" \
+  --source=GitRepository/openappstack \
+  --path="./flux2/cluster/optional/${app}" \
+  --prune=true \
+  --interval=1h
diff --git a/install/install-nextcloud.sh b/install/install-nextcloud.sh
deleted file mode 100755
index 8405a492b..000000000
--- a/install/install-nextcloud.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-. $(dirname "$0")/flux-version-check.sh
-
-# This kustomization's only purpose is to add the kustomization that is in the
-# flxu2/cluster/optional/nextcloud folder. After this kustomization is applied
-# an `add-nextcloud` kustomization will be present on the cluster, as well as a
-# `nextcloud` kustomization that adds the actual app
-flux create kustomization add-nextcloud \
-  --source=GitRepository/openappstack \
-  --path="./flux2/cluster/optional/nextcloud" \
-  --prune=true \
-  --interval=1h
diff --git a/install/install-rocketchat.sh b/install/install-rocketchat.sh
deleted file mode 100755
index 08270f138..000000000
--- a/install/install-rocketchat.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-. $(dirname "$0")/flux-version-check.sh
-
-# This kustomization's only purpose is to add the kustomization that is in the
-# flxu2/cluster/optional/rocketchat folder. After this kustomization is applied
-# an `add-rocketchat` kustomization will be present on the cluster, as well as a
-# `rocketchat` kustomization that adds the actual app
-flux create kustomization add-rocketchat \
-  --source=GitRepository/openappstack \
-  --path="./flux2/cluster/optional/rocketchat" \
-  --prune=true \
-  --interval=1h
diff --git a/install/install-velero.sh b/install/install-velero.sh
deleted file mode 100755
index e110c2a58..000000000
--- a/install/install-velero.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-. $(dirname "$0")/flux-version-check.sh
-
-# This kustomization's only purpose is to add the kustomization that is in the
-# flxu2/cluster/optional/velero folder. After this kustomization is applied
-# an `add-velero` kustomization will be present on the cluster, as well as a
-# `velero` kustomization that adds the actual app
-flux create kustomization add-velero \
-  --source=GitRepository/openappstack \
-  --path="./flux2/cluster/optional/velero" \
-  --prune=true \
-  --interval=1h
diff --git a/install/install-wordpress.sh b/install/install-wordpress.sh
deleted file mode 100755
index 32292a14c..000000000
--- a/install/install-wordpress.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-. $(dirname "$0")/flux-version-check.sh
-
-# This kustomization's only purpose is to add the kustomization that is in the
-# flxu2/cluster/optional/wordpress folder. After this kustomization is applied
-# an `add-wordpress` kustomization will be present on the cluster, as well as a
-# `wordpress` kustomization that adds the actual app
-flux create kustomization add-wordpress \
-  --source=GitRepository/openappstack \
-  --path="./flux2/cluster/optional/wordpress" \
-  --prune=true \
-  --interval=1h
-- 
GitLab