예제 #1
0
        public void Rollback(int enviromentId, int applicationId)
        {
            var versions = db.Deployments
                           .Where(x => x.ApplicationId == applicationId && x.EnviromentId == enviromentId)
                           .OrderByDescending(x => x.StartDate)
                           .Select(x => x.Version)
                           .Take(2).ToList();

            if (versions.Count() < 2)
            {
                return;
            }

            var version = versions.ElementAt(1);

            using (var session = WebApiApplication.Store.OpenSession())
            {
                var deploy = new Deployment()
                {
                    EnviromentId  = enviromentId,
                    ApplicationId = applicationId,
                    Status        = Status.Queud,
                    Version       = version,
                    UserId        = User.Identity.GetUserId()
                };

                session.Save(deploy);
                session.Flush();

                BackgroundJob.Enqueue(() => DeployJob.Execute(deploy.Id));
            };
        }
예제 #2
0
        public void Deploy(int enviromentId, int applicationId, string version, [FromBody] IList <DeploymentTasksDto> tasks)
        {
            using (var session = WebApiApplication.Store.OpenSession())
            {
                var deploy = new Deployment()
                {
                    EnviromentId  = enviromentId,
                    ApplicationId = applicationId,
                    Status        = Status.Queud,
                    Version       = version,
                    UserId        = User.Identity.GetUserId()
                };

                session.Save(deploy);

                if (tasks != null && tasks.Count > 0)
                {
                    foreach (var task in tasks)
                    {
                        deploy.Tasks.Add(new DeploymentTask()
                        {
                            DeployTaskId = task.DeployTaskId,
                            DeployType   = (int)task.DeployType,
                            DeploymentId = deploy.Id
                        });
                    }
                    session.Save(deploy);
                }

                session.Flush();

                BackgroundJob.Enqueue(() => DeployJob.Execute(deploy.Id));
            };
        }
예제 #3
0
        public void WebHook(int enviromentId, int applicationId, string version, string secret)
        {
            var app = db.Applications.SingleOrDefault(x => x.Id == applicationId);

            if (app == null || app.Secret != Guid.Parse(secret))
            {
                throw new UnauthorizedAccessException("Applciation secret invalid");
            }

            using (var session = WebApiApplication.Store.OpenSession())
            {
                var deploy = new Deployment()
                {
                    EnviromentId  = enviromentId,
                    ApplicationId = applicationId,
                    Status        = Status.Queud,
                    Version       = version,
                    UserId        = new Guid().ToString()
                };

                session.Save(deploy);
                session.Flush();

                BackgroundJob.Enqueue(() => DeployJob.Execute(deploy.Id));
            };
        }
예제 #4
0
        public void WebHookLatest(int enviromentId, int applicationId, string secret)
        {
            var app = db.Applications.SingleOrDefault(x => x.Id == applicationId);

            if (app == null || app.Secret != Guid.Parse(secret))
            {
                throw new UnauthorizedAccessException("Application secret invalid");
            }

            var repos = db.DeploTasks
                        .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId)
                        .Select(x => x.Repository)
                        .ToList();

            var package = db.DeploTasks
                          .Where(x => x.EnviromentId == enviromentId && x.ApplicationId == applicationId)
                          .Select(x => x.PackageName)
                          .First();

            var version = PackageSearcher.Search(repos, package).First();

            using (var session = WebApiApplication.Store.OpenSession())
            {
                var deploy = new Deployment()
                {
                    EnviromentId  = enviromentId,
                    ApplicationId = applicationId,
                    Status        = Status.Queud,
                    Version       = version,
                    UserId        = new Guid().ToString()
                };

                session.Save(deploy);
                session.Flush();

                BackgroundJob.Enqueue(() => DeployJob.Execute(deploy.Id));
            };
        }
예제 #5
0
        public void Schedule(int enviromentId, int applicationId, string version, DateTime start, [FromBody] IList <DeploymentTasksDto> tasks)
        {
            using (var session = WebApiApplication.Store.OpenSession())
            {
                var deploy = new Deployment()
                {
                    EnviromentId  = enviromentId,
                    Status        = Status.Scheduled,
                    ApplicationId = applicationId,
                    Version       = version,
                    UserId        = User.Identity.GetUserId(),
                    StartDate     = start.ToUniversalTime(),
                    Scheduled     = true
                };

                session.Save(deploy);

                if (tasks != null && tasks.Count > 0)
                {
                    foreach (var task in tasks)
                    {
                        deploy.Tasks.Add(new DeploymentTask()
                        {
                            DeployTaskId = task.DeployTaskId,
                            DeployType   = (int)task.DeployType,
                            DeploymentId = deploy.Id
                        });
                    }
                    session.Save(deploy);
                }

                session.Flush();

                BackgroundJob.Schedule(() => DeployJob.Execute(deploy.Id), start.ToUniversalTime() - DateTime.UtcNow);
            };
        }