Exemple #1
0
        public ChangeSetViewModel Commit(string message)
        {
            var changeSet = _repository.Commit("Test <*****@*****.**>", message);

            if (changeSet != null)
            {
                // Deploy after comitting
                _deploymentManager.Deploy(changeSet.Id);
                return(new ChangeSetViewModel(changeSet));
            }
            return(null);
        }
Exemple #2
0
        public void Deploy(HttpRequestMessage request, string id)
        {
            // Just block here to read the json payload from the body
            var result = request.Content.ReadAsAsync <JsonValue>().Result;

            using (_tracer.Step("DeploymentService.Deploy(id)"))
            {
                _deploymentLock.LockHttpOperation(() =>
                {
                    try
                    {
                        bool clean = false;

                        if (result != null)
                        {
                            JsonValue cleanValue = result["clean"];
                            clean = cleanValue != null && cleanValue.ReadAs <bool>();
                        }

                        string username = null;
                        AuthUtility.TryExtractBasicAuthUser(request, out username);

                        _deploymentManager.Deploy(id, username, clean);
                    }
                    catch (FileNotFoundException ex)
                    {
                        var response     = new HttpResponseMessage(HttpStatusCode.NotFound);
                        response.Content = new StringContent(ex.Message);
                        throw new HttpResponseException(response);
                    }
                });
            }
        }
Exemple #3
0
        public void Deploy(string id)
        {
            JObject result = GetJsonContent();

            // Just block here to read the json payload from the body
            using (_tracer.Step("DeploymentService.Deploy(id)"))
            {
                _deploymentLock.LockHttpOperation(() =>
                {
                    try
                    {
                        bool clean = false;

                        if (result != null)
                        {
                            clean = result.Value <bool>("clean");
                        }

                        string username = null;
                        AuthUtility.TryExtractBasicAuthUser(Request, out username);

                        _deploymentManager.Deploy(id, username, clean);
                    }
                    catch (FileNotFoundException ex)
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
                    }
                });
            }
        }
Exemple #4
0
        public void ReceivePack(string project)
        {
            ExecuteRpc("receive-pack", () => {
                _repository.Receive(GetInputStream(), Response.OutputStream);
            });

            ThreadPool.QueueUserWorkItem(_ => _deploymentManager.Deploy());
        }
        public static void Deploy(this IDeploymentManager deploymentManager, IRepository repository, string id, string deployer, bool clean)
        {
            ChangeSet changeSet = null;

            if (id != null)
            {
                changeSet = repository.GetChangeSet(id);
            }

            deploymentManager.Deploy(repository, changeSet, deployer, clean);
        }
        public async Task PerformDeployment(DeploymentInfo deploymentInfo)
        {
            DateTime currentMarkerFileUTC;
            DateTime nextMarkerFileUTC = _fileSystem.File.GetLastWriteTimeUtc(_markerFilePath);

            do
            {
                // save the current marker
                currentMarkerFileUTC = nextMarkerFileUTC;

                string targetBranch = _settings.GetBranch();

                using (_tracer.Step("Performing fetch based deployment"))
                {
                    // create temporary deployment before the actual deployment item started
                    // this allows portal ui to readily display on-going deployment (not having to wait for fetch to complete).
                    // in addition, it captures any failure that may occur before the actual deployment item started
                    ChangeSet   tempChangeSet;
                    IDisposable tempDeployment = _deploymentManager.CreateTemporaryDeployment(
                        Resources.ReceivingChanges,
                        out tempChangeSet,
                        deploymentInfo.TargetChangeset,
                        deploymentInfo.Deployer);

                    ILogger innerLogger = null;
                    try
                    {
                        ILogger logger = _deploymentManager.GetLogger(tempChangeSet.Id);

                        // Fetch changes from the repository
                        innerLogger = logger.Log(Resources.FetchingChanges);

                        IRepository repository = _repositoryFactory.EnsureRepository(deploymentInfo.RepositoryType);

                        try
                        {
                            await deploymentInfo.Handler.Fetch(repository, deploymentInfo, targetBranch, innerLogger);
                        }
                        catch (BranchNotFoundException)
                        {
                            // mark no deployment is needed
                            deploymentInfo.TargetChangeset = null;
                        }

                        // set to null as Deploy() below takes over logging
                        innerLogger = null;

                        // In case the commit or perhaps fetch do no-op.
                        if (deploymentInfo.TargetChangeset != null && ShouldDeploy(repository, deploymentInfo, targetBranch))
                        {
                            // Perform the actual deployment
                            var changeSet = repository.GetChangeSet(targetBranch);

                            // Here, we don't need to update the working files, since we know Fetch left them in the correct state
                            await _deploymentManager.Deploy(repository, changeSet, deploymentInfo.Deployer, clean : false, needFileUpdate : false);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (innerLogger != null)
                        {
                            innerLogger.Log(ex);
                        }

                        // In case the commit or perhaps fetch do no-op.
                        if (deploymentInfo.TargetChangeset != null)
                        {
                            IDeploymentStatusFile statusFile = _status.Open(deploymentInfo.TargetChangeset.Id);
                            if (statusFile != null)
                            {
                                statusFile.MarkFailed();
                            }
                        }

                        throw;
                    }

                    // only clean up temp deployment if successful
                    tempDeployment.Dispose();
                }

                // check marker file and, if changed (meaning new /deploy request), redeploy.
                nextMarkerFileUTC = _fileSystem.File.GetLastWriteTimeUtc(_markerFilePath);
            } while (deploymentInfo.IsReusable && currentMarkerFileUTC != nextMarkerFileUTC);
        }
Exemple #7
0
 public void Deploy(string id)
 {
     _deploymentManager.Deploy(id);
 }