Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux installer script: use --global=false for npm #4068

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/buildscripts/packaging/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ensure_not_installed() {
echo "Please uninstall auto instrumentation, or try running this script with the '--uninstall' option." >&2
exit 1
fi
if [ -n "$npm_path" ] && (cd $node_install_prefix && $npm_path ls @splunk/otel >/dev/null 2>&1); then
if [ -n "$npm_path" ] && (cd $node_install_prefix && $npm_path ls --global=false @splunk/otel >/dev/null 2>&1); then
echo "The @splunk/otel npm package is already installed in $node_install_prefix." >&2
echo "Please uninstall @splunk/otel, or try running this script with the '--uninstall' option." >&2
exit 1
Expand Down Expand Up @@ -568,9 +568,9 @@ install_node_package() {
fi

echo "Installing the Node.js Auto Instrumentation package ..."
mkdir -p $node_install_prefix
echo "Running 'cd $node_install_prefix && $npm_path install $node_package_path':"
(cd $node_install_prefix && $npm_path install $node_package_path)
mkdir -p ${node_install_prefix}/node_modules
echo "Running 'cd $node_install_prefix && $npm_path install --global=false $node_package_path':"
(cd $node_install_prefix && $npm_path install --global=false $node_package_path)
}

create_zeroconfig_node() {
Expand Down Expand Up @@ -788,8 +788,8 @@ uninstall() {
fi
done

if command -v npm >/dev/null 2>&1 && (cd $node_install_prefix && npm ls @splunk/otel >/dev/null 2>&1); then
(cd $node_install_prefix && npm uninstall @splunk/otel)
if command -v npm >/dev/null 2>&1 && (cd $node_install_prefix && npm ls --global=false @splunk/otel >/dev/null 2>&1); then
(cd $node_install_prefix && npm uninstall --global=false @splunk/otel)
echo "Successfully uninstalled the @splunk/otel npm package from $node_install_prefix"
fi
}
Expand Down
12 changes: 11 additions & 1 deletion internal/buildscripts/packaging/tests/installer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ def get_zc_method(container, distro, method):


def node_package_installed(container):
return container.exec_run(f"sh -l -c 'cd {NODE_PREFIX} && npm ls @splunk/otel'").exit_code == 0
cmd = f"sh -l -c 'cd {NODE_PREFIX} && npm ls --global=false @splunk/otel'"
print(f"Running '{cmd}':")
rc, output = container.exec_run(cmd)
print(output.decode("utf-8"))
return rc == 0


@pytest.mark.installer
Expand Down Expand Up @@ -378,6 +382,9 @@ def test_installer_with_instrumentation_default(distro, arch, method):
# downgrade npm to support python 3.5 in order to build/compile splunk-otel-js
run_container_cmd(container, "bash -l -c 'npm install --global npm@^6'")

# set global=true for npm to test that splunk-otel-js is still installed locally
run_container_cmd(container, "sh -l -c 'npm config set global true'")

install_cmd = " ".join((
get_installer_cmd(),
"--with-systemd-instrumentation" if method == "systemd" else "--with-instrumentation",
Expand Down Expand Up @@ -494,6 +501,9 @@ def test_installer_with_instrumentation_custom(distro, arch, method, sdk):
# downgrade npm to support python 3.5 in order to build/compile splunk-otel-js
run_container_cmd(container, "bash -l -c 'npm install --global npm@^6'")

# set global=true for npm to test that splunk-otel-js is still installed locally
run_container_cmd(container, "sh -l -c 'npm config set global true'")

service_name = f"service_name_from_{method}"
environment = f"deployment_environment_from_{method}"

Expand Down