Пример #1
0
        public void Deploy(Deployment deployment)
        {
            var log = new DeploymentLogger(deployment, _session, this.GetType());
            log.Info("Beginning deployment...");

            deployment.State = DeploymentState.Running;
            _session.SaveChanges();

            try
            {
                var state = new {};
                foreach (var step in _steps)
                {
                    log.Info("Running {0}...", step.GetType().Name);
                    step.Run(deployment, new DeploymentLogger(deployment, _session, step.GetType()), state);
                }

                deployment.State = DeploymentState.Completed;
                _session.SaveChanges();
            }
            catch (Exception ex)
            {
                deployment.State = DeploymentState.Failed;
                _session.SaveChanges();

                log.ErrorException("Deployment failed.", ex);
            }
        }
        public void Run(Deployment deployment, IDeploymentLogger log, dynamic state)
        {
            bool found = false;

            foreach (var extension in Extensions)
            {
                log.Info("Looking for {0}{1}...", FileName, extension);

                string filePath = Path.Combine(deployment.ApplicationPath(), string.Concat(FileName, extension));

                if (File.Exists(filePath))
                {
                    log.Info("Executing {0}{1}...", FileName, extension);

                    found = true;

                    if (_environment.IsUnix)
                    {
                        SetUnixExecPermission(filePath);
                    }

                    ExecuteScript(filePath, log);
                    break;
                }
            }

            if (!found)
            {
                throw new FileNotFoundException("Could not find a deployment script in the application root.");
            }
        }
Пример #3
0
        public void Run(Deployment deployment, IDeploymentLogger log, dynamic state)
        {
            string path = deployment.PackagePath();
            bool download = true;

            log.Info("Checking package cache...", deployment.Url);

            if (File.Exists(path))
            {
                log.Info("Package has already been downloaded, checking hash...");

                using (var stream = File.OpenRead(path))
                {
                    if (_hasher.ValidateHash(stream, deployment.Hash))
                    {
                        log.Info("Hashes match, no need to download the package again.");
                        download = false;
                    }
                    else
                    {
                        log.Info("Hashes do NOT match, the package must be downloaded again.");
                        File.Delete(path);
                    }
                }
            }

            if (download)
            {
                log.Info("Dowloading package @ {0}...", deployment.Url);

                _webClient.DownloadFile(deployment.Url, path);
            }

            using (var stream = File.OpenRead(path))
            {
                if (!_hasher.ValidateHash(stream, deployment.Hash))
                {
                    throw new DeploymentException("The hashes did not match after downloading the package.");
                }
            }
        }