Esempio n. 1
0
        private static string GetRuntimeIdentifier(DeploymentParameters deploymentParameters)
        {
            var architecture = deploymentParameters.RuntimeArchitecture;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return("win-" + architecture);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return("linux-" + architecture);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return("osx-" + architecture);
            }
            throw new InvalidOperationException("Unrecognized operation system platform");
        }
Esempio n. 2
0
 protected void InvokeUserApplicationCleanup()
 {
     using (Logger.BeginScope("UserAdditionalCleanup"))
     {
         if (DeploymentParameters.UserAdditionalCleanup != null)
         {
             // User cleanup.
             try
             {
                 DeploymentParameters.UserAdditionalCleanup(DeploymentParameters);
             }
             catch (Exception exception)
             {
                 Logger.LogWarning("User cleanup code failed with exception : {exception}", exception.Message);
             }
         }
     }
 }
        public DeploymentParameters(DeploymentParameters parameters)
        {
            foreach (var propertyInfo in typeof(DeploymentParameters).GetProperties())
            {
                if (propertyInfo.CanWrite)
                {
                    propertyInfo.SetValue(this, propertyInfo.GetValue(parameters));
                }
            }

            foreach (var kvp in parameters.EnvironmentVariables)
            {
                EnvironmentVariables.Add(kvp);
            }

            foreach (var kvp in parameters.PublishEnvironmentVariables)
            {
                PublishEnvironmentVariables.Add(kvp);
            }
        }
Esempio n. 4
0
 public DeploymentResult(ILoggerFactory loggerFactory, DeploymentParameters deploymentParameters)
     : this(loggerFactory, deploymentParameters : deploymentParameters, contentRoot : string.Empty, hostShutdownToken : CancellationToken.None)
 {
 }
Esempio n. 5
0
        public virtual Task <PublishedApplication> Publish(DeploymentParameters deploymentParameters, ILogger logger)
        {
            var publishDirectory = CreateTempDirectory();

            using (logger.BeginScope("dotnet-publish"))
            {
                if (string.IsNullOrEmpty(deploymentParameters.TargetFramework))
                {
                    throw new Exception($"A target framework must be specified in the deployment parameters for applications that require publishing before deployment");
                }

                var parameters = $"publish "
                                 + $" --output \"{publishDirectory.FullName}\""
                                 + $" --framework {deploymentParameters.TargetFramework}"
                                 + $" --configuration {deploymentParameters.Configuration}"
                                 // avoids triggering builds of dependencies of the test app which could cause issues like https://github.com/dotnet/arcade/issues/2941
                                 + $" --no-dependencies"
                                 + $" /p:TargetArchitecture={deploymentParameters.RuntimeArchitecture}"
                                 + " --no-restore";

                if (deploymentParameters.ApplicationType == ApplicationType.Standalone)
                {
                    parameters += $" --runtime {GetRuntimeIdentifier(deploymentParameters)}";
                }
                else
                {
                    // Workaround for https://github.com/aspnet/websdk/issues/422
                    parameters += " -p:UseAppHost=false";
                }

                parameters += $" {deploymentParameters.AdditionalPublishParameters}";

                var startInfo = new ProcessStartInfo
                {
                    FileName               = DotnetCommandName,
                    Arguments              = parameters,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    WorkingDirectory       = deploymentParameters.ApplicationPath,
                };

                ProcessHelpers.AddEnvironmentVariablesToProcess(startInfo, deploymentParameters.PublishEnvironmentVariables, logger);

                var hostProcess = new Process()
                {
                    StartInfo = startInfo
                };

                logger.LogInformation($"Executing command {DotnetCommandName} {parameters}");

                hostProcess.StartAndCaptureOutAndErrToLogger("dotnet-publish", logger);

                // A timeout is passed to Process.WaitForExit() for two reasons:
                //
                // 1. When process output is read asynchronously, WaitForExit() without a timeout blocks until child processes
                //    are killed, which can cause hangs due to MSBuild NodeReuse child processes started by dotnet.exe.
                //    With a timeout, WaitForExit() returns when the parent process is killed and ignores child processes.
                //    https://stackoverflow.com/a/37983587/102052
                //
                // 2. If "dotnet publish" does hang indefinitely for some reason, tests should fail fast with an error message.
                const int timeoutMinutes = 5;
                if (hostProcess.WaitForExit(milliseconds: timeoutMinutes * 60 * 1000))
                {
                    if (hostProcess.ExitCode != 0)
                    {
                        var message = $"{DotnetCommandName} publish exited with exit code : {hostProcess.ExitCode}";
                        logger.LogError(message);
                        throw new Exception(message);
                    }
                }
                else
                {
                    var message = $"{DotnetCommandName} publish failed to exit after {timeoutMinutes} minutes";
                    logger.LogError(message);
                    throw new Exception(message);
                }

                logger.LogInformation($"{DotnetCommandName} publish finished with exit code : {hostProcess.ExitCode}");
            }

            return(Task.FromResult(new PublishedApplication(publishDirectory.FullName, logger)));
        }
Esempio n. 6
0
 public SelfHostDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory)
     : base(deploymentParameters, loggerFactory)
 {
 }
Esempio n. 7
0
 protected void StartTimer()
 {
     Logger.LogInformation($"Deploying {DeploymentParameters.ToString()}");
     _stopwatch.Start();
 }