Files
Kubernetes-Build/task
T

115 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
set -e
if [[ -a ".env" ]]; then
source .env
fi
function help() {
echo
echo "task <command> [options]"
echo
echo "commands:"
echo
# Define column widths
cmd_width=22
opt_width=10
desc_width=40
# Print table header
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "Command" "Option" "Description"
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
# Print table rows
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "dev-vitepress" "" "Start VitePress dev server."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "build-vitepress" "" "Build site with VitePress."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "preview-vitepress" "" "Server VitePress build."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "start-kind" "" "Start kind Kubernetes cluster."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "delete-kind" "" "Delete kind Kubernetes cluster."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "start-minikube" "" "Start minikube Kubernetes cluster."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "apply-odoo" "" "Apply the Odoo K8s manifests."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "forward-odoo" "" "Forward Odoo port."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "test-k8s" "" "Test Kubernetes environment."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "install" "" "Setup the local environment."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "version" "" "Show version of required tools."
echo
}
function dev-vitepress() {
pnpm run docs:dev
}
function build-vitepress() {
pnpm run docs:build
}
function preview-vitepress() {
pnpm run docs:preview
}
function start-kind() {
echo "Start kind."
kind create cluster
}
function delete-kind() {
echo "Delete kind."
kind delete cluster
}
function start-minikube() {
echo "Start minikube."
minikube start
}
function apply-odoo() {
echo "Deploy Postgres:"
kubectl apply -f odoo/postgres-cm.yaml
kubectl apply -f odoo/postgres-pvc.yaml
kubectl apply -f odoo/postgres-deploy.yaml
kubectl apply -f odoo/postgres-svc.yaml
echo -e "\nDeploy Odoo:"
kubectl apply -f odoo/odoo-cm.yaml
kubectl apply -f odoo/odoo-deploy.yaml
kubectl apply -f odoo/odoo-svc.yaml
echo -e "\nWait until resources are ready."
sleep 8
ODOO_POD=$(kubectl get pods -o=name --all-namespaces | grep odoo)
POSTGRES_POD=$(kubectl get pods -o=name --all-namespaces | grep postgres)
echo -e "\nWait for $ODOO_POD and $POSTGRES_POD pods to be running:"
kubectl wait --for=condition=Ready "$ODOO_POD" "$POSTGRES_POD" --timeout=60s
}
function test-k8s() {
start-kind
apply-odoo
}
function version() {
minikube version
kind version
}
function forward-odoo() {
echo "Open http://localhost:8069 url in your browser."
kubectl port-forward service/odoo 8069:8069
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
*)
echo "Unknown command: $1"
help
exit 1
;;
esac
fi