Skip to content

Commit

Permalink
feat: make diracx-web editable
Browse files Browse the repository at this point in the history
  • Loading branch information
aldbr committed Oct 5, 2023
1 parent 7e588c7 commit 593af07
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | |
Expand Down
3 changes: 2 additions & 1 deletion demo/values.tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions diracx/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions diracx/templates/diracx-container-entrypoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
8 changes: 4 additions & 4 deletions diracx/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion diracx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 28 additions & 9 deletions run_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 593af07

Please sign in to comment.