522 lines
16 KiB
Bash
Executable File
522 lines
16 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=26
|
|
OPT_WIDTH=14
|
|
DESC_WIDTH=50
|
|
COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n"
|
|
# Print table header
|
|
printf "$COLUMN" "Command" "Option" "Description"
|
|
echo "|$(printf '%*s' $((CMD_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((OPT_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((DESC_WIDTH + 2)) '' | tr ' ' '-')|"
|
|
|
|
# Env
|
|
printf "$COLUMN" "version" "" "Show version of required tools."
|
|
printf "$COLUMN" "template-dotenv" "" "Generate .env from .env.template."
|
|
printf "$COLUMN" "test-k8s" "[clean]" "Test Kubernetes environment."
|
|
printf "$COLUMN" "load-kubeconfig" "" "Load kubeconfig file from pass."
|
|
printf "$COLUMN" "load-dotenv" "" "Restore content to .env from pass entry."
|
|
printf "$COLUMN" "save-kubeconfig" "" "Save kubeconfig file in pass."
|
|
printf "$COLUMN" "save-dotenv" "" "Store content of .env in pass entry."
|
|
# Docs
|
|
printf "$COLUMN" "install" "" "Install node dependencies."
|
|
printf "$COLUMN" "dev-vitepress" "" "Start VitePress dev server."
|
|
printf "$COLUMN" "build-vitepress" "" "Build site with VitePress."
|
|
printf "$COLUMN" "preview-vitepress" "" "Server VitePress build."
|
|
# Host
|
|
printf "$COLUMN" "start-kind" "" "Start kind Kubernetes cluster."
|
|
printf "$COLUMN" "delete-kind" "" "Delete kind Kubernetes cluster."
|
|
printf "$COLUMN" "start-minikube" "" "Start minikube Kubernetes cluster."
|
|
printf "$COLUMN" "add-repos" "" "Add the required Helm repos."
|
|
printf "$COLUMN" "setup-hosts" "" "Update hosts file."
|
|
printf "$COLUMN" "forward-odoo" "" "Forward odoo port."
|
|
printf "$COLUMN" "forward-ingress-nginx" "" "Forward ingress-nginx port."
|
|
printf "$COLUMN" "forward-haproxy-ingress" "" "Forward haproxy-ingress port."
|
|
# Chart, Release and Forwarding
|
|
printf "$COLUMN" "install-odoo" "[env]" "Install Odoo chart. Optionally set env."
|
|
printf "$COLUMN" "install-postgres" "" "Install Postgres chart."
|
|
printf "$COLUMN" "install-vshnpostgres" "" "Install vshnPostgres chart."
|
|
printf "$COLUMN" "install-cert-manager" "" "Install cert manager."
|
|
printf "$COLUMN" "install-ingress-nginx" "" "Install ingress nginx."
|
|
printf "$COLUMN" "install-haproxy-ingress" "" "Install haproxy ingress."
|
|
printf "$COLUMN" "upgrade-odoo" "[env]" "Upgrade Odoo chart release. Optionally set env."
|
|
printf "$COLUMN" "upgrade-cert-manager" "" "Upgrade cert manager release."
|
|
printf "$COLUMN" "upgrade-postgres" "" "Upgrade Postgres release."
|
|
printf "$COLUMN" "upgrade-vshnpostgres" "" "Upgrade Postgres release."
|
|
printf "$COLUMN" "uninstall-odoo" "" "Uninstall Odoo Helm release."
|
|
printf "$COLUMN" "uninstall-cert-manager" "" "Uninstall cert manager release."
|
|
printf "$COLUMN" "uninstall-ingress-nginx" "" "Install ingress nginx."
|
|
printf "$COLUMN" "uninstall-haproxy-ingress" "" "Install haproxy ingress."
|
|
# kubectl
|
|
printf "$COLUMN" "logs-odoo" "" "Show pod logs."
|
|
printf "$COLUMN" "logs-haproxy-ingress" "" "Show haproxy-ingress logs."
|
|
printf "$COLUMN" "logs-ingress-nginx" "" "Show ingress-nginx logs."
|
|
printf "$COLUMN" "list" "" "List Helm deployments."
|
|
printf "$COLUMN" "list-pods" "" "List all pods."
|
|
printf "$COLUMN" "login-oc" "" "Refresh the auth token for OpenShift."
|
|
# Helm
|
|
printf "$COLUMN" "template" "[env]" "Template all charts with Helm."
|
|
printf "$COLUMN" "package-repo" "" "Package Helm charts."
|
|
printf "$COLUMN" "index-repo" "" "Index Helm chart."
|
|
printf "$COLUMN" "publish-repo" "" "Copy Helm chart files to dist."
|
|
printf "$COLUMN" "remove-repo" "" "Remove the kubernetes-build repo."
|
|
printf "$COLUMN" "install-repo" "[name]" "Install chart from kubernetes-build repo."
|
|
# LLM
|
|
printf "$COLUMN" "commit-with-llm" "" "Commit with llm generated commit message."
|
|
printf "$COLUMN" "update-with-llm" "[glob][prompt]" "Feed files matching glob to LLM and apply changes."
|
|
}
|
|
|
|
# Default vars
|
|
|
|
OC_PROJECT=${OC_PROJECT:="odoo"}
|
|
NAMESPACE=${NAMESPACE:="odoo"}
|
|
RELEASE_NAME=${RELEASE_NAME:="odoo"}
|
|
|
|
# Dynamic vars
|
|
|
|
PASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]')
|
|
PASS_KUBECONFIG_ENTRY=$(echo "env/kubeconfig_$USER" | tr '[:upper:]' '[:lower:]')
|
|
|
|
# Import commands
|
|
|
|
function clone-taskfile(){
|
|
if [ ! -d "$HOME/taskfile.build" ]; then
|
|
echo -e "\033[38;5;214mGit\033[0m: Clone taskfile repo"
|
|
git clone https://git.taskfile.build "$HOME/taskfile.build"
|
|
else
|
|
echo -e "\033[38;5;214mGit\033[0m: Pull taskfile repo"
|
|
git -C "$HOME/taskfile.build" pull
|
|
fi
|
|
}
|
|
|
|
if [ -d "$HOME/taskfile.build/bin" ]; then
|
|
for file in "$HOME/taskfile.build/bin/"*; do
|
|
if [ -f "$file" ]; then
|
|
source "$file"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Env Commands
|
|
|
|
function version() {
|
|
minikube version
|
|
kind version
|
|
helm version
|
|
}
|
|
|
|
function install() {
|
|
pnpm install
|
|
}
|
|
|
|
function setup-hosts() {
|
|
echo "Adding entries to /etc/hosts ..."
|
|
grep -qxF '127.0.0.1 cloud.local' /etc/hosts || echo "127.0.0.1 cloud.local" | sudo tee -a /etc/hosts > /dev/null
|
|
grep -qxF "127.0.0.1 $NAMESPACE.cloud.local" /etc/hosts || echo "127.0.0.1 $NAMESPACE.cloud.local" | sudo tee -a /etc/hosts > /dev/null
|
|
grep -qxF "127.0.0.1 $NAMESPACE.local" /etc/hosts || echo "127.0.0.1 $NAMESPACE.local" | sudo tee -a /etc/hosts > /dev/null
|
|
grep -qxF "127.0.0.1 restic.cloud.local" /etc/hosts || echo "127.0.0.1 restic.cloud.local" | sudo tee -a /etc/hosts > /dev/null
|
|
grep -qxF "127.0.0.1 restic.local" /etc/hosts || echo "127.0.0.1 restic.local" | sudo tee -a /etc/hosts > /dev/null
|
|
}
|
|
|
|
function test-k8s() {
|
|
if [ "$1" = "clean" ]; then
|
|
echo "Cleanup environment"
|
|
delete-kind
|
|
else
|
|
start-kind
|
|
add-repos
|
|
install-odoo
|
|
install-ingress-nginx
|
|
fi
|
|
}
|
|
|
|
function save-kubeconfig() {
|
|
if [ -f "$HOME/.kube/config" ]; then
|
|
echo "Store ~/.kube/config file in pass: $PASS_KUBECONFIG_ENTRY"
|
|
cat "$HOME/.kube/config" | pass insert -m -f "$PASS_KUBECONFIG_ENTRY"
|
|
else
|
|
echo "No ~/.kube/config file found."
|
|
fi
|
|
}
|
|
|
|
function load-kubeconfig() {
|
|
if pass find "$PASS_KUBECONFIG_ENTRY" >/dev/null; then
|
|
echo "Load ~/.kube/config file from pass: $PASS_KUBECONFIG_ENTRY"
|
|
mkdir -p "$HOME/.kube/"
|
|
pass show "$PASS_KUBECONFIG_ENTRY" > "$HOME/.kube/config"
|
|
else
|
|
echo "Pass entry not found."
|
|
fi
|
|
}
|
|
|
|
# Docs Commands
|
|
|
|
function dev-vitepress() {
|
|
cp README.md index.md
|
|
pnpm run docs:dev
|
|
}
|
|
|
|
function build-vitepress() {
|
|
cp README.md index.md
|
|
pnpm run docs:build
|
|
}
|
|
|
|
function preview-vitepress() {
|
|
pnpm run docs:preview
|
|
}
|
|
|
|
# Host Commands
|
|
|
|
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 forward-odoo() {
|
|
PORT=8080
|
|
echo "Open http://localhost:$PORT url in your browser."
|
|
kubectl port-forward service/odoo $PORT:8069
|
|
}
|
|
|
|
function forward-ingress-nginx() {
|
|
PORT=8080
|
|
echo "Open http://$NAMESPACE.cloud.local:$PORT or http://$NAMESPACE.local:$PORT url in your browser."
|
|
kubectl port-forward -n ingress-nginx svc/ingress-nginx-controller $PORT:80
|
|
}
|
|
|
|
function forward-haproxy-ingress() {
|
|
PORT=8080
|
|
echo "Open http://$NAMESPACE.cloud.local:$PORT or http://$NAMESPACE.local:$POR url in your browser."
|
|
kubectl port-forward -n haproxy-ingress svc/haproxy-ingress $PORT:80
|
|
}
|
|
|
|
# Helm, Release Commands
|
|
|
|
function install-postgres() {
|
|
echo "Install chart postgres as release $RELEASE_NAME."
|
|
helm install "$RELEASE_NAME" postgres \
|
|
--set postgres.client.enabled=true \
|
|
--set postgres.password="$POSTGRES_PASSWORD"
|
|
}
|
|
|
|
function install-odoo() {
|
|
if [ "$1" = "exo" ]; then
|
|
install-odoo-appuio
|
|
elif [ "$1" = "chk" ]; then
|
|
install-odoo-infomaniak
|
|
else
|
|
echo "Install dependencies."
|
|
helm dependency build odoo
|
|
echo "Install odoo chart as release $RELEASE_NAME."
|
|
helm install "$RELEASE_NAME" odoo \
|
|
--set postgres.password="$POSTGRES_PASSWORD"
|
|
sleep 8
|
|
|
|
echo "Get pods with name $1:"
|
|
kubectl get pods -o=name --all-namespaces | grep "odoo"
|
|
POD_ID=$(kubectl get pods -o=name --all-namespaces | grep "odoo")
|
|
|
|
echo -e "\nWait for $POD_ID pods to be running:"
|
|
kubectl wait --for=condition=Ready "$POD_ID" --timeout=120s
|
|
fi
|
|
}
|
|
|
|
function install-vshnpostgres() {
|
|
echo "Set oc project to $OC_PROJECT."
|
|
oc project "$OC_PROJECT"
|
|
|
|
echo "Install vshnPostgres chart as release odoo with APPUiO-specific values."
|
|
helm install "$RELEASE_NAME" vshnPostgres \
|
|
--set vshnPostgres.enabled=true \
|
|
--set vshnPostgres.client.enabled=true
|
|
}
|
|
|
|
function install-odoo-appuio() {
|
|
echo "Set oc project to $OC_PROJECT."
|
|
oc project "$OC_PROJECT"
|
|
|
|
echo "Install dependencies."
|
|
helm dependency build odoo
|
|
|
|
echo "Install odoo chart as release $RELEASE_NAME with APPUiO-specific values."
|
|
helm install "$RELEASE_NAME" odoo \
|
|
--set ingress.host="$NAMESPACE.exo.mintcloud.ch" \
|
|
--set ingress.className=haproxy \
|
|
--set ingress.secure=true \
|
|
--set vshnPostgres.enabled=true \
|
|
--set vshnPostgres.client.enabled=true \
|
|
--set postgres.enabled=false
|
|
}
|
|
|
|
function install-odoo-infomaniak() {
|
|
echo "Install dependencies."
|
|
helm dependency build odoo
|
|
|
|
echo "Install odoo chart as release $RELEASE_NAME with Infomaniak-specific values."
|
|
helm install "$RELEASE_NAME" odoo \
|
|
--set ingress.host="$NAMESPACE.chk.mintcloud.ch" \
|
|
--set ingress.className=nginx \
|
|
--set ingress.secure=true \
|
|
--set postgres.password="$POSTGRES_PASSWORD"
|
|
}
|
|
|
|
function upgrade-odoo() {
|
|
if [ "$1" = "exo" ]; then
|
|
upgrade-odoo-appuio
|
|
elif [ "$1" = "chk" ]; then
|
|
upgrade-odoo-infomaniak
|
|
else
|
|
echo "Update dependencies."
|
|
helm dependency update odoo
|
|
|
|
echo "Upgrade odoo chart for release $RELEASE_NAME."
|
|
helm upgrade "$RELEASE_NAME" odoo
|
|
fi
|
|
}
|
|
|
|
function upgrade-postgres() {
|
|
echo "Upgrade postgres chart for release $RELEASE_NAME."
|
|
helm upgrade "$RELEASE_NAME" postgres
|
|
}
|
|
|
|
function upgrade-vshnpostgres() {
|
|
echo "Upgrade vshnPostgres chart for release $RELEASE_NAME."
|
|
helm upgrade "$RELEASE_NAME" vshnPostgres \
|
|
--set vshnPostgres.enabled=true \
|
|
--set vshnPostgres.client.enabled=true \
|
|
--set postgres.password="$POSTGRES_PASSWORD"
|
|
}
|
|
|
|
function upgrade-odoo-appuio() {
|
|
echo "Upgrade odoo chart for release $RELEASE_NAME with APPUiO-specific values."
|
|
helm upgrade "$RELEASE_NAME" odoo \
|
|
--set ingress.host="$NAMESPACE.exo.mintcloud.ch" \
|
|
--set ingress.className=haproxy \
|
|
--set ingress.secure=true \
|
|
--set vshnPostgres.enabled=true \
|
|
--set vshnPostgres.client.enabled=true \
|
|
--set postgres.enabled=false
|
|
}
|
|
|
|
function upgrade-odoo-infomaniak() {
|
|
echo "Upgrade odoo chart for release $RELEASE_NAME with Infomaniak-specific values."
|
|
helm upgrade "$RELEASE_NAME" odoo \
|
|
--set ingress.host="$NAMESPACE.chk.mintcloud.ch" \
|
|
--set ingress.className=nginx \
|
|
--set ingress.secure=true \
|
|
--set postgres.password="$POSTGRES_PASSWORD"
|
|
}
|
|
|
|
function upgrade-cert-manager() {
|
|
echo "Upgrade jetstack/cert-manager."
|
|
helm upgrade \
|
|
cert-manager jetstack/cert-manager \
|
|
--namespace cert-manager \
|
|
--version v1.18.2 \
|
|
--set crds.enabled=true
|
|
|
|
echo "Upgrade cluster-issuer."
|
|
helm upgrade \
|
|
cluster-issuer cluster-issuer \
|
|
--namespace cert-manager \
|
|
--set acme.email=$ACME_EMAIL \
|
|
--set acme.infomaniakApiToken="$INFOMANIAK_API_TOKEN"
|
|
}
|
|
|
|
function install-ingress-nginx() {
|
|
echo "Install ingress-nginx/ingress-nginx."
|
|
helm install ingress-nginx ingress-nginx/ingress-nginx \
|
|
--create-namespace --namespace ingress-nginx
|
|
}
|
|
|
|
function install-cert-manager() {
|
|
echo "Install jetstack/cert-manager."
|
|
helm install \
|
|
cert-manager jetstack/cert-manager \
|
|
--namespace cert-manager \
|
|
--create-namespace \
|
|
--version v1.18.2 \
|
|
--set crds.enabled=true
|
|
|
|
echo "Install cluster-issuer."
|
|
helm install \
|
|
cluster-issuer cluster-issuer \
|
|
--namespace cert-manager \
|
|
--set acme.email="$ACME_EMAIL" \
|
|
--set acme.infomaniakApiToken="$INFOMANIAK_API_TOKEN"
|
|
}
|
|
|
|
function install-haproxy-ingress() {
|
|
echo "Install haproxy-ingress/haproxy-ingress."
|
|
|
|
kubectl apply -f - <<EOF
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: IngressClass
|
|
metadata:
|
|
name: haproxy
|
|
spec:
|
|
controller: haproxy-ingress.github.io/controller
|
|
EOF
|
|
|
|
helm install haproxy-ingress haproxy-ingress/haproxy-ingress \
|
|
--create-namespace --namespace haproxy-ingress
|
|
}
|
|
|
|
function uninstall-ingress-nginx() {
|
|
echo "Uninstall release ingress-nginx."
|
|
helm uninstall ingress-nginx --namespace ingress-nginx
|
|
}
|
|
|
|
function uninstall-haproxy-ingress() {
|
|
echo "Uninstall release haproxy-ingress."
|
|
helm uninstall haproxy-ingress --namespace haproxy-ingress
|
|
}
|
|
|
|
function uninstall-odoo() {
|
|
echo "Uninstall release $RELEASE_NAME."
|
|
helm uninstall "$RELEASE_NAME"
|
|
}
|
|
|
|
function uninstall-cert-manager() {
|
|
echo "Uninstall release cert-manager."
|
|
helm uninstall cert-manager --namespace cert-manager
|
|
|
|
echo "Uninstall release cluster-issuer."
|
|
helm uninstall cluster-issuer --namespace cert-manager
|
|
}
|
|
|
|
# kubectl Commands
|
|
|
|
function logs-odoo() {
|
|
POD_ID=$(kubectl get pods -o=name --all-namespaces | grep "odoo")
|
|
kubectl logs "$POD_ID"
|
|
}
|
|
|
|
function list-pods() {
|
|
kubectl get pods
|
|
}
|
|
|
|
function logs-haproxy-ingress() {
|
|
POD_ID=$(kubectl get pods -o=name -n haproxy-ingress | grep "haproxy-ingress")
|
|
kubectl logs "$POD_ID" -n haproxy-ingress
|
|
}
|
|
|
|
function logs-ingress-nginx() {
|
|
POD_ID=$(kubectl get pods -o=name -n ingress-nginx | grep "ingress-nginx")
|
|
kubectl logs "$POD_ID" -n ingress-nginx
|
|
}
|
|
|
|
# Helm Commands
|
|
|
|
function template() {
|
|
echo "Template charts into manifest.yaml."
|
|
if [ "$1" = "exo" ]; then
|
|
helm --debug template "$RELEASE_NAME" odoo \
|
|
--set ingress.host=$NAMESPACE.exo.mintcloud.ch \
|
|
--set ingress.className=haproxy \
|
|
--set ingress.secure=true \
|
|
--set vshnPostgres.enabled=true \
|
|
--set vshnPostgres.client.enabled=true \
|
|
--set postgres.enabled=false > manifest.yaml
|
|
elif [ "$1" = "chk" ]; then
|
|
helm --debug template "$RELEASE_NAME" odoo \
|
|
--set ingress.host="$NAMESPACE.chk.mintcloud.ch" \
|
|
--set ingress.className=nginx \
|
|
--set ingress.secure=true \
|
|
--set postgres.password="$POSTGRES_PASSWORD" > manifest.yaml
|
|
|
|
else
|
|
helm --debug template "$RELEASE_NAME" odoo \
|
|
--set postgres.password="$POSTGRES_PASSWORD" > manifest.yaml
|
|
fi
|
|
|
|
helm --debug template cluster-issuer cluster-issuer \
|
|
--namespace cert-manager \
|
|
--set acme.email="$ACME_EMAIL" \
|
|
--set acme.infomaniakApiToken="$INFOMANIAK_API_TOKEN" >> manifest.yaml
|
|
}
|
|
|
|
function list() {
|
|
helm list
|
|
}
|
|
|
|
function package-repo() {
|
|
echo "Package Helm charts."
|
|
index-repo
|
|
helm package cluster-issuer
|
|
helm package postgres
|
|
helm package vshnPostgres
|
|
mkdir -p ./odoo/charts
|
|
cp postgres-0.1.0.tgz odoo/charts/
|
|
cp vshnPostgres-0.1.0.tgz odoo/charts/
|
|
helm package odoo
|
|
}
|
|
|
|
function index-repo() {
|
|
echo "Update index.yaml"
|
|
helm repo index .
|
|
}
|
|
|
|
function publish-repo() {
|
|
build-vitepress
|
|
cp *.tgz .vitepress/dist
|
|
cp index.yaml .vitepress/dist
|
|
}
|
|
|
|
function add-repos(){
|
|
echo "Add the kubernetes-build repo."
|
|
helm repo add kubernetes-build https://kubernetes.build
|
|
|
|
echo "Add the ingress-nginx repo."
|
|
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
|
|
|
|
echo "Add the haproxy-ingress repo."
|
|
helm repo add haproxy-ingress https://haproxy-ingress.github.io/charts
|
|
|
|
echo "Add the jetstack repo."
|
|
helm repo add jetstack https://charts.jetstack.io
|
|
}
|
|
|
|
function remove-repo(){
|
|
echo "Remove the kubernetes-build repo."
|
|
helm repo remove kubernetes-build
|
|
}
|
|
|
|
function install-repo(){
|
|
echo "Install release odoo from kubernetes-build repo."
|
|
helm install odoo kubernetes-build/odoo
|
|
}
|
|
|
|
if declare -f "$1" > /dev/null; then
|
|
"$1" "${@:2}"
|
|
else
|
|
case "$1" in
|
|
*)
|
|
echo "Unknown command: $1"
|
|
help
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|