private async Task VerifyRuntimeImage_FrameworkDependentApp(ImageData imageData, string appSdkImage) { string frameworkDepAppId = GetIdentifier(imageData.DotNetVersion, "framework-dependent-app"); bool isRunAsContainerAdministrator = String.Equals(OS.NanoServer1709, imageData.OsVariant, StringComparison.OrdinalIgnoreCase) || String.Equals(OS.NanoServer1803, imageData.OsVariant, StringComparison.OrdinalIgnoreCase) || String.Equals(OS.NanoServer1809, imageData.OsVariant, StringComparison.OrdinalIgnoreCase); string publishCmd = GetPublishArgs(imageData); try { // Publish the app to a Docker volume using the app's sdk image _dockerHelper.Run( image: appSdkImage, command: publishCmd, containerName: frameworkDepAppId, volumeName: frameworkDepAppId, runAsContainerAdministrator: isRunAsContainerAdministrator); // Run the app in the Docker volume to verify the runtime image string runtimeImage = GetDotNetImage( imageData.IsWeb ? DotNetImageType.AspNetCore_Runtime : DotNetImageType.Runtime, imageData); string appDllPath = _dockerHelper.GetContainerWorkPath("testApp.dll"); _dockerHelper.Run( image: runtimeImage, command: $"dotnet {appDllPath}", containerName: frameworkDepAppId, volumeName: frameworkDepAppId, detach: imageData.IsWeb, runAsContainerAdministrator: isRunAsContainerAdministrator); if (imageData.IsWeb && !s_isHttpVerificationDisabled) { await VerifyHttpResponseFromContainer(frameworkDepAppId); } } finally { _dockerHelper.DeleteContainer(frameworkDepAppId); _dockerHelper.DeleteVolume(frameworkDepAppId); } }
private async Task VerifyRuntimeImage_FrameworkDependentApp(ImageData imageData, string appSdkImage) { string frameworkDepAppId = GetIdentifier(imageData.DotNetVersion, "framework-dependent-app"); bool isRunAsContainerAdministrator = String.Equals( "nanoserver-1709", imageData.PlatformOS, StringComparison.OrdinalIgnoreCase); string optionalPublishArgs = GetOptionalPublishArgs(imageData); try { // Publish the app to a Docker volume using the app's sdk image _dockerHelper.Run( image: appSdkImage, command: $"dotnet publish -o {DockerHelper.ContainerWorkDir} {optionalPublishArgs}", containerName: frameworkDepAppId, volumeName: frameworkDepAppId, runAsContainerAdministrator: isRunAsContainerAdministrator); // Run the app in the Docker volume to verify the runtime image string runtimeImage = GetDotNetImage( imageData.IsWeb ? DotNetImageType.AspNetCore_Runtime : DotNetImageType.Runtime, imageData); string appDllPath = _dockerHelper.GetContainerWorkPath("testApp.dll"); _dockerHelper.Run( image: runtimeImage, command: $"dotnet {appDllPath}", containerName: frameworkDepAppId, volumeName: frameworkDepAppId, detach: imageData.IsWeb, runAsContainerAdministrator: isRunAsContainerAdministrator); if (imageData.IsWeb) { await VerifyHttpResponseFromContainer(frameworkDepAppId); } } finally { _dockerHelper.DeleteContainer(frameworkDepAppId); _dockerHelper.DeleteVolume(frameworkDepAppId); } }
/// <summary> /// Runs a single instance of each of the dotnet-monitor and samples images. /// </summary> /// <param name="monitorImageData">The image data of the dotnet-monitor image.</param> /// <param name="shareTmpVolume">Set to true to mount the /tmp directory in both containers.</param> /// <param name="listenDiagPortVolume"> /// Set to true to have the monitor container listen with a diagnostic port listener /// for diagnostic connections from the samples container. /// </param> /// <param name="noAuthentication">Set to true to disable dotnet-monitor authenication.</param> /// <param name="verifyContainerAsync">Callback to test some aspect of the containers.</param> /// <param name="monitorRunArgsCallback">Allows for modifying the "docker run" args of the dotnet-monitor container.</param> /// <param name="sampleRunArgsCallback">Allows for modifying the "docker run" args of the samples container.</param> private async Task VerifyScenarioAsync( MonitorImageData monitorImageData, SampleImageData sampleImageData, bool shareTmpVolume, bool listenDiagPortVolume, bool noAuthentication, Func <string, string, Task> verifyContainerAsync, Action <DockerRunArgsBuilder> monitorRunArgsCallback = null, Action <DockerRunArgsBuilder> sampleRunArgsCallback = null) { GetNames(monitorImageData, out string monitorImageName, out string monitorContainerName); GetNames(sampleImageData, out string sampleImageName, out string sampleContainerName); DockerRunArgsBuilder monitorArgsBuilder = DockerRunArgsBuilder.Create() .MonitorUrl(DefaultArtifactsPort); DockerRunArgsBuilder sampleArgsBuilder = DockerRunArgsBuilder.Create() .ExposePort(DefaultHttpPort); string diagPortVolumeName = null; string tmpVolumeName = null; try { // Create a volume for the two containers to share the /tmp directory. if (shareTmpVolume) { tmpVolumeName = DockerHelper.CreateVolume(UniqueName("tmpvol")); monitorArgsBuilder.VolumeMount(tmpVolumeName, Directory_Tmp); sampleArgsBuilder.VolumeMount(tmpVolumeName, Directory_Tmp); } // Create a volume so that the dotnet-monitor container can provide a // diagnostic listening port to the samples container so that the samples // process can connect to the dotnet-monitor process. if (listenDiagPortVolume) { diagPortVolumeName = DockerHelper.CreateVolume(UniqueName("diagportvol")); monitorArgsBuilder.VolumeMount(diagPortVolumeName, Directory_Diag); monitorArgsBuilder.MonitorListen(File_DiagPort); sampleArgsBuilder.VolumeMount(diagPortVolumeName, Directory_Diag); sampleArgsBuilder.RuntimeSuspend(File_DiagPort); } // Allow modification of the "docker run" args of the monitor container if (null != monitorRunArgsCallback) { monitorRunArgsCallback(monitorArgsBuilder); } // Allow modification of the "docker run" args of the samples container if (null != sampleRunArgsCallback) { sampleRunArgsCallback(sampleArgsBuilder); } // Run the sample container DockerHelper.Run( image: sampleImageName, name: sampleContainerName, detach: true, optionalRunArgs: sampleArgsBuilder.Build()); // Run the dotnet-monitor container DockerHelper.Run( image: monitorImageName, name: monitorContainerName, command: GetMonitorAdditionalArgs(noAuthentication), detach: true, optionalRunArgs: monitorArgsBuilder.Build()); await verifyContainerAsync( monitorContainerName, sampleContainerName); } finally { DockerHelper.DeleteContainer(monitorContainerName); DockerHelper.DeleteContainer(sampleContainerName); if (!string.IsNullOrEmpty(diagPortVolumeName)) { DockerHelper.DeleteVolume(diagPortVolumeName); } if (!string.IsNullOrEmpty(tmpVolumeName)) { DockerHelper.DeleteVolume(tmpVolumeName); } } }