11
11
using NewRelic . Agent . IntegrationTests . Shared ;
12
12
using Xunit ;
13
13
14
- namespace NewRelic . Agent . ContainerIntegrationTests . ContainerFixtures ;
14
+ namespace NewRelic . Agent . ContainerIntegrationTests . Applications ;
15
15
16
16
public class ContainerApplication : RemoteApplication
17
17
{
@@ -22,12 +22,14 @@ public class ContainerApplication : RemoteApplication
22
22
private readonly string _targetArch ;
23
23
private readonly string _agentArch ;
24
24
private readonly string _containerPlatform ;
25
- private readonly string _dockerComposeServiceName ;
25
+
26
+ private static Random random = new Random ( ) ;
27
+ private readonly long _randomId ;
26
28
27
29
// Used for handling dependent containers started automatically for services
28
30
public readonly List < string > DockerDependencies ;
29
31
30
- protected override string ApplicationDirectoryName { get ; }
32
+ protected override string ApplicationDirectoryName { get ; } = "ContainerApplication" ;
31
33
32
34
protected override string SourceApplicationDirectoryPath
33
35
{
@@ -37,16 +39,16 @@ protected override string SourceApplicationDirectoryPath
37
39
}
38
40
}
39
41
40
- public ContainerApplication ( string applicationDirectoryName , string distroTag , Architecture containerArchitecture ,
42
+ public ContainerApplication ( string distroTag , Architecture containerArchitecture ,
41
43
string dotnetVersion , string dockerfile , string dockerComposeFile = "docker-compose.yml" ) : base ( applicationType : ApplicationType . Container , isCoreApp : true )
42
44
{
43
- ApplicationDirectoryName = applicationDirectoryName ;
44
- _dockerComposeServiceName = applicationDirectoryName ;
45
45
_distroTag = distroTag ;
46
46
_dotnetVersion = dotnetVersion ;
47
47
_dockerfile = dockerfile ;
48
48
_dockerComposeFile = dockerComposeFile ;
49
49
50
+ _randomId = random . NextInt64 ( ) ; // a random id to help ensure container name uniqueness
51
+
50
52
DockerDependencies = new List < string > ( ) ;
51
53
52
54
switch ( containerArchitecture )
@@ -64,9 +66,9 @@ public ContainerApplication(string applicationDirectoryName, string distroTag, A
64
66
}
65
67
}
66
68
67
- public override string AppName => $ "{ _dockerComposeServiceName } _ { _dotnetVersion } -{ _distroTag } _{ _targetArch } ";
69
+ public override string AppName => $ "ContainerTestApp_ { _dotnetVersion } -{ _distroTag } _{ _targetArch } _ { _randomId } ";
68
70
69
- private string ContainerName => $ " { _dockerComposeServiceName } _ { _dotnetVersion } - { _distroTag } _ { _targetArch } " . ToLower ( ) ; // must be lowercase
71
+ private string ContainerName => AppName . ToLower ( ) . Replace ( "." , "_" ) ; // must be lowercase, can't have any periods in it
70
72
71
73
public override void CopyToRemote ( )
72
74
{
@@ -79,7 +81,7 @@ public override void Start(string commandLineArguments, Dictionary<string, strin
79
81
{
80
82
CleanupContainer ( ) ;
81
83
82
- var arguments = $ "compose -f { _dockerComposeFile } -p { _dockerComposeServiceName . ToLower ( ) } up --abort-on-container-exit --remove-orphans --force-recreate { _dockerComposeServiceName } ";
84
+ var arguments = $ "compose -f { _dockerComposeFile } -p { ContainerName } up --abort-on-container-exit --remove-orphans --force-recreate LinuxSmokeTestApp ";
83
85
84
86
var newRelicHomeDirectoryPath = DestinationNewRelicHomeDirectoryPath ;
85
87
var profilerLogDirectoryPath = DefaultLogFileDirectoryPath ;
@@ -107,6 +109,7 @@ public override void Start(string commandLineArguments, Dictionary<string, strin
107
109
startInfo . EnvironmentVariables . Remove ( "NEWRELIC_LOG_DIRECTORY" ) ;
108
110
startInfo . EnvironmentVariables . Remove ( "NEWRELIC_LOG_LEVEL" ) ;
109
111
startInfo . EnvironmentVariables . Remove ( "NEWRELIC_LICENSEKEY" ) ;
112
+ startInfo . EnvironmentVariables . Remove ( "NEW_RELIC_APP_NAME" ) ;
110
113
startInfo . EnvironmentVariables . Remove ( "NEW_RELIC_LICENSE_KEY" ) ;
111
114
startInfo . EnvironmentVariables . Remove ( "NEW_RELIC_HOST" ) ;
112
115
startInfo . EnvironmentVariables . Remove ( "NEWRELIC_INSTALL_PATH" ) ;
@@ -132,9 +135,6 @@ public override void Start(string commandLineArguments, Dictionary<string, strin
132
135
startInfo . EnvironmentVariables . Add ( "AGENT_PATH" , newRelicHomeDirectoryPath ) ;
133
136
startInfo . EnvironmentVariables . Add ( "LOG_PATH" , profilerLogDirectoryPath ) ;
134
137
startInfo . EnvironmentVariables . Add ( "CONTAINER_NAME" , ContainerName ) ;
135
- // generate a random network name to keep parallel test execution from failing
136
- // network name length needs to be less than 15 characters to be compatible with linux containers
137
- startInfo . EnvironmentVariables . Add ( "NETWORK_NAME" , $ "net-{ System . Security . Cryptography . RandomNumberGenerator . GetInt32 ( 1000000 , 10000000 ) } ") ;
138
138
139
139
if ( AdditionalEnvironmentVariables != null )
140
140
{
@@ -183,7 +183,7 @@ public override void Shutdown()
183
183
184
184
// stop and remove the container, no need to kill RemoteProcess, as it will die when this command runs
185
185
// wait up to 5 seconds for the app to terminate gracefully before forcefully closing it
186
- Process . Start ( "docker" , $ "compose -p { _dockerComposeServiceName . ToLower ( ) } down --rmi local --remove-orphans") ;
186
+ Process . Start ( "docker" , $ "compose -p { ContainerName . ToLower ( ) } down --rmi local --remove-orphans") ;
187
187
188
188
Thread . Sleep ( TimeSpan . FromSeconds ( 5 ) ) ; // give things a chance to settle before destroying the container
189
189
}
@@ -193,7 +193,7 @@ private void CleanupContainer()
193
193
Console . WriteLine ( $ "[{ AppName } { DateTime . Now } ] Cleaning up container and images related to { ContainerName } container.") ;
194
194
TestLogger ? . WriteLine ( $ "[{ AppName } ] Cleaning up container and images related to { ContainerName } container.") ;
195
195
196
- Process . Start ( "docker" , $ "compose -p { _dockerComposeServiceName . ToLower ( ) } down --rmi local --remove-orphans") ;
196
+ Process . Start ( "docker" , $ "compose -p { ContainerName . ToLower ( ) } down --rmi local --remove-orphans") ;
197
197
198
198
199
199
#if DEBUG
0 commit comments