Skip to content

Commit 2f52480

Browse files
mrickardnewrelic-node-agent-teamjsumners-nr
authored
test: Testing GHA for azure site extension (#12)
* docs: Updated compatibility report (newrelic#2440) Co-authored-by: jsumners-nr <[email protected]> * feat: Testing tooling available to windows runners Signed-off-by: mrickard <[email protected]> * feat: Added dotnet setup Signed-off-by: mrickard <[email protected]> * test: Added site extension files for workflow tests Signed-off-by: mrickard <[email protected]> * test: Added build and archive steps for GHA testing Signed-off-by: mrickard <[email protected]> --------- Signed-off-by: mrickard <[email protected]> Co-authored-by: Node Agent Bot <[email protected]> Co-authored-by: jsumners-nr <[email protected]>
1 parent 5d617de commit 2f52480

File tree

11 files changed

+284
-10
lines changed

11 files changed

+284
-10
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Azure Site Extension
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
# Enable versioned runner quiet mode to make CI output easier to read:
8+
OUTPUT_MODE: quiet
9+
SPEC_FILE_TEMPLATE: 'NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec'
10+
PACKAGE_FILENAME: ''
11+
SPEC_CONTENT: ''
12+
AGENT_VERSION: ''
13+
14+
jobs:
15+
setup_tools:
16+
runs-on: windows-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Setup dotnet '6.0.x'
21+
uses: actions/setup-dotnet@v3
22+
with:
23+
dotnet-version: '6.0.x'
24+
- name: Display dotnet version
25+
run: dotnet --version
26+
- name: Display NuGet version
27+
run: nuget --version
28+
29+
create_extension_bundle:
30+
runs-on: windows-latest
31+
needs:
32+
- setup_tools
33+
34+
strategy:
35+
matrix:
36+
node-version: ['18.x', '20.x']
37+
# Node 22 isn't yet available on Azure
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
- name: Use Node.js ${{ matrix.node-version }}
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: ${{ matrix.node-version }}
45+
- name: find_agent_version
46+
run: |
47+
npm view newrelic version >> ${{ env.AGENT_VERSION }}
48+
cd "cloud-tooling/azure-site-extension"
49+
echo Agent version: ${{ env.AGENT_VERSION }}
50+
echo "NewRelic.Azure.WebSites.Extension.NodeAgent.${{env.AGENT_VERSION}}.${{ matrix.node-version }}" >> ${{ env.PACKAGE_FILENAME }}
51+
- name: install_agent
52+
run: |
53+
cd Content
54+
npm i newrelic@${{ env.AGENT_VERSION }}
55+
- name: configure_package
56+
run: |
57+
cd ..
58+
(Get-Content ${{ env.SPEC_FILE_TEMPLATE }}).Replace('{VERSION}', ${{ env.AGENT_VERSION }}).Replace('{NODE_VERSION}', ${{ matrix.node-version }}) | Set-Content ${{ env.PACKAGE_FILENAME }}.nuspec
59+
# get-content ${{ env.SPEC_FILE_TEMPLATE }} | %{$_ -replace "{VERSION}","${{ env.AGENT_VERSION }}"} >> ${{NUSPEC_GENERATED}}
60+
61+
- name: pack
62+
run: nuget pack "${{ env.PACKAGE_FILENAME }}.nuspec" -OutputDirectory=./azure-site-extension/dist
63+
- name: Archive package for verification
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: azure-site-extension-test-${{ env.PACKAGE_FILENAME }}
67+
path: ./azure-site-extension/dist/
68+
69+
# - name: publish_package
70+
# run: |
71+
# NUGET_API_KEY=$1
72+
# NUGET_SOURCE=$2
73+
# dotnet nuget push "NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nupkg" --api-key ${NUGET_API_KEY} --source ${NUGET_SOURCE}
74+
#
75+
76+
77+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
3+
<system.webServer>
4+
<runtime xdt:Transform="InsertIfMissing" >
5+
<environmentVariables xdt:Transform="InsertIfMissing">
6+
<add name="NEW_RELIC_METADATA_AZURE_APP_SERVICE_NAME" xdt:Locator="Match(name)" xdt:Transform="RemoveAll"/>
7+
<add name="NEW_RELIC_METADATA_AZURE_APP_SERVICE_NAME" value="%WEBSITE_SITE_NAME%" xdt:Locator="Match(name)" xdt:Transform="Insert"/>
8+
</environmentVariables>
9+
</runtime>
10+
</system.webServer>
11+
</configuration>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:: Copyright 2022 New Relic Corporation. All rights reserved.
2+
:: SPDX-License-Identifier: Apache-2.0
3+
4+
@echo off
5+
6+
powershell.exe -ExecutionPolicy RemoteSigned -File install.ps1
7+
8+
echo %ERRORLEVEL%
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
############################################################
2+
# Copyright 2022 New Relic Corporation. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
############################################################
5+
6+
# Install.ps1
7+
#
8+
# This version uses npm install, which we're not going to want to do
9+
# in the released version
10+
11+
try {
12+
WriteToInstallLog "Start executing install.ps1"
13+
14+
# Selects the agent version
15+
$agentVersion = "latest"
16+
if ($env:NEWRELIC_AGENT_VERSION_OVERRIDE -ne $null) {
17+
$agentVersion = $env:NEWRELIC_AGENT_VERSION_OVERRIDE.ToString()
18+
WriteToInstallLog "Installing Node agent version $agentVersion"
19+
} else {
20+
WriteToInstallLog "Installing the latest Node agent"
21+
}
22+
23+
WriteToInstallLog "Executing npm install newrelic@latest"
24+
npm install newrelic@latest
25+
26+
WriteToInstallLog "End executing install.ps1."
27+
WriteToInstallLog "-----------------------------"
28+
exit $LASTEXITCODE
29+
}
30+
catch
31+
{
32+
$errorMessage = $_.Exception.Message
33+
$errorLine = $_.InvocationInfo.ScriptLineNumber
34+
WriteToInstallLog "Error at line $errorLine : $errorMessage"
35+
WriteToInstallLog "Explicitly adding node to path"
36+
SET PATH=C:\Program Files\Nodejs;%PATH%
37+
WriteToInstallLog "Executing npm install newrelic@latest"
38+
npm install newrelic@latest
39+
WriteToInstallLog "End executing install.ps1."
40+
WriteToInstallLog "-----------------------------"
41+
42+
exit $LASTEXITCODE
43+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:: Copyright 2022 New Relic Corporation. All rights reserved.
2+
:: SPDX-License-Identifier: Apache-2.0
3+
4+
SET NEW_RELIC_FOLDER="%HOME%\node_modules/newrelic"
5+
IF EXIST %NEW_RELIC_FOLDER% (
6+
npm uninstall newrelic
7+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<metadata>
4+
<id>NewRelic.Azure.WebSites.Extension.NodeAgent</id>
5+
<version>{VERSION}-{NODE_VERSION}</version>
6+
<title>New Relic Node Agent {VERSION} (Node.js {NODE_VERSION})</title>
7+
<authors>New Relic</authors>
8+
<license type="expression">Apache-2.0</license>
9+
<projectUrl>https://github.com/newrelic/node-newrelic</projectUrl>
10+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
11+
<description>This extension adds the New Relic Node Agent to your Azure WebSite.</description>
12+
<iconUrl>https://newrelic.com/static-assets/images/icons/avatar-newrelic.png</iconUrl>
13+
<icon>images\icon.png</icon>
14+
<copyright>New Relic, Inc., 2024</copyright>
15+
<tags>AzureSiteExtension</tags>
16+
<packageTypes>
17+
<packageType name="AzureSiteExtension" />
18+
</packageTypes>
19+
</metadata>
20+
<files>
21+
<file src="Content\**\*.*" target="content" />
22+
<file src="icon.png" target="images\" />
23+
</files>
24+
</package>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Azure Node Agent Site Extension
2+
3+
This project creates an Azure site extension that automatically installs the New Relic Node Agent. This extension is designed for JVM applications running on Azure Windows compute resources. The site extensions follow [semantic versioning conventions](https://semver.org/). You can expect to find artifacts in [Nuget](https://www.nuget.org/).
4+
5+
## Installation
6+
7+
This extension is designed for Node applications running on Azure Windows compute resources.
8+
9+
**Note:** Make sure that the target application is stopped prior to installing the extension.
10+
11+
From the Azure Home page, do the following:
12+
- Click the App Services tile
13+
- Click the name of the target application in the displayed list
14+
- On the options listed on the left, scroll down to "Extensions" located under the `Development Tools` category
15+
- Click on `+ Add` at the top of the page
16+
- From the extension drop down, select `New Relic Node Agent`
17+
- Click on the `Accept Legal Terms` link
18+
- Click `OK` on the bottom left of the page
19+
- Again, click `OK` on the bottom left of the page. This will begin installation of the extension
20+
21+
Once installed, the extension creates the following artifacts:
22+
- Folder: `C:\home\node_modules\newrelic` - Contains the Node agent artifacts
23+
- XDT: `applicationHost.xdt` that will add the necessary environment variable on application startup
24+
25+
If the extension fails to install, a log file is created at `C:\home\SiteExtensions\NewRelic.Azure.WebSites.Extension.NodeAgent\install.log`.
26+
27+
## Getting Started
28+
29+
Once the site extension is installed, you'll need to manually enter two configuration items before restarting your application:
30+
- On the options listed on the left, scroll down to "Configuration" located under the `Settings` category
31+
- On the configuration page, add the following two app settings:
32+
- `NEW_RELIC_LICENSE_KEY` - Your New Relic license key value
33+
- `NEW_RELIC_APP_NAME` - The name you wish your application to show up as in the New Relic Platform
34+
35+
You can also add any additional [app settings](https://docs.newrelic.com/docs/apm/agents/node-agent/configuration/node-agent-configuration-config-file/#Environment_Variables) to configure the agent as needed.
36+
37+
## Building
38+
39+
### Installing Dependencies (for MacOS and Linux)
40+
41+
- Download and install the latest version of [Mono](https://www.mono-project.com/download/stable/)
42+
- Download `nuget.exe`: `sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe`
43+
- Create an alias in your .bashrc or .zshrc for mono: `alias nuget="mono /usr/local/bin/nuget.exe"`
44+
- Download and install [.Net 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0). Using the installer will create a `dotnet` command that will be available when you restart your shell.
45+
- Restart your shell and execute `nuget` to verify your mono installation and `dotnet` to verify your .Net installation.
46+
47+
References:
48+
- https://www.wiliam.com.au/wiliam-blog/creating-a-nuget-package
49+
- https://learn.microsoft.com/en-au/nuget/install-nuget-client-tools#nugetexe-cli
50+
51+
### Publishing the Package
52+
53+
#### Publishing the Package with the Script (recommended)
54+
- Your nuget package version is hardcoded in `version.txt`, update the file to change the version number.
55+
- Run `./publish.sh <NUGET_API_KEY> <NUGET_SOURCE>`: this will create the NuGet package and upload to the target repository
56+
- The parameters for `publish.sh` are the following:
57+
- `NUGET_API_KEY` - API key for uploading artifacts to the target NuGet repository
58+
- `NUGET_SOURCE` - Target NuGet repository (https://api.nuget.org/v3/index.json is the main, public URL)
59+
60+
#### Manually publishing the Package
61+
62+
- Change into the folder where the `.nuget` file exists
63+
- Replace `{VERSION}` in `NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec` with a version number you want to push. (DO NOT COMMIT THIS CHANGE)
64+
- Execute: `nuget pack NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec`
65+
- This will create a package with the name: `NewRelic.Azure.WebSites.Extension.NodeAgent.VERSION.nupkg`
66+
- Execute: `dotnet nuget push NewRelic.Node.Azure.WebSites.Extension.nupkg --api-key NUGET_API_KEY --source NUGET_SOURCE` where `NUGET_API_KEY` is your NuGet API key and `NUGET_SOURCE` is the URL of the target NuGet site (https://api.nuget.org/v3/index.json is the main, public URL)
67+
68+
For testing the extension, it is best to publish to a personel [MyGet repository](https://www.myget.org/). There you can publish and release packages without worrying about pushing your extension out to the publix.
69+
70+
## Testing
71+
72+
It is recommended you use a personnel repository created in [MyGet](https://www.myget.org/).
73+
74+
Upload the nuget package then set up an app config variable in Azure:
75+
- `SCM_SITEEXTENSIONS_FEED_URL`: The URL to the private Nuget repository created when registering your myget.org account. For example: https://www.myget.org/F/username-nuget-test/api/v3/index.json
76+
77+
In Azure, when you browse to `Development Tools` > `Extensions`, you will see a list of Nuget packages in your private repository.
78+
79+
80+
## Extension Source Files
81+
82+
Below is a description of the files that make up the extension. This can be helpful for future maintenance on the extension or for the creation of another Site Extension.
83+
84+
- `README.md` - This file
85+
- `NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec` - Contains the metadata about the target extension: Name, authors, copyright, etc. [Nuspec Format](https://learn.microsoft.com/en-us/nuget/reference/nuspec)
86+
- `publish.sh` - Simple script to package the script and upload to the Nuget repository
87+
- `Content/applicationHost.xdt` - XDT transformation to add the necessary agent startup environment variable to the app config when the app starts up
88+
- `Content/install.cmd` - Simple batch file that wraps a call to the Powershell `install.ps1` script
89+
- `Content/install.ps1` - Powershell script that downloads the agent bundle and installs it to the proper location on the host
90+
- `Content/uninstall.cmd` - Simple batch file that will remove the Node installtion artifacts when the extension is removed
5.43 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is just a simple shell script that will later be
2+
# used as a template for a GHA job for
3+
# azure-site-extension site extension uploads.
4+
5+
# Dependencies: .Net 5 and up or .Net Core, Mono, and the Nuget CLI.
6+
NUGET_API_KEY=$1
7+
NUGET_SOURCE=$2
8+
VERSION=$(cat version.txt)
9+
NUSPEC_GENERATED="NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nuspec"
10+
sed "s/{VERSION}/${VERSION}/g" NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec > "${NUSPEC_GENERATED}"
11+
nuget pack "${NUSPEC_GENERATED}"
12+
dotnet nuget push "NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nupkg" --api-key ${NUGET_API_KEY} --source ${NUGET_SOURCE}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.0.0

0 commit comments

Comments
 (0)