Beispiel #1
0
 public MsBuildSiteBuilder(IBuildPropertyProvider propertyProvider, string workingDirectory, string tempPath, string nugetCachePath)
 {
     _propertyProvider = propertyProvider;
     _msbuildExe = new Executable(PathUtility.ResolveMSBuildPath(), workingDirectory);
     _msbuildExe.EnvironmentVariables[NuGetCachePathKey] = nugetCachePath;
     _tempPath = tempPath;
 }
        public Executable BuildExternalCommandExecutable(string workingDirectory, string deploymentTargetPath)
        {
            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(StarterScriptPath, workingDirectory, _deploymentSettings.GetCommandIdleTimeout());
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            exe.EnvironmentVariables[SourcePath] = _repositoryPath;
            exe.EnvironmentVariables[TargetPath] = deploymentTargetPath;
            exe.EnvironmentVariables[MSBuildPath] = PathUtility.ResolveMSBuildPath();
            exe.EnvironmentVariables[KuduSyncCommandKey] = KuduSyncCommand;
            exe.EnvironmentVariables[SelectNodeVersionCommandKey] = SelectNodeVersionCommand;
            exe.EnvironmentVariables[NpmJsPathKey] = PathUtility.ResolveNpmJsPath();

            // Disable this for now
            // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath;

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";

            exe.SetHomePath(_environment.SiteRootPath);

            // Set the path so we can add more variables
            exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH");

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new[] {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath())
            };

            exe.AddToPath(toolsPaths);

            return exe;
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            string loopValue = context.Request["l"];
            int loops;
            if (!Int32.TryParse(loopValue, out loops))
            {
                loops = 1;
            }

            string wwwroot = Path.Combine(HttpRuntime.AppDomainAppPath, "wwwroot");
            string nodeDir = Path.Combine(wwwroot, "node_modules");

            var npmPath = ResolveNpmPath();
            var exe = new Executable(npmPath, wwwroot);

            for (int i = 0; i < loops; i++)
            {
                try
                {
                    var result = exe.Execute("install");
                    context.Response.Write(@"<div style=""font-weight:bold;color:green"">Run " + (i + 1) + " success! </div>");
                    context.Response.Flush();
                    FileSystemHelpers.DeleteDirectorySafe(nodeDir);
                }
                catch (Exception ex)
                {
                    context.Response.Write(@"<div style=""font-weight:bold;color:red"">Run " + (i + 1) + " failed!</div>");
                    context.Response.Write(@"<pre>" + ex.Message + "</pre>");
                    context.Response.Flush();
                    break;
                }
            }
        }
        public Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger)
        {
            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(commandPath, workingDirectory, idleTimeout);
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger);

            exe.SetHomePath(_environment);

            // Set the path so we can add more variables
            string path = System.Environment.GetEnvironmentVariable("PATH");
            exe.EnvironmentVariables["PATH"] = path;

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new List<string> {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath()),
                Path.GetDirectoryName(PathUtility.ResolveVsTestPath()),
                Path.GetDirectoryName(PathUtility.ResolveSQLCmdPath()),
                _environment.ScriptPath
            };

            toolsPaths.AddRange(PathUtility.ResolveNodeNpmPaths());
            
            toolsPaths.Add(PathUtility.ResolveNpmGlobalPrefix());

            exe.PrependToPath(toolsPaths);
            return exe;
        }
        protected MsBuildSiteBuilder(IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string workingDirectory)
        {
            _settings = settings;
            _propertyProvider = propertyProvider;
            _msbuildExe = new Executable(PathUtility.ResolveMSBuildPath(), workingDirectory, settings.GetCommandIdleTimeout());

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            _msbuildExe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";
        }
Beispiel #6
0
        public static void Install(string packageToInstall, string installToPath)
        {
            using (new LatencyLogger("npm install " + packageToInstall + " to " + installToPath))
            {
                var exe = new Executable(PathUtility.ResolveNpmPath(), installToPath, idleTimeout: TimeSpan.FromSeconds(3600));
                var result = exe.Execute("install {0} .", packageToInstall);

                TestTracer.Trace("  stdout: {0}", result.Item1);
                TestTracer.Trace("  stderr: {0}", result.Item2);
            }
        }
Beispiel #7
0
Datei: Npm.cs Projekt: 40a/kudu
        public static void Install(string packageToInstall, string installToPath)
        {
            using (new LatencyLogger("npm install " + packageToInstall + " to " + installToPath))
            {
                string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                string npmPath = Path.Combine(programFiles, "nodejs", "npm.cmd");
                var exe = new Executable(npmPath, installToPath, idleTimeout: TimeSpan.FromSeconds(3600));
                var result = exe.Execute("install {0} .", packageToInstall);

                TestTracer.Trace("  stdout: {0}", result.Item1);
                TestTracer.Trace("  stderr: {0}", result.Item2);
            }
        }
Beispiel #8
0
        public MsBuildSiteBuilder(IBuildPropertyProvider propertyProvider, string workingDirectory, string tempPath, string nugetCachePath)
        {
            _propertyProvider = propertyProvider;
            _msbuildExe = new Executable(PathUtility.ResolveMSBuildPath(), workingDirectory);

            // Disable this for now
            // _msbuildExe.EnvironmentVariables[NuGetCachePathKey] = nugetCachePath;

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            _msbuildExe.EnvironmentVariables[NuGetPackageRestoreKey] = "true";

            _tempPath = tempPath;
        }
Beispiel #9
0
Datei: Node.cs Projekt: 40a/kudu
        public static void Execute(string workingDirectory, string commandFormat, params object[] args)
        {
            var command = String.Format(commandFormat, args);

            using (new LatencyLogger(NodeExe + " " + command))
            {
                var exe = new Executable(NodeExe, workingDirectory, idleTimeout: TimeSpan.FromSeconds(3600));
                exe.SetHomePath(Environment.GetEnvironmentVariable("USERPROFILE"));
                var result = exe.Execute(command);

                TestTracer.Trace("  stdout: {0}", result.Item1);
                TestTracer.Trace("  stderr: {0}", result.Item2);
            }
        }
        public Executable BuildExternalCommandExecutable(string workingDirectory, string deploymentTargetPath, ILogger logger)
        {
            string sourcePath = _repositoryPath;
            string targetPath = deploymentTargetPath;

            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(StarterScriptPath, workingDirectory, _deploymentSettings.GetCommandIdleTimeout());
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SourcePath, sourcePath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.TargetPath, targetPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SelectNodeVersionCommandKey, SelectNodeVersionCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger);

            if (PathUtility.PathsEquals(sourcePath, targetPath))
            {
                UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.InPlaceDeployment, "1", logger);
            }

            // Disable this for now
            // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath;

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";

            exe.SetHomePath(_environment.SiteRootPath);

            // Set the path so we can add more variables
            exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH");

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new[] {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath()),
                Path.GetDirectoryName(PathUtility.ResolveVsTestPath())
            };

            exe.AddToPath(toolsPaths);

            return exe;
        }
Beispiel #11
0
        public static string SelectNodeVersion(IFileSystem fileSystem, string scriptPath, string sourcePath, ITracer tracer)
        {
            // The node.js version selection logic is implemented in selectNodeVersion.js.

            // run with default node.js version which is on the path
            Executable executor = new Executable("node.exe", String.Empty);
            try
            {
                return executor.ExecuteWithConsoleOutput(
                    tracer,
                    "\"{0}\\selectNodeVersion.js\" \"{1}\" \"{1}\"",
                    scriptPath,
                    sourcePath).Item1;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resources.Error_UnableToSelectNodeVersion, e);
            }
        }
        public Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger)
        {
            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(commandPath, workingDirectory, idleTimeout);
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger);

            exe.SetHomePath(_environment);

            // Set the path so we can add more variables
            string path = System.Environment.GetEnvironmentVariable("PATH");
            exe.EnvironmentVariables["PATH"] = path;

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new List<string> {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath()),
                Path.GetDirectoryName(PathUtility.ResolveVsTestPath()),
                Path.GetDirectoryName(PathUtility.ResolveSQLCmdPath()),
                _environment.ScriptPath
            };

            string nodeExePath = PathUtility.ResolveNodePath();
            if (!String.IsNullOrEmpty(nodeExePath))
            {
                // If IIS node path is available prepend it to the path list so that it's discovered before any other node versions in the path.
                toolsPaths.Add(Path.GetDirectoryName(nodeExePath));
            }

            string npmExePath = PathUtility.ResolveNpmCmdPath();
            if (!String.IsNullOrEmpty(npmExePath))
            {
                toolsPaths.Add(Path.GetDirectoryName(npmExePath));
            }

            exe.PrependToPath(toolsPaths);
            return exe;
        }
        private void GenerateScript(DeploymentContext context, ILogger buildLogger)
        {
            try
            {
                using (context.Tracer.Step("Generating deployment script"))
                {
                    var scriptGenerator = new Executable(DeploymentScriptGeneratorToolPath, RepositoryPath, DeploymentSettings.GetCommandIdleTimeout());

                    // Set home path to the user profile so cache directories created by azure-cli are created there
                    scriptGenerator.SetHomePath(System.Environment.GetEnvironmentVariable("APPDATA"));

                    var scriptGeneratorCommand = String.Format(ScriptGeneratorCommandFormat, RepositoryPath, Environment.DeploymentToolsPath, ScriptGeneratorCommandArguments);

                    bool cacheUsed = UseCachedDeploymentScript(scriptGeneratorCommand, context);
                    if (!cacheUsed)
                    {
                        buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommand);

                        scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, scriptGeneratorCommand);

                        CacheDeploymentScript(scriptGeneratorCommand, context);
                    }
                    else
                    {
                        buildLogger.Log(Resources.Log_DeploymentScriptGeneratorUsingCache, scriptGeneratorCommand);
                    }
                }
            }
            catch (Exception ex)
            {
                context.Tracer.TraceError(ex);

                // HACK: Log an empty error to the global logger (post receive hook console output).
                // The reason we don't log the real exception is because the 'live output' running
                // msbuild has already been captured.
                context.GlobalLogger.LogError();

                throw;
            }
        }
Beispiel #14
0
        public Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger)
        {
            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(commandPath, workingDirectory, idleTimeout);
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.DnvmPath, DnvmPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.GypMsvsVersion, Constants.VCVersion, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.VCTargetsPath, PathUtility.ResolveVCTargetsPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.VCInstallDir140, PathUtility.ResolveVCInstallDirPath(), logger);

            exe.SetHomePath(_environment);

            // Set the path so we can add more variables
            string path = System.Environment.GetEnvironmentVariable("PATH");
            exe.EnvironmentVariables["PATH"] = path;

            return exe;
        }
        // TODO: add specific support in script for this:
        //protected string GetMSBuildExtraArguments()
        //{
        //if (_settings == null) return String.Empty;
        //return _settings.GetValue(SettingsKeys.BuildArgs);
        //}
        protected void RunCommand(DeploymentContext context, string command)
        {
            ILogger customLogger = context.Logger.Log("Running deployment command...");
            customLogger.Log("Command: " + command);

            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable("cmd", RepositoryPath);
            exe.AddDeploymentSettingsAsEnvironmentVariables(DeploymentSettings);
            exe.EnvironmentVariables[SourcePath] = RepositoryPath;
            exe.EnvironmentVariables[TargetPath] = context.OutputPath;
            exe.EnvironmentVariables[MSBuildPath] = PathUtility.ResolveMSBuildPath();
            exe.EnvironmentVariables[PreviousManifestPath] = context.PreviousManifestFilePath ?? String.Empty;
            exe.EnvironmentVariables[NextManifestPath] = context.NextManifestFilePath;
            exe.EnvironmentVariables["KUDU_SYNC_COMMAND"] = KuduSyncPath;

            // Disable this for now
            // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath;

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";

            exe.SetHomePath(HomePath);

            // Create a directory for the script output temporary artifacts
            string buildTempPath = Path.Combine(Environment.TempPath, Guid.NewGuid().ToString());
            FileSystemHelpers.EnsureDirectory(buildTempPath);
            exe.EnvironmentVariables[BuildTempPath] = buildTempPath;

            // Populate the enviornment with the build propeties
            foreach (var property in PropertyProvider.GetProperties())
            {
                exe.EnvironmentVariables[property.Key] = property.Value;
            }

            // Set the path so we can add more variables
            exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH");

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new[] {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath())
            };

            exe.AddToPath(toolsPaths);

            try
            {
                exe.ExecuteWithProgressWriter(customLogger, context.Tracer, ShouldFilterOutMsBuildWarnings, "/c " + command, String.Empty);
            }
            catch (CommandLineException ex)
            {
                context.Tracer.TraceError(ex);

                // HACK: Log an empty error to the global logger (post receive hook console output).
                // The reason we don't log the real exception is because the 'live output' running
                // msbuild has already been captured.
                context.GlobalLogger.LogError();

                // Add the output stream and the error stream to the log for better
                // debugging
                customLogger.Log(ex.Output, LogEntryType.Error);
                customLogger.Log(ex.Error, LogEntryType.Error);

                throw new CommandLineException(ex.Message, ex);
            }
            finally
            {
                // Clean the temp folder up
                CleanBuild(context.Tracer, buildTempPath);
                FileSystemHelpers.DeleteDirectorySafe(buildTempPath);
            }
        }
Beispiel #16
0
 public HgRepository(string path)
 {
     _repository = new Repository(path);
     _hgExe = new Executable(Client.ClientPath, path);
 }
Beispiel #17
0
        public Executable BuildExternalCommandExecutable(string workingDirectory, string deploymentTargetPath, ILogger logger)
        {
            string sourcePath = _repositoryPath;
            string targetPath = deploymentTargetPath;

            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(StarterScriptPath, workingDirectory, _deploymentSettings.GetCommandIdleTimeout());
            exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SourcePath, sourcePath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.TargetPath, targetPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.PostDeploymentActionsCommandKey, PostDeploymentActionsCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.PostDeploymentActionsDirectoryKey, PostDeploymentActionsDir, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SelectNodeVersionCommandKey, SelectNodeVersionCommand, logger);
            UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger);

            bool isInPlace = false;
            string project = _deploymentSettings.GetValue(SettingsKeys.Project);
            if (!String.IsNullOrEmpty(project))
            {
                isInPlace = PathUtility.PathsEquals(Path.Combine(sourcePath, project), targetPath);
            }
            else
            {
                isInPlace = PathUtility.PathsEquals(sourcePath, targetPath);
            }

            if (isInPlace)
            {
                UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.InPlaceDeployment, "1", logger);
            }

            // NuGet.exe 1.8 will require an environment variable to make package restore work
            exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";

            exe.SetHomePath(_environment.SiteRootPath);

            // Set the path so we can add more variables
            string path = System.Environment.GetEnvironmentVariable("PATH");
            exe.EnvironmentVariables["PATH"] = path;

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new List<string> {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath()),
                Path.GetDirectoryName(PathUtility.ResolveVsTestPath())
            };

            string nodeExePath = PathUtility.ResolveNodePath();
            if (!String.IsNullOrEmpty(nodeExePath))
            {
                // If IIS node path is available prepend it to the path list so that it's discovered before any other node versions in the path.
                toolsPaths.Add(Path.GetDirectoryName(nodeExePath));
            }

            exe.PrependToPath(toolsPaths);
            return exe;
        }
Beispiel #18
0
 private void UpdateToDefaultIfNotSet(Executable exe, string key, string defaultValue, ILogger logger)
 {
     var value = _deploymentSettings.GetValue(key);
     if (string.IsNullOrEmpty(value))
     {
         exe.EnvironmentVariables[key] = defaultValue;
     }
     else
     {
         logger.Log("Using custom deployment setting for {0} custom value is '{1}'.", key, value);
         exe.EnvironmentVariables[key] = value;
     }
 }
Beispiel #19
0
        private static Server GetServer(IEnvironment environment)
        {
            string configFile = EnsureConfiguration(environment);
            string pidFilePath = Path.Combine(environment.ApplicationRootPath, "serverpid");

            var hgExe = new Executable(Client.ClientPath, environment.RepositoryPath);

            return new Server(hgExe, environment.AppName, configFile, pidFilePath);
        }
 public SolutionBasedSiteBuilder(string repositoryPath, string solutionPath)
 {
     SolutionPath = solutionPath;
     _msbuildExe = new Executable(ResolveMSBuildPath(), repositoryPath);
 }
Beispiel #21
0
        protected virtual bool MapPath(string path, out string driveName)
        {
            var cmd = new Executable("cmd", GetWindowsFolder());
            driveName = null;

            foreach (var letter in DriveLetters)
            {
                try
                {
                    // There's probably an API for this as well but this is easy to do
                    // Not as easy to parse out the results of net use
                    cmd.Execute("/c net use {0}: {1}", letter, path);
                    driveName = letter + @":\";
                    return true;
                }
                catch
                {

                }
            }

            return false;
        }
        public static void GCDump(this Process process, string dumpFile, string resourcePath, int maxDumpCountK, ITracer tracer, TimeSpan idleTimeout)
        {
            var exe = new Executable(_gcDumpExe.Value, Path.GetDirectoryName(dumpFile), idleTimeout);

            exe.Execute(tracer, "\"{0}\" \"{1}\" \"{2}\" \"{3}\"", process.Id, dumpFile, resourcePath, maxDumpCountK);
        }
Beispiel #23
0
        private void GenerateScript(DeploymentContext context, ILogger buildLogger)
        {
            try
            {
                using (context.Tracer.Step("Generating deployment script"))
                {
                    var scriptGenerator = new Executable(DeploymentScriptGeneratorToolPath, RepositoryPath, DeploymentSettings.GetCommandIdleTimeout());
                    scriptGenerator.SetHomePath(HomePath);

                    var scriptGeneratorCommand = String.Format(ScriptGeneratorCommandFormat, RepositoryPath, ScriptGeneratorCommandArguments);
                    buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommand);

                    scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, _ => false, scriptGeneratorCommand);
                }
            }
            catch (CommandLineException ex)
            {
                context.Tracer.TraceError(ex);

                // HACK: Log an empty error to the global logger (post receive hook console output).
                // The reason we don't log the real exception is because the 'live output' running
                // msbuild has already been captured.
                context.GlobalLogger.LogError();

                // Add the output stream and the error stream to the log for better
                // debugging
                buildLogger.Log(ex.Output, LogEntryType.Error);
                buildLogger.Log(ex.Error, LogEntryType.Error);

                throw;
            }
        }
Beispiel #24
0
 public MsBuildSiteBuilder(IBuildPropertyProvider propertyProvider, string workingDirectory)
 {
     _propertyProvider = propertyProvider;
     _msbuildExe = new Executable(ResolveMSBuildPath(), workingDirectory);
 }
Beispiel #25
0
        public string SelectNodeVersion(ITracer tracer)
        {
            // The node.js version selection logic is implemented in selectNodeVersion.js. 

            // run with default node.js version which is on the path
            Executable executor = new Executable("node.exe", String.Empty, _settings.GetCommandIdleTimeout());
            try
            {
                return executor.ExecuteWithConsoleOutput(
                    tracer,
                    "\"{0}\\selectNodeVersion.js\" \"{1}\" \"{2}\"",
                    _scriptPath,
                    _repoFolder,
                    _siteFolder).Item1;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resources.Error_UnableToSelectNodeVersion, e);
            }
        }
Beispiel #26
0
 public MSBuildDeployer(IEnvironment environment)
 {
     _environment = environment;
     _msbuildExe = new Executable(ResolveMSBuildPath(), environment.RepositoryPath);
 }
Beispiel #27
0
        public void CleanWwwRoot()
        {
            var tracer = _traceFactory.GetTracer();
            using (tracer.Step("Cleaning wwwroot"))
            {
                string activeDeploymentId = _status.ActiveDeploymentId;

                // Clean only required if there is an actual deployment (active deployment id is not null)
                if (activeDeploymentId != null)
                {
                    string emptyTempPath = Path.Combine(_environment.TempPath, Guid.NewGuid().ToString());

                    try
                    {
                        // Create an empty temporary directory
                        FileSystemHelpers.EnsureDirectory(emptyTempPath);

                        string from = emptyTempPath;
                        string to = _environment.WebRootPath;
                        string previousManifest = GetDeploymentManifestPath(activeDeploymentId);
                        string nextManifest = Path.Combine(emptyTempPath, "manifest");

                        // Run kudu sync from the empty directory to wwwroot using the current manifest
                        // This will cause all previously deployed files to be removed from wwwroot
                        var exe = new Executable(Path.Combine(_environment.ScriptPath, "kudusync.cmd"), emptyTempPath, _settings.GetCommandIdleTimeout());
                        Tuple<string, string> result = exe.Execute(tracer, "-f {0} -t {1} -p {2} -n {3} -v 50", from, to, previousManifest, nextManifest);

                        if (!String.IsNullOrEmpty(result.Item1))
                        {
                            tracer.Trace("Process output: {0}", result.Item1);
                        }
                        if (!String.IsNullOrEmpty(result.Item2))
                        {
                            tracer.Trace("Process error: {0}", result.Item2);
                        }
                    }
                    finally
                    {
                        FileSystemHelpers.DeleteDirectorySafe(emptyTempPath);
                    }
                }
                else
                {
                    tracer.Trace("No active deployment to clean");
                }
            }
        }
Beispiel #28
0
        public Task Build(DeploymentContext context)
        {
            var tcs = new TaskCompletionSource<object>();

            ILogger customLogger = context.Logger.Log("Running custom deployment command...");

            // Creates an executable pointing to cmd and the working directory being
            // the repository root
            var exe = new Executable(StarterScriptPath, _repositoryPath, _settings.GetCommandIdleTimeout());
            exe.AddDeploymentSettingsAsEnvironmentVariables(_settings);
            exe.EnvironmentVariables[ExternalCommandFactory.SourcePath] = _repositoryPath;
            exe.EnvironmentVariables[ExternalCommandFactory.TargetPath] = context.OutputPath;
            exe.EnvironmentVariables[ExternalCommandBuilder.PreviousManifestPath] = (context.PreviousManifest != null) ? context.PreviousManifest.ManifestFilePath : String.Empty;
            exe.EnvironmentVariables[ExternalCommandBuilder.NextManifestPath] = context.ManifestWriter.ManifestFilePath;
            exe.EnvironmentVariables[ExternalCommandFactory.MSBuildPath] = PathUtility.ResolveMSBuildPath();
            exe.EnvironmentVariables[ExternalCommandFactory.KuduSyncCommandKey] = KuduSyncCommand;
            exe.EnvironmentVariables[ExternalCommandFactory.SelectNodeVersionCommandKey] = SelectNodeVersionCommand;
            exe.EnvironmentVariables[ExternalCommandFactory.NpmJsPathKey] = PathUtility.ResolveNpmJsPath();
            exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true";

            exe.SetHomePath(_homePath);

            // Create a directory for the script output temporary artifacts
            string buildTempPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
            FileSystemHelpers.EnsureDirectory(buildTempPath);
            exe.EnvironmentVariables[ExternalCommandBuilder.BuildTempPath] = buildTempPath;

            // Populate the enviornment with the build propeties
            foreach (var property in _propertyProvider.GetProperties())
            {
                exe.EnvironmentVariables[property.Key] = property.Value;
            }

            // Set the path so we can add more variables
            exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH");

            // Add the msbuild path and git path to the %PATH% so more tools are available
            var toolsPaths = new[] {
                Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
                Path.GetDirectoryName(PathUtility.ResolveGitPath())
            };

            exe.AddToPath(toolsPaths);

            try
            {
                exe.ExecuteWithProgressWriter(customLogger, context.Tracer, _command, String.Empty);

                tcs.SetResult(null);
            }
            catch (CommandLineException ex)
            {
                context.Tracer.TraceError(ex);

                // HACK: Log an empty error to the global logger (post receive hook console output).
                // The reason we don't log the real exception is because the 'live output' running
                // msbuild has already been captured.
                context.GlobalLogger.LogError();

                // Add the output stream and the error stream to the log for better
                // debugging
                customLogger.Log(ex.Output, LogEntryType.Error);
                customLogger.Log(ex.Error, LogEntryType.Error);

                tcs.SetException(ex);
            }
            finally
            {
                // Clean the temp folder up
                FileSystemHelpers.DeleteDirectorySafe(buildTempPath);
            }

            return tcs.Task;
        }
 public static void GCDump(this Process process, string dumpFile, string resourcePath, int maxDumpCountK, ITracer tracer, TimeSpan idleTimeout)
 {
     var exe = new Executable(_gcDumpExe.Value, Path.GetDirectoryName(dumpFile), idleTimeout);
     exe.Execute(tracer, "\"{0}\" \"{1}\" \"{2}\" \"{3}\"", process.Id, dumpFile, resourcePath, maxDumpCountK);  
 }
Beispiel #30
0
        private void SetupAcls(string appName, string appPoolName)
        {
            // Setup Acls for this user
            var icacls = new Executable(@"C:\Windows\System32\icacls.exe", Directory.GetCurrentDirectory());

            // Make sure the application path exists
            string applicationPath = _pathResolver.GetApplicationPath(appName);
            Directory.CreateDirectory(applicationPath);

            try
            {
                // Give full control to the app folder (we can make it minimal later)
                icacls.Execute(@"""{0}\*"" /grant ""IIS AppPool\{1}:F"" /C /Q /T", applicationPath, appPoolName);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            try
            {
                // Give full control to the temp folder
                string windowsTemp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Temp");
                icacls.Execute(@"""{0}"" /grant ""IIS AppPool\{1}:F"" /C /Q /T", windowsTemp, appPoolName);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #31
0
 internal Server(Executable hgExe, string appName, string configFile, string pidFile)
 {
     _hgExe = hgExe;
     _appName = appName;
     _configFile = configFile;
     _pidFile = pidFile;
 }