Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Added Azure site extension installation scripts #2448

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bcfb43a
wip extension scripts
svetlanabrennan Aug 9, 2024
d08187b
Add spec files
svetlanabrennan Aug 9, 2024
e4e18dc
Add version file
svetlanabrennan Aug 9, 2024
4f33dc3
update install script
svetlanabrennan Aug 19, 2024
60d40c2
refactor script and add update site extension version script
svetlanabrennan Aug 19, 2024
47cc522
Delete cloud-tooling/azure-site-extension/Content/.gitignore
svetlanabrennan Aug 19, 2024
52fb75c
Delete cloud-tooling/azure-site-extension/Content/NewRelic.Azure.Webs…
svetlanabrennan Aug 19, 2024
0a590e4
Delete cloud-tooling/azure-site-extension/Content/publish.sh
svetlanabrennan Aug 19, 2024
c599b6c
delete site extension and version files
svetlanabrennan Aug 19, 2024
247af7c
Remove application host files
svetlanabrennan Aug 19, 2024
0a6d499
delete gitignore and site extension file
svetlanabrennan Aug 19, 2024
9205318
fix lint
svetlanabrennan Aug 19, 2024
0db8d2f
refactor install scripts
svetlanabrennan Aug 21, 2024
8af6880
Add comments to install file
svetlanabrennan Aug 21, 2024
4e7b7db
update npm install in catch block
svetlanabrennan Aug 22, 2024
6528e56
Add readme to cloud tooling directory
svetlanabrennan Aug 22, 2024
899ffcc
Update cloud-tooling/README.md
svetlanabrennan Aug 22, 2024
4fbb5dd
Add testing to readme
svetlanabrennan Aug 23, 2024
f5e1b0c
Add another step to testing
svetlanabrennan Aug 23, 2024
b69583c
remove testing readme, update uninstall and refactor env vars in inst…
svetlanabrennan Aug 30, 2024
0286e8a
Update uninstall script to remove empty @ directories
svetlanabrennan Sep 3, 2024
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
54 changes: 54 additions & 0 deletions cloud-tooling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Node Agent Cloud Tooling

This repository contains various cloud based tools for the New Relic Node Agent (e.g. Azure Site Extensions).

## Getting Started
Please refer to the README of any of the cloud based tools:

- [Azure Site Extensions](./azure-site-extension/README.md)

## Support

Should you need assistance with New Relic products, you are in good hands with several support channels.

If the issue has been confirmed as a bug or is a feature request, please file a GitHub issue.

**Support Channels**

* [New Relic Documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/introduction-new-relic-nodejs): Comprehensive guidance for using our platform
* [New Relic Community](https://forum.newrelic.com/): The best place to engage in troubleshooting questions
* [New Relic Developer](https://developer.newrelic.com/): Resources for building a custom observability applications
* [New Relic University](https://learn.newrelic.com/): A range of online training for New Relic users of every level
* [New Relic Technical Support](https://support.newrelic.com/) 24/7/365 ticketed support. Read more about our [Technical Support Offerings](https://docs.newrelic.com/docs/licenses/license-information/general-usage-licenses/support-plan).


## Privacy
At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise.

We define “Personal Data” as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address and email address.

Please review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy) for more information.

## Contribute

We encourage your contributions to improve the Node.js agent! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.

If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.

**A note about vulnerabilities**

As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [our bug bounty program](https://docs.newrelic.com/docs/security/security-privacy/information-security/report-security-vulnerabilities/).

If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).

To [all contributors](https://github.com/newrelic/node-newrelic/graphs/contributors), we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to [New Relic Node Agent](https://opensource.newrelic.com/projects/newrelic/node-newrelic).

## License

Except as noted below, the Node.js agent is licensed under the [Apache 2.0](https://apache.org/licenses/LICENSE-2.0.txt) License.

The New Relic [security agent](https://github.com/newrelic/csec-node-agent) is licensed under the New Relic Software License v1.0. The New Relic security agent module may be integrated like the New Relic Node.js agent.

The Node.js agent also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in [the third-party notices document](https://github.com/newrelic/node-newrelic/blob/main/THIRD_PARTY_NOTICES.md).
9 changes: 9 additions & 0 deletions cloud-tooling/azure-site-extension/Content/install.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:: Copyright 2024 New Relic Corporation. All rights reserved.
:: SPDX-License-Identifier: Apache-2.0

@echo off
REM Call the PowerShell script
powershell.exe -ExecutionPolicy Bypass -File .\install.ps1

REM Echo the exit code
echo %ERRORLEVEL%
113 changes: 113 additions & 0 deletions cloud-tooling/azure-site-extension/Content/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Define paths
$extensionModulesPath = "$PSScriptRoot\node_modules"
$appRootPath = "$env:HOME\site\wwwroot"
$userModulesPath = "$appRootPath\node_modules"

# Define the path to the node_modules directory and the package to check
$UserNodeModulesPath = "$env:HOME"
$packageName = "newrelic"

WriteToInstallLog "Explicitly adding node to path"
$env:PATH = "C:\Program Files\Nodejs;" + $env:PATH

function WriteToInstallLog($output)
{
$logPath = (Split-Path -Parent $PSCommandPath) + "\install.log"
Write-Output "[$(Get-Date)] -- $output" | Out-File -FilePath $logPath -Append
}

function Check-Version {
WriteToInstallLog "Checking installed version..."

# Get installed version using npm list
$installedVersionOutput = & npm ls $packageName --prefix $UserNodeModulesPath | Select-String -Pattern "$packageName@(\S+)"

if ($installedVersionOutput) {
$UserVersion = $installedVersionOutput.Matches.Groups[1].Value
} else {
$UserVersion = ""
}

WriteToInstallLog "Installed version is: $installedVersionOutput"
WriteToInstallLog "User version: $UserVersion"

# Check if user package exists
if ($UserVersion -eq "") {
WriteToInstallLog "User package not found. Running install.ps1..."
Copy-NodeModules -sourcePath $extensionModulesPath -destinationPath $userModulesPath
exit $LASTEXITCODE
} else {
WriteToInstallLog "Installed version: $UserVersion"
WriteToInstallLog "Getting latest version from npm..."

$LatestVersion = npm show $packageName version
WriteToInstallLog "Latest version: $LatestVersion"

# Check if user package version matches the latest version
if ($UserVersion -ne $LatestVersion) {
WriteToInstallLog "Installed version ($UserVersion) does not match latest version ($LatestVersion). Running install.ps1..."
Copy-NodeModules -sourcePath $extensionModulesPath -destinationPath $userModulesPath
exit $LASTEXITCODE
} else {
WriteToInstallLog "Installed version ($UserVersion) matches the latest version ($LatestVersion). Skipping install.ps1..."
exit 0
}
}
}

# Function to move contents from extension's node_modules to user's node_modules
function Copy-NodeModules {
param (
[string]$sourcePath,
[string]$destinationPath
)

try {
WriteToInstallLog "Start executing install.ps1"

# Check if extension's node_module directory exists
if (Test-Path -Path $sourcePath) {
WriteToInstallLog "Source path exists: $sourcePath"

# Check if user's node_modules directory exists and create if it doesn't
if (-not (Test-Path -Path $destinationPath)) {
WriteToInstallLog "Destination path does not exist: $destinationPath"
WriteToInstallLog "Creating destination directory..."
WriteToInstallLog -ItemType Directory -Path $destinationPath
}

# Move node_modules from extension's node_modules directory to users
WriteToInstallLog "Moving node_modules from $sourcePath to $destinationPath..."
Move-Item -Path "$sourcePath\*" -Destination $destinationPath -Force

WriteToInstallLog "Copy complete."
WriteToInstallLog "End executing install.ps1."
WriteToInstallLog "-----------------------------"
exit $LASTEXITCODE
} else {
WriteToInstallLog "Source path does not exist: $sourcePath. Skipping copy."
}
} catch {
$errorMessage = $_.Exception.Message
$errorLine = $_.InvocationInfo.ScriptLineNumber
WriteToInstallLog "Error at line $errorLine : $errorMessage"

# Install node agent using npm
WriteToInstallLog "Executing npm install newrelic@latest"
npm install --prefix "$env:HOME\site\wwwroot" newrelic

# Check if the installation was successful
if ($LASTEXITCODE -ne 0) {
WriteToInstallLog "npm install failed with exit code $LASTEXITCODE"
} else {
WriteToInstallLog "npm install completed successfully"
}

WriteToInstallLog "End executing install.ps1."
WriteToInstallLog "-----------------------------"
exit 1
}
}

# Call the function
Check-Version
7 changes: 7 additions & 0 deletions cloud-tooling/azure-site-extension/Content/uninstall.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:: Copyright 2024 New Relic Corporation. All rights reserved.
:: SPDX-License-Identifier: Apache-2.0

SET NEW_RELIC_FOLDER="%HOME%\node_modules/newrelic"
IF EXIST %NEW_RELIC_FOLDER% (
npm uninstall newrelic
)