예제 #1
0
        public override Task Build(DeploymentContext context)
        {
            context.Logger.Log($"Running build. Project type: {ProjectType}");

            // Start by copying the manifest as-is so that
            // manifest based deployments (Example: ZipDeploy) are unaffected
            context.Logger.Log($"Copying the manifest");
            FileSystemHelpers.CopyFile(context.PreviousManifestFilePath, context.NextManifestFilePath);

            // If we want to clean up the target directory before copying
            // the new files, use kudusync so that only unnecessary files are
            // deleted. This has two benefits:
            // 1. This is faster than deleting the target directory before copying the source dir.
            // 2. Minimizes chances of failure in deleting a directory due to open handles.
            //    This is especially useful when a target directory is present in the source and
            //    need not be deleted.
            if (_deploymentInfo.CleanupTargetDirectory)
            {
                context.Logger.Log($"Clean deploying to {context.OutputPath}");

                // We do not want to use the manifest for OneDeploy. Set manifest paths to null.
                // This way we don't interfere with manifest based deployments.
                context.PreviousManifestFilePath = context.NextManifestFilePath = string.Empty;
                base.Build(context);
            }
            else
            {
                context.Logger.Log($"Incrementally deploying to {context.OutputPath}");
                FileSystemHelpers.CopyDirectoryRecursive(_repositoryPath, context.OutputPath);
            }

            context.Logger.Log($"Build completed succesfully.");

            return(Task.CompletedTask);
        }
예제 #2
0
        public void Save()
        {
            if (String.IsNullOrEmpty(Id))
            {
                throw new InvalidOperationException();
            }

            var document = new XDocument(new XElement("deployment",
                                                      new XElement("id", Id),
                                                      new XElement("author", XmlUtility.Sanitize(Author)),
                                                      new XElement("deployer", Deployer),
                                                      new XElement("authorEmail", AuthorEmail),
                                                      new XElement("message", XmlUtility.Sanitize(Message)),
                                                      new XElement("progress", Progress),
                                                      new XElement("status", Status),
                                                      new XElement("statusText", StatusText),
                                                      new XElement("lastSuccessEndTime", LastSuccessEndTime),
                                                      new XElement("receivedTime", ReceivedTime),
                                                      new XElement("startTime", StartTime),
                                                      new XElement("endTime", EndTime),
                                                      new XElement("complete", Complete.ToString()),
                                                      new XElement("is_temp", IsTemporary.ToString()),
                                                      new XElement("is_readonly", IsReadOnly.ToString())
                                                      ));

            _statusLock.LockOperation(() =>
            {
                using (Stream stream = FileSystemHelpers.CreateFile(_statusFile))
                {
                    document.Save(stream);
                }

                OperationManager.Attempt(() =>
                {
                    // Used for ETAG
                    if (FileSystemHelpers.FileExists(_activeFile))
                    {
                        FileSystemHelpers.SetLastWriteTimeUtc(_activeFile, DateTime.UtcNow);
                    }
                    else
                    {
                        FileSystemHelpers.WriteAllText(_activeFile, String.Empty);
                    }
                });

                OperationManager.Attempt(() =>
                {
                    // enable the feature thru configuration
                    if (ScmHostingConfigurations.DeploymentStatusCompleteFileEnabled && Complete)
                    {
                        FileSystemHelpers.CopyFile(_statusFile, _statusCompleteFile);
                    }
                    else if (FileSystemHelpers.FileExists(_statusCompleteFile))
                    {
                        FileSystemHelpers.DeleteFile(_statusCompleteFile);
                    }
                });
            }, "Updating deployment status", DeploymentStatusManager.LockTimeout);
        }
예제 #3
0
        private void SaveInitialDeploymentManifest()
        {
            // Delete any existing one for robustness
            string firstDeploymentManifest = Path.Combine(_environment.SiteRootPath, Constants.FirstDeploymentManifestFileName);

            FileSystemHelpers.DeleteFileSafe(firstDeploymentManifest);

            // Write the new file
            string activeDeploymentId = _status.ActiveDeploymentId;

            if (!String.IsNullOrEmpty(activeDeploymentId))
            {
                string activeDeploymentManifest = Path.Combine(_environment.DeploymentsPath, activeDeploymentId, Constants.ManifestFileName);
                if (FileSystemHelpers.FileExists(activeDeploymentManifest))
                {
                    FileSystemHelpers.CopyFile(activeDeploymentManifest, firstDeploymentManifest, overwrite: true);
                }
            }
        }