Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate test suite to single-node Kubernetes infrastructure #73

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .devcontainer/devcontainer.json

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ servers/apache-php-7.4/tls
servers/apache-php-8.0/tls
servers/revad/tls
servers/ci/tls
charts
Chart.lock
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
135 changes: 135 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

. ./common.sh

# Kubernetes Dashboard admin-user token.
DASHBOARD_TOKEN=""

function build_push_images() {
(
echo "🐳 Building & publishing Docker images in Kubernetes registry"
(
./build-images.sh
) || (echo "❗️ Failed publish docker images.." && exit 1)
) | indent
}

function install_k8s_dashboard() {
(
echo "🖥️ Installing Kubernetes Dashboard"
(
kubectl get namespaces kubernetes-dashboard 2>&1 >/dev/null && echo "✅ Already installed." | indent && return ||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml | indent_cli &&
kubectl apply -f ./k8s/kubernetes-dashboard/dashboard-adminuser.yaml | indent_cli
) || (echo "❗️ Failed to install Kubernetes Dashboard. You can set this up later..." | indent)
) | indent

DASHBOARD_TOKEN=$(kubectl -n kubernetes-dashboard create token admin-user)
}

function install_k8s_ingress_controller() {
(
echo "🔀 Installing Nginx ingress controller"
(
helm -n ingress-nginx list | grep 'ingress-nginx' 2>&1 >/dev/null && echo "✅ Already installed." | indent && return ||
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
-n ingress-nginx --create-namespace 2>&1 >/dev/null && echo "✅ Ingress controller installed successfully" | indent
) || (echo "❌ Failed to set up ingress controller" && exit 1)
) | indent
}

function fetch_repositories() {
(
(
mkdir -p workspace/ &&
clone_repo https://github.com/pondersource/nc-sciencemesh workspace/nc-sciencemesh &&
clone_repo https://github.com/cs3org/reva workspace/revad master &&
clone_repo https://github.com/michielbdejong/ocm-stub workspace/ocm-stub
) || (echo "❌ Failed to set up repositories" && exit 1)
) | indent
}

function configure_helm() {
(
(
echo "📦 Configuring Helm Chart repositories" &&
helm_add owncloud https://owncloud-docker.github.io/helm-charts &&
helm_add nextcloud https://nextcloud.github.io/helm/ &&
helm_add cs3org https://cs3org.github.io/charts/ &&
helm_add bitnami https://charts.bitnami.com/bitnami &&
helm_add ingress-nginx https://kubernetes.github.io/ingress-nginx
) || (echo "❌ Failed to configure helm repositories" && exit 1)
) | indent
}

function is_installed() {
(
if [ -x "$(command -v "$1")" ]; then
echo "✅ $1 is properly installed"
else
echo "❌ Install $1 before running this script"
exit 1
fi
) | indent
}

echo
echo "🩻 Performing system checks"

is_installed docker
is_installed docker-compose
is_installed git
is_installed helm
is_installed kubectl

(
($docker ps 2>&1 >/dev/null && echo "✅ Docker is properly executable") ||
(echo "❌ Cannot run docker ps, you might need to check that your user is able to use docker properly" && exit 1)
) | indent

(
(kubectl version | grep 'Server Version:' 2>&1 >/dev/null && echo "✅ Kubernetes cluster is running properly") ||
(echo "❌ Kubernetes cluster is not running properly. Please refer e.g. to https://rancherdesktop.io on how to set-up a single-node Kubernetes cluster." && exit 1)
) | indent

echo
echo "🗄️ Setting up folder structure and fetching repositories"
fetch_repositories

echo
echo "☸️ Setting up Kubernetes environment"
build_push_images
configure_helm
ask "install k8s dashboard" install_k8s_dashboard
ask "install nginx ingress controller" install_k8s_ingress_controller

cat <<EOF

╔═════════════════════════════════════════╗
║ \O/ Ready to go! ║
╚═════════════════════════════════════════╝

🖥️ You can check status & manage all k8s services by navigating to:
NOTE: This applies only if you choose to install the k8s dashboard.
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

Use 'admin-user' password:
${DASHBOARD_TOKEN}

🔌 Start the ingress-controller port-forwarding proxy

$ ./ingress-proxy.sh

🚀 Pick and deploy a testing scenario

$ ./deploy.sh

🗑 Wipe all cluster deployments & namespaces

$ ./cleanup.sh

EOF
15 changes: 15 additions & 0 deletions build-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

. ./common.sh

find . -name build.sh -type f | while read -r build_file; do
build_dir="$(dirname "${build_file}")"
(
echo "🏗️ Building ${build_dir}" | indent &&
cd "${build_dir}" && ./build.sh . 2>&1 >/dev/null | indent_cli
)
done
23 changes: 0 additions & 23 deletions build.sh

This file was deleted.

38 changes: 38 additions & 0 deletions cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

SCENARIO_DIR=$1
TEST_DIR=./k8s/tests

scenarios=("$(find ${TEST_DIR} -name 'cleanup.sh' -type f -exec dirname {} \;)")

# If no cleanup.sh found, exit
if [ ${#scenarios[@]} -eq 0 ]; then
echo "🤷🏽‍♂️ No test scenarios found."
exit 1
fi

options=()
for d in $scenarios; do
options+=("$d ($(head -n 2 "$d/NOTES.txt" | tail -1))")
done

# Prompt user to select a directory
if [ -z "$SCENARIO_DIR" ]; then
echo "📝 Select a test scenario to uninstall:"
select opt in "${options[@]}"; do
if [[ "$REPLY" =~ ^[0-9]+$ ]]; then
dir=$(echo "$opt" | cut -d " " -f1)

echo
echo "🚀 Uninstalling test scenario" $(echo "$opt" | cut -d ' ' -f1)
break
else
echo "Invalid selection. Please try again."
fi
done
SCENARIO_DIR=$dir
fi

cd "$SCENARIO_DIR" && ./cleanup.sh && (
echo '✅ Unistalled successfully!'
) || echo '❌ Failed to uninstall'
69 changes: 69 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

docker=${DOCKER_PATH:-docker}

function indent() {
sed 's/^/ /'
}

function indent_cli() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -l 's/^/ > /'
else
sed -u 's/^/ > /'
fi
}

function helm_add() {
(
(helm repo add "$1" "$2" 2>&1 >/dev/null && echo "✅ $1 repo configured successfully") ||
(echo "❌ Failed to configure repo $1" && exit 1)
) | indent
}

function ask() {
read -r -p "❓ Do you want to ${1}? (y/n) " yn

case $yn in
[yY])
"${2}"
return
;;
[nN])
return
;;
*) echo invalid response ;;
esac
}

function is_installed() {
(
if [ -x "$(command -v "$1")" ]; then
echo "✅ $1 is properly installed"
else
echo "❌ Install $1 before running this script"
exit 1
fi
) | indent
}

function clone_repo() {
URL=$1
NAME=$2
BRANCH=${3:-main}

if [ -d "${NAME}" ]; then
echo "✅ Repository ${NAME} already present Pulling latest changes..."
(cd "$NAME" && git pull)
return
fi

echo "🌏 Fetching 𓆱 ${BRANCH} of ${NAME}"
(
git clone -b "${BRANCH}" "${URL}" "${NAME}" 2>&1 | indent_cli
) || (echo "❌ Failed to clone ${NAME}" | indent && exit 1)
}
44 changes: 44 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

SCENARIO_DIR=$1
TEST_DIR=./k8s/tests

scenarios=("$(find ${TEST_DIR} -name 'deploy.sh' -type f -exec dirname {} \;)")

# If no deploy.sh found, exit
if [ ${#scenarios[@]} -eq 0 ]; then
echo "🤷🏽‍♂️ No test scenarios found."
exit 1
fi

options=()
for d in $scenarios; do
options+=("$d ($(head -n 2 "$d/NOTES.txt" | tail -1))")
done

if [ -z "$SCENARIO_DIR" ]; then
# Prompt user to select a directory
echo "📝 Select a test scenario to deploy:"
select opt in "${options[@]}"; do
if [[ "$REPLY" =~ ^[0-9]+$ ]]; then
dir=$(echo "$opt" | cut -d " " -f1)

echo
echo "🚀 Deploying test scenario" $(echo "$opt" | cut -d ' ' -f1)
echo
break
else
echo "Invalid selection. Please try again."
fi
done

SCENARIO_DIR=$dir
fi

echo
shift
cd "$SCENARIO_DIR" && ./deploy.sh "$@" && (
echo '✅ Scenario successfully Deployed!' && (
test -f NOTES.txt && cat NOTES.txt || echo
)
) || echo '❌ Failed to deploy'
10 changes: 10 additions & 0 deletions ingress-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

INGRESS_NAMESPACE=${1:-ingress-nginx}
INGRESS_SERVICE=${2:-ingress-nginx-controller}

echo
echo "🔌 Proxying connections to ${INGRESS_NAMESPACE}/${INGRESS_SERVICE} ports 80, 443"
echo

kubectl port-forward --namespace="${INGRESS_NAMESPACE}" service/"${INGRESS_SERVICE}" 8080:80 8443:443
7 changes: 7 additions & 0 deletions k8s/central-component/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: central-component
description: Central Component services of the Science Mesh project.
type: application
version: 0.0.1
appVersion: 2.0.1
home: https://developer.sciencemesh.io/
Loading