Skip to content

Commit

Permalink
work in progress for stubbing out containerized integration test apps
Browse files Browse the repository at this point in the history
  • Loading branch information
nrcventura committed Jul 19, 2023
1 parent 974335c commit 0a23b4a
Show file tree
Hide file tree
Showing 18 changed files with 379 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace ContainerizedAspNetCoreApp.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
WORKDIR /src
COPY ["ContainerApplications/SmokeTestApp/SmokeTestApp.csproj", "SmokeTestApp/"]
RUN dotnet restore "SmokeTestApp/SmokeTestApp.csproj"
COPY . .
WORKDIR "/src/SmokeTestApp"
RUN dotnet build "SmokeTestApp.csproj" -c Release -o /app/build

FROM build AS publish
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
RUN dotnet publish "SmokeTestApp.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
ARG RESOURCE_REAPER_SESSION_ID="00000000-0000-0000-0000-000000000000"
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SmokeTestApp.dll"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace ContainerizedAspNetCoreApp
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseAuthorization();


app.MapControllers();

app.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"profiles": {
"ContainerizedAspNetCoreApp": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5075"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast",
"publishAllPorts": true
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:7298",
"sslPort": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;

namespace ContainerizedAspNetCoreApp
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
54 changes: 54 additions & 0 deletions tests/Agent/IntegrationTests/ContainerIntegrationTests.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContainerIntegrationTests", "ContainerIntegrationTests\ContainerIntegrationTests.csproj", "{3B33858F-A8CF-44FE-B1A6-9308254C0019}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTestHelpers", "IntegrationTestHelpers\IntegrationTestHelpers.csproj", "{1A7589F4-614C-47BA-8163-E42A6863BC13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTestHelpers.Test", "IntegrationTestHelpers.Test\IntegrationTestHelpers.Test.csproj", "{992B2E91-6439-4AB8-9C4C-E8F7FC68AE4D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{0EECB18A-4350-4D17-AB0D-F7647B4E3B58}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmokeTestApp", "ContainerApplications\SmokeTestApp\SmokeTestApp.csproj", "{FBA07795-8066-4641-88E5-05DD272D333A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ContainerApplications", "ContainerApplications", "{84D70574-4AC7-4EA7-AE52-832C3531E082}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B33858F-A8CF-44FE-B1A6-9308254C0019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B33858F-A8CF-44FE-B1A6-9308254C0019}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B33858F-A8CF-44FE-B1A6-9308254C0019}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B33858F-A8CF-44FE-B1A6-9308254C0019}.Release|Any CPU.Build.0 = Release|Any CPU
{1A7589F4-614C-47BA-8163-E42A6863BC13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A7589F4-614C-47BA-8163-E42A6863BC13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A7589F4-614C-47BA-8163-E42A6863BC13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A7589F4-614C-47BA-8163-E42A6863BC13}.Release|Any CPU.Build.0 = Release|Any CPU
{992B2E91-6439-4AB8-9C4C-E8F7FC68AE4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{992B2E91-6439-4AB8-9C4C-E8F7FC68AE4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{992B2E91-6439-4AB8-9C4C-E8F7FC68AE4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{992B2E91-6439-4AB8-9C4C-E8F7FC68AE4D}.Release|Any CPU.Build.0 = Release|Any CPU
{0EECB18A-4350-4D17-AB0D-F7647B4E3B58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EECB18A-4350-4D17-AB0D-F7647B4E3B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EECB18A-4350-4D17-AB0D-F7647B4E3B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EECB18A-4350-4D17-AB0D-F7647B4E3B58}.Release|Any CPU.Build.0 = Release|Any CPU
{FBA07795-8066-4641-88E5-05DD272D333A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBA07795-8066-4641-88E5-05DD272D333A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBA07795-8066-4641-88E5-05DD272D333A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBA07795-8066-4641-88E5-05DD272D333A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FBA07795-8066-4641-88E5-05DD272D333A} = {84D70574-4AC7-4EA7-AE52-832C3531E082}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB230433-D05D-4A1F-951B-CC14F47BBF42}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions tests/Agent/IntegrationTests/ContainerIntegrationTests/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

namespace ContainerIntegrationTests
{
public class Class1
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;

namespace NewRelic.Agent.ContainerIntegrationTests.ContainerFixtures
{
public class ContainerApplication : RemoteService
{
public ContainerApplication(string applicationDirectoryName, string executableName) :
base(applicationDirectoryName, executableName, applicationType:ApplicationType.Container, createsPidFile:false, isCoreApp:true, publishApp:true)
{
}

protected override void PublishWithDotnetExe(string framework)
{
// In a container application we do not need to perform a dotnet publish. Instead we need to copy the application
// so that it can be built into a docker container.
CopyApplicationDirectoryToRemote();
}

public override void Start(string commandLineArguments, Dictionary<string, string> environmentVariables, bool captureStandardOutput = false, bool doProfile = true)
{
var futureImage = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory(DestinationApplicationDirectoryPath)
.WithDockerfile("Dockerfile")
.WithBuildArgument("RESOURCE_REAPER_SESSION_ID", ResourceReaper.DefaultSessionId.ToString("D"))
.WithCleanUp(true)
.Build();

Task.Run(async () => await futureImage.CreateAsync().ConfigureAwait(false)).GetAwaiter().GetResult();

var containerBuilder = new ContainerBuilder()
.WithBindMount(DestinationNewRelicHomeDirectoryPath, "/newrelichome")
.WithCleanUp(true)
.WithImage(futureImage.FullName)
.WithPortBinding(Port, 80)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80));

}

protected override void WaitForAppServerToStartListening(Process process, bool captureStandardOutput)
{
base.WaitForAppServerToStartListening(process, captureStandardOutput);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;

namespace NewRelic.Agent.ContainerIntegrationTests.ContainerFixtures
{
public class ContainerFixture : RemoteApplicationFixture
{
public ContainerFixture(ContainerApplication remoteApplication) : base(remoteApplication)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>NewRelic.Agent.ContainerIntegrationTests</RootNamespace>
<AssemblyName>NewRelic.Agent.ContainerIntegrationTests</AssemblyName>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<Import Project="Test.targets" />

<ItemGroup>
<PackageReference Include="Testcontainers" Version="3.3.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IntegrationTestHelpers\IntegrationTestHelpers.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Test">
<Xunit.Runner.MSBuild.xunit Assemblies="$(ProjectDir)bin\$(Configuration)\NewRelic.Agent.ContainerIntegrationTests.dll" Xml="$(TargetDir)xUnitTestResults.xml"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
}
Loading

0 comments on commit 0a23b4a

Please sign in to comment.