From 593af0754b287ffb07d296ad3f9b652727fd40c9 Mon Sep 17 00:00:00 2001 From: aldbr Date: Thu, 5 Oct 2023 10:00:31 +0200 Subject: [PATCH] feat: make diracx-web editable --- README.md | 3 +- demo/values.tpl.yaml | 3 +- diracx/templates/deployment.yaml | 10 ++--- .../diracx-container-entrypoint.yaml | 4 +- diracx/templates/web-deployment.yaml | 8 ++-- diracx/values.yaml | 3 +- run_demo.sh | 37 ++++++++++++++----- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3a3ff42..41e2f07 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ TODO | autoscaling.targetCPUUtilizationPercentage | int | `80` | | | developer.enableCoverage | bool | `false` | | | developer.enabled | bool | `true` | | -| developer.modulesToInstall | list | `[]` | | +| developer.nodeModuleToInstall | string | `nil` | | +| developer.pythonModulesToInstall | list | `[]` | | | developer.sourcePath | string | `"/diracx_source"` | | | developer.urls | object | `{}` | | | dex."https.enabled" | bool | `false` | | diff --git a/demo/values.tpl.yaml b/demo/values.tpl.yaml index 92c6e8c..53537a8 100644 --- a/demo/values.tpl.yaml +++ b/demo/values.tpl.yaml @@ -5,7 +5,8 @@ developer: minio: http://{{ hostname }}:32000 dex: http://{{ hostname }}:32002 demoDir: {{ demo_dir }} - modulesToInstall: {{ modules_to_mount }} + pythonModulesToInstall: {{ python_modules_to_mount }} + nodeModuleToInstall: {{ node_module_to_mount }} diracx: settings: diff --git a/diracx/templates/deployment.yaml b/diracx/templates/deployment.yaml index 406c363..62f2377 100644 --- a/diracx/templates/deployment.yaml +++ b/diracx/templates/deployment.yaml @@ -38,11 +38,11 @@ spec: emptyDir: sizeLimit: 5Mi {{- end }} - {{- if and .Values.developer.enabled .Values.developer.modulesToInstall }} + {{- if and .Values.developer.enabled .Values.developer.pythonModulesToInstall }} - name: diracx-code-mount persistentVolumeClaim: claimName: pvc-diracx-code - {{- range $module := .Values.developer.modulesToInstall }} + {{- range $module := .Values.developer.pythonModulesToInstall }} - name: {{ lower $module }}-editable-install empty-dir: sizeLimit: 5Mi @@ -69,9 +69,9 @@ spec: {{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/diracx-coveragerc" "name" "container-entrypoint" "subPath" "coveragerc") }} {{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/coverage-reports" "name" "coverage-data" "readOnly" false) }} {{- end }} - {{- if and .Values.developer.enabled .Values.developer.modulesToInstall }} + {{- if and .Values.developer.enabled .Values.developer.pythonModulesToInstall }} {{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" .Values.developer.sourcePath "name" "diracx-code-mount" "readOnly" true) }} - {{- range $module := .Values.developer.modulesToInstall }} + {{- range $module := .Values.developer.pythonModulesToInstall }} {{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" (printf "%s/%s/src/%s.egg-info" $.Values.developer.sourcePath $module $module) "name" (printf "%s-editable-install" (lower $module)) "readOnly" false) }} {{- end }} {{- end }} @@ -164,7 +164,7 @@ spec: {{- if .Values.developer.enabled }} - "--reload" - "--proxy-headers" - {{- if .Values.developer.modulesToInstall }} + {{- if .Values.developer.pythonModulesToInstall }} - "--reload-dir={{ .Values.developer.sourcePath }}" {{- end }} {{- end }} diff --git a/diracx/templates/diracx-container-entrypoint.yaml b/diracx/templates/diracx-container-entrypoint.yaml index 13bb7e6..5ac7f8a 100644 --- a/diracx/templates/diracx-container-entrypoint.yaml +++ b/diracx/templates/diracx-container-entrypoint.yaml @@ -11,8 +11,8 @@ data: ulimit -n 8192 eval "$(micromamba shell hook --shell=posix)" && micromamba activate base - {{ if .Values.developer.modulesToInstall }} - pip install {{- range $moduleName := .Values.developer.modulesToInstall }} -e {{ $.Values.developer.sourcePath }}/{{ $moduleName }} {{- end }} + {{ if .Values.developer.pythonModulesToInstall }} + pip install {{- range $moduleName := .Values.developer.pythonModulesToInstall }} -e {{ $.Values.developer.sourcePath }}/{{ $moduleName }} {{- end }} {{- end }} {{- if and .Values.developer.enabled .Values.developer.enableCoverage }} diff --git a/diracx/templates/web-deployment.yaml b/diracx/templates/web-deployment.yaml index afd68eb..f7cd6e5 100644 --- a/diracx/templates/web-deployment.yaml +++ b/diracx/templates/web-deployment.yaml @@ -28,7 +28,7 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} volumes: - {{- if and .Values.developer.enabled }} + {{- if and .Values.developer.enabled .Values.developer.nodeModuleToInstall }} - name: diracx-web-code-mount persistentVolumeClaim: claimName: pvc-diracx-code @@ -53,10 +53,10 @@ spec: path: / port: http {{- if .Values.developer.enabled }} - command: ["npm", "run", "dev"] + command: ["npm", "run", "dev", "--prefix", {{ printf "%s/%s" $.Values.developer.sourcePath $.Values.developer.nodeModuleToInstall }}] volumeMounts: - - mountPath: /diracxweb_source - name: diracx-web-code-mount + - mountPath: {{ .Values.developer.sourcePath }} + name: "diracx-web-code-mount" readOnly: true {{- else }} command: ["npm", "start"] diff --git a/diracx/values.yaml b/diracx/values.yaml index dd34ad4..3187e4e 100644 --- a/diracx/values.yaml +++ b/diracx/values.yaml @@ -55,7 +55,8 @@ developer: urls: {} # Path from which to mount source of DIRACX sourcePath: /diracx_source - modulesToInstall: [] + pythonModulesToInstall: [] + nodeModuleToInstall: null enableCoverage: false # If set, mount the CS stored localy instead of initializing a default one # localCSPath: /local_cs_store diff --git a/run_demo.sh b/run_demo.sh index 79bd27d..6812c1d 100755 --- a/run_demo.sh +++ b/run_demo.sh @@ -123,17 +123,20 @@ done # Remaining arguments are positional parameters that are used to specify which # source directories to mount in the demo cluster declare -a pkg_dirs=() -declare -a pkg_names=() +declare -a python_pkg_names=() +node_pkg_name="" + for src_dir in "$@"; do pkg_dirs+=("${src_dir}") + # Python packages # shellcheck disable=SC2044 for pkg_dir in $(find "$src_dir/src" -mindepth 2 -maxdepth 2 -type f -name '__init__.py'); do pkg_name="$(basename "$(dirname "${pkg_dir}")")" # Check for the presence of $pkg_name in pkg_names array found=0 - if [ ${#pkg_names[@]} -gt 0 ]; then - for existing_pkg_name in "${pkg_names[@]}"; do + if [ ${#python_pkg_names[@]} -gt 0 ]; then + for existing_pkg_name in "${python_pkg_names[@]}"; do if [[ "$existing_pkg_name" == "$pkg_name" ]]; then found=1 break @@ -145,11 +148,19 @@ for src_dir in "$@"; do printf "%b Error: Source directory for %s was given twice!\n" "${SKULL_EMOJI}" "${pkg_name}" exit 1 fi - pkg_names+=("${pkg_name}") + python_pkg_names+=("${pkg_name}") + done + + # Node packages: we keep a single package, the last one found + # shellcheck disable=SC2044 + for pkg_json in $(find "$src_dir" -mindepth 1 -maxdepth 1 -type f -name 'package.json'); do + node_pkg_name=$(jq -r '.name' < "${pkg_json}") done done -if [ ${#pkg_names[@]} -gt 0 ]; then - printf "%b Found package directories for: %s\n" ${UNICORN_EMOJI} "${pkg_names[@]}" + +if [ ${#python_pkg_names[@]} -gt 0 ] || [ ${#node_pkg_name} != "" ]; then + pkg_names_joined=$(IFS=' '; echo "${python_pkg_names[*]} ${node_pkg_name}") + printf "%b Found package directories for: %s\n" ${UNICORN_EMOJI} "${pkg_names_joined}" else printf "%b No source directories were specified\n" ${UNICORN_EMOJI} fi @@ -236,14 +247,22 @@ sed "s/{{ hostname }}/${machine_hostname}/g" "${script_dir}/demo/values.tpl.yaml mv "${demo_dir}/values.yaml" "${demo_dir}/values.yaml.bak" sed "s@{{ demo_dir }}@${demo_dir}@g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml" mv "${demo_dir}/values.yaml" "${demo_dir}/values.yaml.bak" + +# Add python packages json="[" -if [ ${#pkg_names[@]} -gt 0 ]; then - for pkg_name in "${pkg_names[@]}"; do +if [ ${#python_pkg_names[@]} -gt 0 ]; then + for pkg_name in "${python_pkg_names[@]}"; do json+="\"$pkg_name\"," done fi json="${json%,}]" -sed "s/{{ modules_to_mount }}/${json}/g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml" +sed "s/{{ python_modules_to_mount }}/${json}/g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml" +mv "${demo_dir}/values.yaml" "${demo_dir}/values.yaml.bak" + +# Add the node package +sed "s/{{ node_module_to_mount }}/${node_pkg_name}/g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml" + +# Final check if grep '{{' "${demo_dir}/values.yaml"; then printf "%b Error generating template. Found {{ in the template result\n" ${SKULL_EMOJI} exit 1