Skip to content

Commit

Permalink
Merge pull request #124 from aldbr/main_FEAT_npm-workspaces
Browse files Browse the repository at this point in the history
feat(diracx-web): support npm workspaces
  • Loading branch information
chrisburr authored Dec 5, 2024
2 parents 3ea5eeb + c54754b commit 83688ba
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ Note that this configuration is trivial and does not follow production recommand
| developer.enabled | bool | `true` | |
| developer.ipAlias | string | `nil` | The IP that the demo is running at |
| developer.localCSPath | string | `"/local_cs_store"` | If set, mount the CS stored localy instead of initializing a default one |
| developer.mountedNodeModuleToInstall | string | `nil` | List of node modules to install |
| developer.mountedNodeModuleToInstall | string | `nil` | Node module to install |
| developer.mountedPythonModulesToInstall | list | `[]` | List of packages which are mounted into developer.sourcePath and should be installed with pip install SOURCEPATH/... |
| developer.nodeImage | string | `"node:alpine"` | Image to use for the webapp if nodeModuleToInstall is set |
| developer.nodeWorkspacesDirectories | list | `[]` | List of node workspace directories to manage in the diracx-web container (node_modules) |
| developer.offline | bool | `false` | Make it possible to launch the demo without having an internet connection |
| developer.sourcePath | string | `"/diracx_source"` | Path from which to mount source of DIRACX |
| developer.urls | object | `{}` | URLs which can be used to access various components of the demo (diracx, minio, dex, etc). They are used by the diracx tests |
Expand Down
1 change: 1 addition & 0 deletions demo/values.tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ developer:
mountedPythonModulesToInstall: {{ mounted_python_modules }}
editableMountedPythonModules: {{ editable_mounted_modules }}
mountedNodeModuleToInstall: {{ node_module_to_mount }}
nodeWorkspacesDirectories: {{ node_module_workspaces }}

diracx:
hostname: {{ hostname }}
Expand Down
23 changes: 15 additions & 8 deletions diracx/templates/diracx-web/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ spec:
- name: diracx-web-code-mount
persistentVolumeClaim:
claimName: pvc-diracx-code
# These volumes override the node_modules and .next directories to
# These volumes override the node_modules directories to
# start from a clean state
- name: diracx-web-scratch-node-modules
emptyDir:
sizeLimit: 2Gi
- name: diracx-web-scratch-next
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
emptyDir:
sizeLimit: 1Gi
sizeLimit: 2Gi
{{- end }}
{{- else }}
{{- if .Values.diracxWeb.branch }}
# This volume is used to clone the specified diracx-web repository branch
Expand Down Expand Up @@ -91,8 +93,10 @@ spec:
subPath: "{{ .Values.developer.mountedNodeModuleToInstall }}"
- mountPath: "{{ $nodeMountedModulePath }}/node_modules"
name: "diracx-web-scratch-node-modules"
- mountPath: "{{ $nodeMountedModulePath }}/.next"
name: "diracx-web-scratch-next"
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- mountPath: "{{ $nodeMountedModulePath }}/{{ $module }}/node_modules"
name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
{{- end }}
{{- else }}
# Install the diracx-web repository, specific branch
command: ["/bin/sh", "-c"]
Expand Down Expand Up @@ -136,7 +140,8 @@ spec:
{{- if $nodeDevInstall }}
# Start the node module in development mode
image: {{ .Values.developer.nodeImage }}
command: ["npm", "run", "dev", "--prefix", "{{ $nodeMountedModulePath }}"]
command: ["npm", "run", "dev"]
workingDir: "{{ $nodeMountedModulePath }}"
env:
- name: NEXT_TELEMETRY_DISABLED
value: "1"
Expand All @@ -148,8 +153,10 @@ spec:
subPath: "{{ .Values.developer.mountedNodeModuleToInstall }}"
- mountPath: "{{ $nodeMountedModulePath }}/node_modules"
name: "diracx-web-scratch-node-modules"
- mountPath: "{{ $nodeMountedModulePath }}/.next"
name: "diracx-web-scratch-next"
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- mountPath: "{{ $nodeMountedModulePath }}/{{ $module }}/node_modules"
name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
{{- end }}
{{- else }}
# Start the node module in production mode
image: {{ .Values.global.images.web.repository }}:{{ .Values.global.images.web.tag }}
Expand Down
4 changes: 3 additions & 1 deletion diracx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ developer:
# -- Use pip install -e for mountedPythonModulesToInstall
# This is used by the integration tests because editable install might behave differently
editableMountedPythonModules: true
# -- List of node modules to install
# -- Node module to install
mountedNodeModuleToInstall: null
# -- List of node workspace directories to manage in the diracx-web container (node_modules)
nodeWorkspacesDirectories: []
# -- Image to use for the webapp if nodeModuleToInstall is set
nodeImage: node:alpine
# -- Enable collection of coverage reports (intended for CI usage only)
Expand Down
34 changes: 30 additions & 4 deletions run_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ done
declare -a pkg_dirs=()
declare -a python_pkg_names=()
node_pkg_name=""
declare -a node_pkg_workspaces=()
declare -a diracx_and_extensions_pkgs=()

for src_dir in "$@"; do
Expand Down Expand Up @@ -313,9 +314,22 @@ if [ ${#python_pkg_names[@]} -gt 0 ]; then
printf "%b Found Python package directories for: %s\n" ${UNICORN_EMOJI} "${python_pkg_names[*]}"
fi
if [ "${node_pkg_name}" != "" ]; then
printf "%b Found Node package directories for: %s\n" ${UNICORN_EMOJI} "${node_pkg_name}"
# Ensure node_modules and .next exist, else create them, as volumes will be mounted there
mkdir -p "${node_pkg_name}"/node_modules "${node_pkg_name}"/.next
printf "%b Found Node package directory for: %s\n" ${UNICORN_EMOJI} "${node_pkg_name}"

pkg_json="${node_pkg_name}/package.json"

# Check for workspaces in the package.json
if [ "$(jq -e ".workspaces | type== \"array\"" "$pkg_json")" == "true" ]; then
readarray -t node_pkg_workspaces < <(jq -r ".workspaces[]" "$pkg_json")
node_pkg_workspaces=("${node_pkg_workspaces[@]}")
printf "%b Found Node package workspaces for: %s\n" ${UNICORN_EMOJI} "$(IFS=' '; echo "${node_pkg_workspaces[*]}")"
fi

# Ensure node_modules exist, else create them, as volumes will be mounted there
mkdir -p "${node_pkg_name}"/node_modules
for workspace in "${node_pkg_workspaces[@]}"; do
mkdir -p "${node_pkg_name}/${workspace}"/node_modules
done
fi

trap "cleanup" EXIT
Expand Down Expand Up @@ -489,8 +503,20 @@ json="${json%,}]"
sed "s#{{ mounted_python_modules }}#${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
# Add the node package and its workspaces
sed "s/{{ node_module_to_mount }}/${node_pkg_name}/g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml"
mv "${demo_dir}/values.yaml" "${demo_dir}/values.yaml.bak"

json="["
if [ ${#node_pkg_workspaces[@]} -gt 0 ]; then
for workspace in "${node_pkg_workspaces[@]}"; do
json+="\"$workspace\","
done
fi
json="${json%,}]"
printf "%b Node workspaces json: %s\n" ${UNICORN_EMOJI} "${json}"
sed "s#{{ node_module_workspaces }}#${json}#g" "${demo_dir}/values.yaml.bak" > "${demo_dir}/values.yaml"


# Final check
if grep '{{' "${demo_dir}/values.yaml"; then
Expand Down

0 comments on commit 83688ba

Please sign in to comment.