From 6bfe8ecb795df7bbd24fc2b7556831bc37db91ce Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Fri, 7 Mar 2025 14:22:06 +0100 Subject: [PATCH] feat(helm): init --- .github/workflows/test.yml | 3 +- .gitignore | 4 +- .helmignore | 15 +++ Chart.yaml | 14 +++ odoo/odoo-cm.yaml | 16 --- odoo/postgres-cm.yaml | 11 -- task | 129 ++++++++++++++++++++--- templates/odoo-cm.yaml | 17 +++ {odoo => templates}/odoo-deploy.yaml | 3 +- {odoo => templates}/odoo-svc.yaml | 3 +- templates/postgres-cm.yaml | 12 +++ {odoo => templates}/postgres-deploy.yaml | 3 +- {odoo => templates}/postgres-pvc.yaml | 2 +- {odoo => templates}/postgres-svc.yaml | 3 +- values.yaml | 16 +++ 15 files changed, 201 insertions(+), 50 deletions(-) create mode 100644 .helmignore create mode 100644 Chart.yaml delete mode 100644 odoo/odoo-cm.yaml delete mode 100644 odoo/postgres-cm.yaml create mode 100644 templates/odoo-cm.yaml rename {odoo => templates}/odoo-deploy.yaml (96%) rename {odoo => templates}/odoo-svc.yaml (83%) create mode 100644 templates/postgres-cm.yaml rename {odoo => templates}/postgres-deploy.yaml (92%) rename {odoo => templates}/postgres-pvc.yaml (94%) rename {odoo => templates}/postgres-svc.yaml (89%) create mode 100644 values.yaml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5e1feb..4bf3213 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,4 +17,5 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v5 - name: Run task test-k8s - run: ./task test-k8s \ No newline at end of file + run: ./task test-k8s + diff --git a/.gitignore b/.gitignore index 1258eab..6ef58d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules .vitepress/dist -.vitepress/cache \ No newline at end of file +.vitepress/cache +tmp +manifest.yaml \ No newline at end of file diff --git a/.helmignore b/.helmignore new file mode 100644 index 0000000..0714e8e --- /dev/null +++ b/.helmignore @@ -0,0 +1,15 @@ +node_modules +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ \ No newline at end of file diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..1c68505 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: . +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.16.0" +templates: + - postgres-cm.yaml + - postgres-deploy.yaml + - odoo-cm.yaml + - postgres-svc.yaml + - odoo-svc.yaml + - odoo-deploy.yaml + - postgres-pvc.yaml diff --git a/odoo/odoo-cm.yaml b/odoo/odoo-cm.yaml deleted file mode 100644 index bb5cafd..0000000 --- a/odoo/odoo-cm.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: odoo-config - labels: - app: odoo -data: - PGHOST: postgres - PGUSER: odoo - PGPASSWORD: odoo - PROXY_MODE: "True" - ADDONS_GIT_REPOS: "https://github.com/Mint-System/Odoo-Apps-Server-Tools.git#16.0,https://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/postgres-cm.yaml b/odoo/postgres-cm.yaml deleted file mode 100644 index dd2398f..0000000 --- a/odoo/postgres-cm.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -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/task b/task index 98465ce..bc1e95d 100755 --- a/task +++ b/task @@ -14,10 +14,9 @@ function help() { # Define column widths CMD_WIDTH=20 - OPT_WIDTH=6 + OPT_WIDTH=14 DESC_WIDTH=36 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 ' ' '-')|" @@ -34,10 +33,21 @@ function help() { printf "$COLUMN" "test-k8s" "" "Test Kubernetes environment." printf "$COLUMN" "install" "" "Setup the local environment." printf "$COLUMN" "version" "" "Show version of required tools." + printf "$COLUMN" "update-with-llm" "[path][prompt]" "Update files with LLM prompt." echo } +# Env Commands + +function version() { + minikube version + kind version + helm version +} + +# Docs Commands + function dev-vitepress() { pnpm run docs:dev } @@ -50,6 +60,8 @@ function preview-vitepress() { pnpm run docs:preview } +# Kubernetes Commands + function start-kind() { echo "Start kind." kind create cluster @@ -66,16 +78,11 @@ function start-minikube() { } 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 "Template the manifest files." + helm template odoo . > manifest.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 "Apply manifest files." + kubectl apply -f manifest.yaml echo -e "\nWait until resources are ready." sleep 8 @@ -92,16 +99,106 @@ function test-k8s() { 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 } +# Helm Commands + +# LLM Commands + +function update-with-llm() { + if test -z "$1"; then + echo "\$1 is empty. Usage:"; + help | grep "${FUNCNAME[0]}" + exit 1; + fi + + # Get files from path + if [ -f "$1" ]; then + FILES="$1" + elif [ -d "$1" ]; then + FILES=$(find "$1" -type f \( -name "*.md" -o -name "*.yml" -o -name "*.yaml" -o -name "*.conf" -o -name "*.nginx" \) \ + | grep -vFf <(git -C "$1" ls-files --ignored --exclude-standard --others)) + else + echo "$1 is neither a file nor a directory." + exit 1 + fi + echo -e "Loaded these files into prompt:\n\n$FILES\n" + + # Prompt task description + if [ -z "$2" ]; then + read -p "Enter the task description: " TASK_DESCRIPTION + else + TASK_DESCRIPTION="$2" + fi + + # Prepare the files content for prompt + FILE_CONTENTS="" + for FILE in $FILES; do + FILE_CONTENTS+="<<<$FILE>>> +$(cat "$FILE") + +" + done + + # Define prompt content + mkdir -p tmp + PROMPT_FILE="tmp/llm_update" + echo -e "\nWrite prompt to $PROMPT_FILE." + cat << EOF > "$PROMPT_FILE" +Look at the code files below and do the following: + +$TASK_DESCRIPTION + +Output all files that you need to change in full again, including your changes. +In the same format as I provide the files below. Under no circumstances output any other text, +no additional infos, no code formatting chars. Only the code in the given format. + +Here are the files: + +$FILE_CONTENTS +EOF + + # Run the llm command + echo -e "Send prompt and wait for the response of the $LLM_MODEL LLM." + RESULT=$(cat "$PROMPT_FILE" | llm -m "$LLM_MODEL") + + # Check if result is empty + if [ -z "$RESULT" ]; then + echo "No response from the model. Exiting." + exit 1 + fi + + # Save the result to a file + RESULT_FILE="tmp/llm_update_result" + echo "$RESULT" > "$RESULT_FILE" + echo -e "Saved response to $RESULT_FILE.\n" + + # Show a preview of result file + less "$RESULT_FILE" + + # Ask for confirmation before updating files + read -p "Do you want to apply these updates to the files? (y/n): " CONFIRM + if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then + exit 0 + fi + + # Parse the response from the file and update the files directly + echo -e "Parsing the response and updating files...\n" + CURRENT_FILE="" + while IFS= read -r LINE; do + if [[ $LINE =~ ^"<<<"(.*)">>>" ]]; then + CURRENT_FILE="${BASH_REMATCH[1]}" + echo "Update file $CURRENT_FILE." + > "$CURRENT_FILE" + elif [[ -n $CURRENT_FILE ]]; then + echo "$LINE" >> "$CURRENT_FILE" + fi + done < "$RESULT_FILE" +} + if declare -f "$1" > /dev/null; then "$1" "${@:2}" else diff --git a/templates/odoo-cm.yaml b/templates/odoo-cm.yaml new file mode 100644 index 0000000..76690d4 --- /dev/null +++ b/templates/odoo-cm.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: odoo-config + labels: + app: odoo +data: + PGHOST: {{ .Values.odoo.pgHost | quote }} + PGUSER: {{ .Values.odoo.user | quote }} + PGPASSWORD: {{ .Values.odoo.password | quote }} + PROXY_MODE: {{ .Values.odoo.proxyMode | quote }} + ADDONS_GIT_REPOS: {{ .Values.odoo.addonsGitRepos | quote }} + ODOO_DATABASE: {{ .Values.odoo.database | quote }} + ODOO_INIT: {{ .Values.odoo.init | quote }} + ODOO_INIT_LANG: {{ .Values.odoo.initLang | quote }} + diff --git a/odoo/odoo-deploy.yaml b/templates/odoo-deploy.yaml similarity index 96% rename from odoo/odoo-deploy.yaml rename to templates/odoo-deploy.yaml index a7fbec0..6475552 100644 --- a/odoo/odoo-deploy.yaml +++ b/templates/odoo-deploy.yaml @@ -38,4 +38,5 @@ spec: - containerPort: 8069 envFrom: - configMapRef: - name: odoo-config \ No newline at end of file + name: odoo-config + diff --git a/odoo/odoo-svc.yaml b/templates/odoo-svc.yaml similarity index 83% rename from odoo/odoo-svc.yaml rename to templates/odoo-svc.yaml index 2277bf7..53aa843 100644 --- a/odoo/odoo-svc.yaml +++ b/templates/odoo-svc.yaml @@ -8,4 +8,5 @@ spec: app: odoo ports: - port: 8069 - targetPort: 8069 \ No newline at end of file + targetPort: 8069 + diff --git a/templates/postgres-cm.yaml b/templates/postgres-cm.yaml new file mode 100644 index 0000000..ee471ec --- /dev/null +++ b/templates/postgres-cm.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config + labels: + app: postgres +data: + POSTGRES_DB: {{ .Values.postgres.db | quote }} + POSTGRES_USER: {{ .Values.postgres.user | quote }} + POSTGRES_PASSWORD: {{ .Values.postgres.password | quote }} + diff --git a/odoo/postgres-deploy.yaml b/templates/postgres-deploy.yaml similarity index 92% rename from odoo/postgres-deploy.yaml rename to templates/postgres-deploy.yaml index 9b6f620..dc3b5ff 100644 --- a/odoo/postgres-deploy.yaml +++ b/templates/postgres-deploy.yaml @@ -27,4 +27,5 @@ spec: volumes: - name: postgredb persistentVolumeClaim: - claimName: postgresql-data-claim \ No newline at end of file + claimName: postgresql-data-claim + diff --git a/odoo/postgres-pvc.yaml b/templates/postgres-pvc.yaml similarity index 94% rename from odoo/postgres-pvc.yaml rename to templates/postgres-pvc.yaml index 2869e22..a8f8882 100644 --- a/odoo/postgres-pvc.yaml +++ b/templates/postgres-pvc.yaml @@ -24,4 +24,4 @@ spec: accessModes: - ReadWriteMany hostPath: - path: "/data/volume" \ No newline at end of file + path: "/data/volume" diff --git a/odoo/postgres-svc.yaml b/templates/postgres-svc.yaml similarity index 89% rename from odoo/postgres-svc.yaml rename to templates/postgres-svc.yaml index 7d85d24..18cf504 100644 --- a/odoo/postgres-svc.yaml +++ b/templates/postgres-svc.yaml @@ -10,4 +10,5 @@ spec: - port: 5432 targetPort: 5432 selector: - app: postgres \ No newline at end of file + app: postgres + diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..66a1a48 --- /dev/null +++ b/values.yaml @@ -0,0 +1,16 @@ +replicaCount: 1 + +postgres: + db: odoo + user: odoo + password: odoo + +odoo: + pgHost: postgres + user: odoo + password: odoo + proxyMode: "True" + addonsGitRepos: "https://github.com/Mint-System/Odoo-Apps-Server-Tools.git#16.0,https://github.com/OCA/Server-Tools.git#16.0" + database: "odoo" + init: "True" + initLang: de_CH