From 7b6ce4f1bd868cd4fda984e6e1ab5911eff1b2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 12 Nov 2021 00:21:43 +0100 Subject: [PATCH] Preserve odoo-venv for faster startup --- src/runboat/kubefiles/deployment.yaml | 8 ++++---- src/runboat/kubefiles/initialize.yaml | 8 ++++---- src/runboat/kubefiles/kustomization.yaml.jinja | 4 ++-- src/runboat/kubefiles/pvc.yaml | 6 +++--- src/runboat/kubefiles/runboat-clone-and-install.sh | 14 ++++++++++++++ src/runboat/kubefiles/runboat-initialize.sh | 2 +- src/runboat/kubefiles/runboat-start.sh | 2 +- tests/test_render_kubefiles.py | 4 ++-- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/runboat/kubefiles/deployment.yaml b/src/runboat/kubefiles/deployment.yaml index 7e28f42..c583c53 100644 --- a/src/runboat/kubefiles/deployment.yaml +++ b/src/runboat/kubefiles/deployment.yaml @@ -23,8 +23,8 @@ spec: volumeMounts: - name: runboat-scripts mountPath: /runboat - - name: odoo-data - mountPath: /opt/odoo-data + - name: data + mountPath: /mnt/data envFrom: - secretRef: name: odoosecretenv @@ -47,6 +47,6 @@ spec: - name: runboat-scripts configMap: name: runboat-scripts - - name: odoo-data + - name: data persistentVolumeClaim: - claimName: odoo-data + claimName: data diff --git a/src/runboat/kubefiles/initialize.yaml b/src/runboat/kubefiles/initialize.yaml index a263f02..b060d9f 100644 --- a/src/runboat/kubefiles/initialize.yaml +++ b/src/runboat/kubefiles/initialize.yaml @@ -16,8 +16,8 @@ spec: volumeMounts: - name: runboat-scripts mountPath: /runboat - - name: odoo-data - mountPath: /opt/odoo-data + - name: data + mountPath: /mnt/data envFrom: - secretRef: name: odoosecretenv @@ -35,9 +35,9 @@ spec: - name: runboat-scripts configMap: name: runboat-scripts - - name: odoo-data + - name: data persistentVolumeClaim: - claimName: odoo-data + claimName: data restartPolicy: Never backoffLimit: 0 activeDeadlineSeconds: 1200 diff --git a/src/runboat/kubefiles/kustomization.yaml.jinja b/src/runboat/kubefiles/kustomization.yaml.jinja index 86d5c09..2775891 100644 --- a/src/runboat/kubefiles/kustomization.yaml.jinja +++ b/src/runboat/kubefiles/kustomization.yaml.jinja @@ -40,7 +40,7 @@ configMapGenerator: - name: odooenv literals: - PGDATABASE={{ build_name }} - - ADDONS_DIR=/build + - ADDONS_DIR=/mnt/data/odoo-data-dir - RUNBOAT_GIT_REPO=https://github.com/{{ repo }} - RUNBOAT_GIT_REF={{ git_commit }} {%- for key, value in build_env.items() %} @@ -59,7 +59,7 @@ generatorOptions: patches: - target: kind: PersistentVolumeClaim - name: odoo-data + name: data patch: |- - op: replace path: /spec/storageClassName diff --git a/src/runboat/kubefiles/pvc.yaml b/src/runboat/kubefiles/pvc.yaml index f78b347..e851063 100644 --- a/src/runboat/kubefiles/pvc.yaml +++ b/src/runboat/kubefiles/pvc.yaml @@ -1,12 +1,12 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: odoo-data + name: data spec: accessModes: - ReadWriteOnce resources: requests: - storage: 10Mi + storage: 200Mi limits: - storage: 100Mi + storage: 250Mi diff --git a/src/runboat/kubefiles/runboat-clone-and-install.sh b/src/runboat/kubefiles/runboat-clone-and-install.sh index 3a0f66f..4c19b49 100755 --- a/src/runboat/kubefiles/runboat-clone-and-install.sh +++ b/src/runboat/kubefiles/runboat-clone-and-install.sh @@ -2,6 +2,15 @@ set -ex +DEBIAN_FRONTEND=noninteractive apt-get -yq install rsync + +# If it exists, copy the previously initialized venv. +if [ -f /mnt/data/initialized ] ; then + rsync -a --delete /mnt/data/odoo-venv/ /opt/odoo-venv + pip list + exit 0 +fi + # # Clone an addons repository at git reference in $ADDONS_DIR. # Run oca_install_addons on it. @@ -13,3 +22,8 @@ git fetch origin $RUNBOAT_GIT_REF:build git checkout build oca_install_addons + +# Keep a copy of the venv that we can re-use for shorter startup time. +rsync -a /opt/odoo-venv/ /mnt/data/odoo-venv + +touch /mnt/data/initialized diff --git a/src/runboat/kubefiles/runboat-initialize.sh b/src/runboat/kubefiles/runboat-initialize.sh index 2dac4df..54cf098 100755 --- a/src/runboat/kubefiles/runboat-initialize.sh +++ b/src/runboat/kubefiles/runboat-initialize.sh @@ -16,7 +16,7 @@ dropdb --if-exists $PGDATABASE ADDONS=$(addons --addons-dir ${ADDONS_DIR} --include "${INCLUDE}" --exclude "${EXCLUDE}" list) unbuffer $(which odoo || which openerp-server) \ - --data-dir=/opt/odoo-data \ + --data-dir=/mnt/data/odoo-data-dir \ -d ${PGDATABASE} \ -i ${ADDONS:-base} \ --stop-after-init diff --git a/src/runboat/kubefiles/runboat-start.sh b/src/runboat/kubefiles/runboat-start.sh index 0864385..35d58fd 100755 --- a/src/runboat/kubefiles/runboat-start.sh +++ b/src/runboat/kubefiles/runboat-start.sh @@ -11,6 +11,6 @@ bash /runboat/runboat-clone-and-install.sh oca_wait_for_postgres unbuffer $(which odoo || which openerp-server) \ - --data-dir=/opt/odoo-data \ + --data-dir=/mnt/data/odoo-data-dir \ --no-database-list \ -d ${PGDATABASE} diff --git a/tests/test_render_kubefiles.py b/tests/test_render_kubefiles.py index 855e9a9..a150afb 100644 --- a/tests/test_render_kubefiles.py +++ b/tests/test_render_kubefiles.py @@ -34,7 +34,7 @@ configMapGenerator: - name: odooenv literals: - PGDATABASE=build-name - - ADDONS_DIR=/build + - ADDONS_DIR=/mnt/data/odoo-data-dir - RUNBOAT_GIT_REPO=https://github.com/oca/mis-builder - RUNBOAT_GIT_REF=abcdef123456789 - name: runboat-scripts @@ -50,7 +50,7 @@ generatorOptions: patches: - target: kind: PersistentVolumeClaim - name: odoo-data + name: data patch: |- - op: replace path: /spec/storageClassName