Skip to content

Commit

Permalink
test: Testing GHA for azure site extension (#13)
Browse files Browse the repository at this point in the history
* 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]>

* fix: Fixed nuget test

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]>
  • Loading branch information
3 people authored Aug 13, 2024
1 parent 5d617de commit 676c580
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 10 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/azure-site-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Azure Site Extension

on:
workflow_dispatch:

env:
# Enable versioned runner quiet mode to make CI output easier to read:
OUTPUT_MODE: quiet
SPEC_FILE_TEMPLATE: 'NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec'
PACKAGE_FILENAME: ''
SPEC_CONTENT: ''
AGENT_VERSION: ''

jobs:
setup_tools:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Setup dotnet '6.0.x'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- name: Display dotnet version
run: dotnet --version
- name: Display NuGet version
run: nuget ?

create_extension_bundle:
runs-on: windows-latest
needs:
- setup_tools

strategy:
matrix:
node-version: ['18.x', '20.x']
# Node 22 isn't yet available on Azure

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: find_agent_version
run: |
npm view newrelic version >> ${{ env.AGENT_VERSION }}
cd "cloud-tooling/azure-site-extension"
echo Agent version: ${{ env.AGENT_VERSION }}
echo "NewRelic.Azure.WebSites.Extension.NodeAgent.${{env.AGENT_VERSION}}.${{ matrix.node-version }}" >> ${{ env.PACKAGE_FILENAME }}
- name: install_agent
run: |
cd Content
npm i newrelic@${{ env.AGENT_VERSION }}
- name: configure_package
run: |
cd ..
(Get-Content ${{ env.SPEC_FILE_TEMPLATE }}).Replace('{VERSION}', ${{ env.AGENT_VERSION }}).Replace('{NODE_VERSION}', ${{ matrix.node-version }}) | Set-Content ${{ env.PACKAGE_FILENAME }}.nuspec
# get-content ${{ env.SPEC_FILE_TEMPLATE }} | %{$_ -replace "{VERSION}","${{ env.AGENT_VERSION }}"} >> ${{NUSPEC_GENERATED}}

- name: pack
run: nuget pack "${{ env.PACKAGE_FILENAME }}.nuspec" -OutputDirectory=./azure-site-extension/dist
- name: Archive package for verification
uses: actions/upload-artifact@v4
with:
name: azure-site-extension-test-${{ env.PACKAGE_FILENAME }}
path: ./azure-site-extension/dist/

# - name: publish_package
# run: |
# NUGET_API_KEY=$1
# NUGET_SOURCE=$2
# dotnet nuget push "NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nupkg" --api-key ${NUGET_API_KEY} --source ${NUGET_SOURCE}
#



11 changes: 11 additions & 0 deletions cloud-tooling/azure-site-extension/Content/applicationHost.xdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing" >
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="NEW_RELIC_METADATA_AZURE_APP_SERVICE_NAME" xdt:Locator="Match(name)" xdt:Transform="RemoveAll"/>
<add name="NEW_RELIC_METADATA_AZURE_APP_SERVICE_NAME" value="%WEBSITE_SITE_NAME%" xdt:Locator="Match(name)" xdt:Transform="Insert"/>
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
8 changes: 8 additions & 0 deletions cloud-tooling/azure-site-extension/Content/install.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:: Copyright 2022 New Relic Corporation. All rights reserved.
:: SPDX-License-Identifier: Apache-2.0

@echo off

powershell.exe -ExecutionPolicy RemoteSigned -File install.ps1

echo %ERRORLEVEL%
43 changes: 43 additions & 0 deletions cloud-tooling/azure-site-extension/Content/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
############################################################
# Copyright 2022 New Relic Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
############################################################

# Install.ps1
#
# This version uses npm install, which we're not going to want to do
# in the released version

try {
WriteToInstallLog "Start executing install.ps1"

# Selects the agent version
$agentVersion = "latest"
if ($env:NEWRELIC_AGENT_VERSION_OVERRIDE -ne $null) {
$agentVersion = $env:NEWRELIC_AGENT_VERSION_OVERRIDE.ToString()
WriteToInstallLog "Installing Node agent version $agentVersion"
} else {
WriteToInstallLog "Installing the latest Node agent"
}

WriteToInstallLog "Executing npm install newrelic@latest"
npm install newrelic@latest

WriteToInstallLog "End executing install.ps1."
WriteToInstallLog "-----------------------------"
exit $LASTEXITCODE
}
catch
{
$errorMessage = $_.Exception.Message
$errorLine = $_.InvocationInfo.ScriptLineNumber
WriteToInstallLog "Error at line $errorLine : $errorMessage"
WriteToInstallLog "Explicitly adding node to path"
SET PATH=C:\Program Files\Nodejs;%PATH%
WriteToInstallLog "Executing npm install newrelic@latest"
npm install newrelic@latest
WriteToInstallLog "End executing install.ps1."
WriteToInstallLog "-----------------------------"

exit $LASTEXITCODE
}
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 2022 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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>NewRelic.Azure.WebSites.Extension.NodeAgent</id>
<version>{VERSION}-{NODE_VERSION}</version>
<title>New Relic Node Agent {VERSION} (Node.js {NODE_VERSION})</title>
<authors>New Relic</authors>
<license type="expression">Apache-2.0</license>
<projectUrl>https://github.com/newrelic/node-newrelic</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>This extension adds the New Relic Node Agent to your Azure WebSite.</description>
<iconUrl>https://newrelic.com/static-assets/images/icons/avatar-newrelic.png</iconUrl>
<icon>images\icon.png</icon>
<copyright>New Relic, Inc., 2024</copyright>
<tags>AzureSiteExtension</tags>
<packageTypes>
<packageType name="AzureSiteExtension" />
</packageTypes>
</metadata>
<files>
<file src="Content\**\*.*" target="content" />
<file src="icon.png" target="images\" />
</files>
</package>
90 changes: 90 additions & 0 deletions cloud-tooling/azure-site-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Azure Node Agent Site Extension

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/).

## Installation

This extension is designed for Node applications running on Azure Windows compute resources.

**Note:** Make sure that the target application is stopped prior to installing the extension.

From the Azure Home page, do the following:
- Click the App Services tile
- Click the name of the target application in the displayed list
- On the options listed on the left, scroll down to "Extensions" located under the `Development Tools` category
- Click on `+ Add` at the top of the page
- From the extension drop down, select `New Relic Node Agent`
- Click on the `Accept Legal Terms` link
- Click `OK` on the bottom left of the page
- Again, click `OK` on the bottom left of the page. This will begin installation of the extension

Once installed, the extension creates the following artifacts:
- Folder: `C:\home\node_modules\newrelic` - Contains the Node agent artifacts
- XDT: `applicationHost.xdt` that will add the necessary environment variable on application startup

If the extension fails to install, a log file is created at `C:\home\SiteExtensions\NewRelic.Azure.WebSites.Extension.NodeAgent\install.log`.

## Getting Started

Once the site extension is installed, you'll need to manually enter two configuration items before restarting your application:
- On the options listed on the left, scroll down to "Configuration" located under the `Settings` category
- On the configuration page, add the following two app settings:
- `NEW_RELIC_LICENSE_KEY` - Your New Relic license key value
- `NEW_RELIC_APP_NAME` - The name you wish your application to show up as in the New Relic Platform

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.

## Building

### Installing Dependencies (for MacOS and Linux)

- Download and install the latest version of [Mono](https://www.mono-project.com/download/stable/)
- Download `nuget.exe`: `sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe`
- Create an alias in your .bashrc or .zshrc for mono: `alias nuget="mono /usr/local/bin/nuget.exe"`
- 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.
- Restart your shell and execute `nuget` to verify your mono installation and `dotnet` to verify your .Net installation.

References:
- https://www.wiliam.com.au/wiliam-blog/creating-a-nuget-package
- https://learn.microsoft.com/en-au/nuget/install-nuget-client-tools#nugetexe-cli

### Publishing the Package

#### Publishing the Package with the Script (recommended)
- Your nuget package version is hardcoded in `version.txt`, update the file to change the version number.
- Run `./publish.sh <NUGET_API_KEY> <NUGET_SOURCE>`: this will create the NuGet package and upload to the target repository
- The parameters for `publish.sh` are the following:
- `NUGET_API_KEY` - API key for uploading artifacts to the target NuGet repository
- `NUGET_SOURCE` - Target NuGet repository (https://api.nuget.org/v3/index.json is the main, public URL)

#### Manually publishing the Package

- Change into the folder where the `.nuget` file exists
- Replace `{VERSION}` in `NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec` with a version number you want to push. (DO NOT COMMIT THIS CHANGE)
- Execute: `nuget pack NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec`
- This will create a package with the name: `NewRelic.Azure.WebSites.Extension.NodeAgent.VERSION.nupkg`
- 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)

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.

## Testing

It is recommended you use a personnel repository created in [MyGet](https://www.myget.org/).

Upload the nuget package then set up an app config variable in Azure:
- `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

In Azure, when you browse to `Development Tools` > `Extensions`, you will see a list of Nuget packages in your private repository.


## Extension Source Files

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.

- `README.md` - This file
- `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)
- `publish.sh` - Simple script to package the script and upload to the Nuget repository
- `Content/applicationHost.xdt` - XDT transformation to add the necessary agent startup environment variable to the app config when the app starts up
- `Content/install.cmd` - Simple batch file that wraps a call to the Powershell `install.ps1` script
- `Content/install.ps1` - Powershell script that downloads the agent bundle and installs it to the proper location on the host
- `Content/uninstall.cmd` - Simple batch file that will remove the Node installtion artifacts when the extension is removed
Binary file added cloud-tooling/azure-site-extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions cloud-tooling/azure-site-extension/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just a simple shell script that will later be
# used as a template for a GHA job for
# azure-site-extension site extension uploads.

# Dependencies: .Net 5 and up or .Net Core, Mono, and the Nuget CLI.
NUGET_API_KEY=$1
NUGET_SOURCE=$2
VERSION=$(cat version.txt)
NUSPEC_GENERATED="NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nuspec"
sed "s/{VERSION}/${VERSION}/g" NewRelic.Azure.WebSites.Extension.NodeAgent.nuspec > "${NUSPEC_GENERATED}"
nuget pack "${NUSPEC_GENERATED}"
dotnet nuget push "NewRelic.Azure.WebSites.Extension.NodeAgent.${VERSION}.nupkg" --api-key ${NUGET_API_KEY} --source ${NUGET_SOURCE}
1 change: 1 addition & 0 deletions cloud-tooling/azure-site-extension/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.0.0
21 changes: 11 additions & 10 deletions compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ version.
| --- | --- | --- | --- |
| `@apollo/gateway` | 2.3.0 | 2.8.4 | `@newrelic/[email protected]` |
| `@apollo/server` | 4.0.0 | 4.10.5 | `@newrelic/[email protected]` |
| `@aws-sdk/client-bedrock-runtime` | 3.474.0 | 3.622.0 | 11.13.0 |
| `@aws-sdk/client-dynamodb` | 3.0.0 | 3.622.0 | 8.7.1 |
| `@aws-sdk/client-sns` | 3.0.0 | 3.622.0 | 8.7.1 |
| `@aws-sdk/client-sqs` | 3.0.0 | 3.622.0 | 8.7.1 |
| `@aws-sdk/lib-dynamodb` | 3.377.0 | 3.622.0 | 8.7.1 |
| `@aws-sdk/client-bedrock-runtime` | 3.474.0 | 3.624.0 | 11.13.0 |
| `@aws-sdk/client-dynamodb` | 3.0.0 | 3.624.0 | 8.7.1 |
| `@aws-sdk/client-sns` | 3.0.0 | 3.624.0 | 8.7.1 |
| `@aws-sdk/client-sqs` | 3.0.0 | 3.624.0 | 8.7.1 |
| `@aws-sdk/lib-dynamodb` | 3.377.0 | 3.624.0 | 8.7.1 |
| `@aws-sdk/smithy-client` | 3.47.0 | 3.374.0 | 8.7.1 |
| `@elastic/elasticsearch` | 7.16.0 | 8.14.0 | 11.9.0 |
| `@grpc/grpc-js` | 1.4.0 | 1.11.1 | 8.17.0 |
| `@hapi/hapi` | 20.1.2 | 21.3.10 | 9.0.0 |
| `@koa/router` | 11.0.2 | 12.0.1 | 3.2.0 |
| `@langchain/core` | 0.1.17 | 0.2.19 | 11.13.0 |
| `@langchain/core` | 0.1.17 | 0.2.21 | 11.13.0 |
| `@nestjs/cli` | 9.0.0 | 10.4.2 | 10.1.0 |
| `@prisma/client` | 5.0.0 | 5.17.0 | 11.0.0 |
| `@prisma/client` | 5.0.0 | 5.18.0 | 11.0.0 |
| `@smithy/smithy-client` | 2.0.0 | 3.1.12 | 11.0.0 |
| `amqplib` | 0.5.0 | 0.10.4 | 2.0.0 |
| `apollo-server` | 3.0.0 | 3.13.0 | `@newrelic/[email protected]` |
| `apollo-server-express` | 3.0.0 | 3.13.0 | `@newrelic/[email protected]` |
| `aws-sdk` | 2.2.48 | 2.1666.0 | 6.2.0 |
| `aws-sdk` | 2.2.48 | 2.1669.0 | 6.2.0 |
| `bluebird` | 2.0.0 | 3.7.2 | 1.27.0 |
| `bunyan` | 1.8.12 | 1.8.15 | 9.3.0 |
| `cassandra-driver` | 3.4.0 | 4.7.2 | 1.7.1 |
| `connect` | 3.0.0 | 3.7.0 | 2.6.0 |
| `express` | 4.6.0 | 4.19.2 | 2.6.0 |
| `fastify` | 2.0.0 | 4.28.1 | 8.5.0 |
Expand All @@ -47,14 +48,14 @@ version.
| `mysql` | 2.2.0 | 2.18.1 | 1.32.0 |
| `mysql2` | 2.0.0 | 3.11.0 | 1.32.0 |
| `next` | 13.4.19 | 14.2.5 | 12.0.0 |
| `openai` | 4.0.0 | 4.54.0 | 11.13.0 |
| `openai` | 4.0.0 | 4.55.1 | 11.13.0 |
| `pg` | 8.2.0 | 8.12.0 | 9.0.0 |
| `pg-native` | 2.0.0 | 3.1.0 | 9.0.0 |
| `pino` | 7.0.0 | 9.3.2 | 8.11.0 |
| `q` | 1.3.0 | 1.5.1 | 1.26.2 |
| `redis` | 3.1.0 | 4.7.0 | 1.31.0 |
| `restify` | 11.0.0 | 11.1.0 | 2.6.0 |
| `superagent` | 3.0.0 | 9.0.2 | 4.9.0 |
| `superagent` | 3.0.0 | 10.0.0 | 4.9.0 |
| `undici` | 5.0.0 | 6.19.5 | 11.1.0 |
| `when` | 3.7.0 | 3.7.8 | 1.26.2 |
| `winston` | 3.0.0 | 3.13.1 | 8.11.0 |
Expand Down

0 comments on commit 676c580

Please sign in to comment.