diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b5e1feb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +on: + pull_request: + branches: + - "main" + push: + branches: + - "main" + +jobs: + task-all: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Run task test-k8s + run: ./task test-k8s \ No newline at end of file diff --git a/README.md b/README.md index 28b95a5..144b19f 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,45 @@ The Mint System collection of Helm Charts. +* ☸️ **Kubernetes**: Deploy Odoo and Postgres to a local Kubernetes cluster. + ## Requirements -* Install [Helm](https://helm.sh/docs/intro/install/) +* Install [Helm](https://helm.sh/docs/intro/install/) and [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) +* Setup [kind](https://kind.sigs.k8s.io/) or [minikube](https://minikube.sigs.k8s.io/docs/) ## Usage -## Build +Install this Helm repository. -## Develop \ No newline at end of file +## Develop + +Run a local Kubernets cluster with kind or minikube. + +### Start Kubernetes Cluster + +Start Kubernetes with `kind`. + +```bash +task start-kind +``` + +Or start Kubernetes with `minikube`. + +```bash +task start-minikube +``` + +### Deploy Odoo to Kubernetes + +Ensure you have `kubectl` installed and can access the cluster. + +The following command applies the Odoo and Postgres manifests and initializes the Odoo database. + +```bash +task odoo-apply +``` + +### Release + +Create new release for this repository. diff --git a/odoo/odoo-cm.yaml b/odoo/odoo-cm.yaml new file mode 100644 index 0000000..9aef30c --- /dev/null +++ b/odoo/odoo-cm.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: odoo-config + labels: + app: odoo +data: + PGHOST: postgres + PGUSER: odoo + PGPASSWORD: odoo + PROXY_MODE: "True" + ADDONS_GIT_REPOS: "git@github.com:Mint-System/Odoo-Apps-Server-Tools.git#16.0,git@github.com:OCA/server-tools.git#16.0" + ODOO_DATABASE: "odoo" + ODOO_INIT: "True" + ODOO_INIT_LANG: de_CH \ No newline at end of file diff --git a/odoo/odoo-deploy.yaml b/odoo/odoo-deploy.yaml new file mode 100644 index 0000000..f94c0d3 --- /dev/null +++ b/odoo/odoo-deploy.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: odoo + labels: + app: odoo +spec: + replicas: 1 + selector: + matchLabels: + app: odoo + template: + metadata: + labels: + app: odoo + spec: + containers: + - name: odoo + image: mintsystem/odoo:16.0.20250207 + ports: + - containerPort: 8069 + envFrom: + - configMapRef: + name: odoo-config + initContainers: + - name: git-clone-addons + image: mintsystem/odoo:16.0.20250207 + command: ["git-clone-addons"] + envFrom: + - configMapRef: + name: odoo-config + - name: init-db + image: mintsystem/odoo:16.0.20250207 + command: ["init-db"] + envFrom: + - configMapRef: + name: odoo-config diff --git a/odoo/odoo-svc.yaml b/odoo/odoo-svc.yaml new file mode 100644 index 0000000..dd945d9 --- /dev/null +++ b/odoo/odoo-svc.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: odoo +spec: + type: NodePort + selector: + app: odoo + ports: + - protocol: TCP + port: 8069 + targetPort: 8069 + nodePort: 31945 \ No newline at end of file diff --git a/odoo/postgres-cm.yaml b/odoo/postgres-cm.yaml new file mode 100644 index 0000000..dd2398f --- /dev/null +++ b/odoo/postgres-cm.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config + labels: + app: postgres +data: + POSTGRES_DB: odoo + POSTGRES_USER: odoo + POSTGRES_PASSWORD: odoo \ No newline at end of file diff --git a/odoo/postgres-deploy.yaml b/odoo/postgres-deploy.yaml new file mode 100644 index 0000000..9b6f620 --- /dev/null +++ b/odoo/postgres-deploy.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:16 + ports: + - containerPort: 5432 + envFrom: + - configMapRef: + name: postgres-config + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgredb + volumes: + - name: postgredb + persistentVolumeClaim: + claimName: postgresql-data-claim \ No newline at end of file diff --git a/odoo/postgres-pvc.yaml b/odoo/postgres-pvc.yaml new file mode 100644 index 0000000..2869e22 --- /dev/null +++ b/odoo/postgres-pvc.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgresql-data-claim +spec: + storageClassName: manual + accessModes: + - ReadWriteMany + resources: + requests: + storage: 10Gi +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: postgresql-data + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 10Gi + accessModes: + - ReadWriteMany + hostPath: + path: "/data/volume" \ No newline at end of file diff --git a/odoo/postgres-svc.yaml b/odoo/postgres-svc.yaml new file mode 100644 index 0000000..ad19a08 --- /dev/null +++ b/odoo/postgres-svc.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres + labels: + app: postgres +spec: + type: NodePort + ports: + - port: 5432 + selector: + app: postgres \ No newline at end of file diff --git a/task b/task new file mode 100644 index 0000000..5c39a06 --- /dev/null +++ b/task @@ -0,0 +1,87 @@ +#!/bin/bash +set -e + +if [[ -a ".env" ]]; then + source .env +fi + +function help() { + echo + echo "task [options]" + echo + echo "commands:" + echo + + # Define column widths + cmd_width=10 + opt_width=6 + 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" "start-kind" "" "Start 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" "odoo-apply" "" "Apply the Odoo K8s manifests." + 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 start-kind() { + echo "Start kind." + kind create cluster +} + +function start-minikube() { + echo "Start minikube." + minikube start +} + +function odoo-apply() { + 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-odoo() { + start-kind + odoo-apply +} + +function version() { + minikube version + kind version +} + +if declare -f "$1" > /dev/null; then + "$1" "${@:2}" +else + case "$1" in + *) + echo "Unknown command: $1" + help + exit 1 + ;; + esac +fi \ No newline at end of file