Ejemplo n.º 1
0
        public override async Task RunAsync()
        {
            var contextOutput = new DomainOutput();

            contextOutput.OnWrite     += (text, color) => Output.Write(text, color);
            contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
            contextOutput.OnWriteRaw  += (text) => Output.WriteRaw(text);

            var context = new ServerBuildContext {
                BuildNumber       = Build.Number,
                Agents            = PhotonServer.Instance.Agents.All.ToArray(),
                Project           = Project,
                AssemblyFilename  = AssemblyFilename,
                PreBuild          = PreBuild,
                TaskName          = TaskName,
                WorkDirectory     = WorkDirectory,
                ContentDirectory  = ContentDirectory,
                BinDirectory      = BinDirectory,
                Packages          = PackageClient,
                ConnectionFactory = ConnectionFactory,
                Output            = contextOutput,
                ServerVariables   = Variables,
                Commit            = Commit,
            };

            try {
                switch (Mode)
                {
                case AgentStartModes.All:
                    await RunAll(context);

                    break;

                case AgentStartModes.Any:
                    await RunAny(context);

                    break;
                }

                Build.IsSuccess = true;
            }
            catch (OperationCanceledException) {
                Build.IsCancelled = true;
                throw;
            }
            catch (Exception error) {
                Build.Exception = error.UnfoldMessages();
                throw;
            }
            finally {
                Build.IsComplete      = true;
                Build.Duration        = DateTime.UtcNow - Build.Created;
                Build.ProjectPackages = PushedProjectPackages.ToArray();
                Build.Save();

                await Build.SetOutput(Output.GetString());

                // TODO: Save alternate version with ansi characters removed
            }
        }
Ejemplo n.º 2
0
        public override async Task RunAsync()
        {
            var assemblyFilename = Path.Combine(BinDirectory, AssemblyFilename);

            if (!File.Exists(assemblyFilename))
            {
                throw new FileNotFoundException($"The assembly file '{assemblyFilename}' could not be found!");
            }

            Domain = new ServerDomain();
            Domain.Initialize(assemblyFilename);

            using (var contextOutput = new DomainOutput()) {
                contextOutput.OnWrite     += (text, color) => Output.Write(text, color);
                contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
                contextOutput.OnWriteRaw  += (text) => Output.WriteRaw(text);

                var context = new ServerDeployContext {
                    DeploymentNumber      = Deployment.Number,
                    Project               = Project,
                    Agents                = PhotonServer.Instance.Agents.All.ToArray(),
                    ProjectPackageId      = ProjectPackageId,
                    ProjectPackageVersion = ProjectPackageVersion,
                    EnvironmentName       = EnvironmentName,
                    ScriptName            = ScriptName,
                    WorkDirectory         = WorkDirectory,
                    BinDirectory          = BinDirectory,
                    ContentDirectory      = ContentDirectory,
                    Packages              = PackageClient,
                    ConnectionFactory     = ConnectionFactory,
                    Output                = contextOutput,
                    ServerVariables       = Variables,
                };

                try {
                    await Domain.RunDeployScript(context, TokenSource.Token);

                    Deployment.IsSuccess = true;
                }
                catch (OperationCanceledException) {
                    Deployment.IsCancelled = true;
                    throw;
                }
                catch (Exception error) {
                    Deployment.Exception = error.UnfoldMessages();
                    throw;
                }
                finally {
                    Deployment.IsComplete = true;
                    Deployment.Duration   = DateTime.UtcNow - Deployment.Created;
                    //Deployment.ApplicationPackages = ?;
                    Deployment.Save();

                    await Deployment.SetOutput(Output.GetString());

                    // TODO: Save alternate version with ansi characters removed
                }
            }
        }
Ejemplo n.º 3
0
        public override async Task RunTaskAsync(string taskName, string taskSessionId)
        {
            if (taskName == null)
            {
                throw new ArgumentNullException(nameof(taskName));
            }
            if (taskSessionId == null)
            {
                throw new ArgumentNullException(nameof(taskSessionId));
            }

            var domainOutput = new DomainOutput();

            domainOutput.OnWrite     += (text, color) => Output.Write(text, color);
            domainOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
            domainOutput.OnWriteRaw  += text => Output.WriteRaw(text);

            var packageClient     = new DomainPackageClient(Packages.Boundary);
            var applicationClient = new ApplicationManagerClient(Applications.Boundary)
            {
                CurrentProjectId        = Project.Id,
                CurrentDeploymentNumber = DeploymentNumber,
            };

            var context = new AgentDeployContext {
                DeploymentNumber      = DeploymentNumber,
                Project               = Project,
                ProjectPackageId      = ProjectPackageId,
                ProjectPackageVersion = ProjectPackageVersion,
                AssemblyFilename      = AssemblyFilename,
                TaskName              = taskName,
                WorkDirectory         = WorkDirectory,
                ContentDirectory      = ContentDirectory,
                BinDirectory          = BinDirectory,
                ApplicationsDirectory = ApplicationsDirectory,
                Output          = domainOutput,
                Packages        = packageClient,
                AgentVariables  = AgentVariables,
                ServerVariables = ServerVariables,
                Applications    = applicationClient,
                EnvironmentName = EnvironmentName,
                Agent           = Agent,
            };

            try {
                var task = Task.Run(async() => {
                    await Domain.RunDeployTask(context, TokenSource.Token);
                });
                await taskList.AddOrUpdate(taskSessionId, id => task, (id, _) => task);

                await task.ContinueWith(t => {
                    taskList.TryRemove(taskSessionId, out _);
                });
            }
            catch (Exception error) {
                Exception = error;
                throw;
            }
        }
Ejemplo n.º 4
0
        public override async Task RunTaskAsync(string taskName, string taskSessionId)
        {
            using (var contextOutput = new DomainOutput()) {
                contextOutput.OnWrite     += (text, color) => Output.Write(text, color);
                contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
                contextOutput.OnWriteRaw  += text => Output.WriteRaw(text);

                var packageClient     = new DomainPackageClient(Packages.Boundary);
                var applicationClient = new ApplicationManagerClient(Applications.Boundary)
                {
                    CurrentProjectId        = Project.Id,
                    CurrentDeploymentNumber = BuildNumber, // TODO: BuildTask should not have access
                };

                var context = new AgentBuildContext {
                    Project          = Project,
                    Agent            = Agent,
                    AssemblyFilename = AssemblyFilename,
                    GitRefspec       = GitRefspec,
                    TaskName         = taskName,
                    WorkDirectory    = WorkDirectory,
                    ContentDirectory = ContentDirectory,
                    BinDirectory     = BinDirectory,
                    BuildNumber      = BuildNumber,
                    Output           = contextOutput,
                    Packages         = packageClient,
                    ServerVariables  = ServerVariables,
                    AgentVariables   = AgentVariables,
                    Applications     = applicationClient,
                    CommitHash       = CommitHash,
                    CommitAuthor     = CommitAuthor,
                    CommitMessage    = CommitMessage,
                };

                var githubSource = Project?.Source as ProjectGithubSource;
                var notifyGithub = githubSource != null && githubSource.NotifyOrigin == NotifyOrigin.Agent;

                if (notifyGithub && SourceCommit != null)
                {
                    await NotifyGithubStarted(githubSource);
                }

                try {
                    var task = Task.Run(async() => {
                        await Domain.RunBuildTask(context, TokenSource.Token);
                    });
                    await taskList.AddOrUpdate(taskSessionId, id => task, (id, _) => task);

                    await task.ContinueWith(t => {
                        taskList.TryRemove(taskSessionId, out _);
                    });
                }
                catch (Exception error) {
                    Exception = error;
                    throw;
                }
            }
        }
Ejemplo n.º 5
0
        public override async Task RunTaskAsync(string taskName, string taskSessionId)
        {
            if (taskName == null)
            {
                throw new ArgumentNullException(nameof(taskName));
            }
            if (taskSessionId == null)
            {
                throw new ArgumentNullException(nameof(taskSessionId));
            }

            var domainOutput = new DomainOutput();

            domainOutput.OnWrite     += (text, color) => Output.Write(text, color);
            domainOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
            domainOutput.OnWriteRaw  += (text) => Output.WriteRaw(text);

            var context = new AgentDeployContext {
                DeploymentNumber      = DeploymentNumber,
                Project               = Project,
                ProjectPackageId      = ProjectPackageId,
                ProjectPackageVersion = ProjectPackageVersion,
                AssemblyFilename      = AssemblyFilename,
                TaskName              = taskName,
                WorkDirectory         = WorkDirectory,
                ContentDirectory      = ContentDirectory,
                BinDirectory          = BinDirectory,
                ApplicationsDirectory = ApplicationsDirectory,
                Output          = domainOutput,
                Packages        = PackageClient,
                AgentVariables  = AgentVariables,
                ServerVariables = ServerVariables,
                EnvironmentName = EnvironmentName,
                Agent           = Agent,
            };

            try {
                await Domain.RunDeployTask(context, TokenSource.Token);
            }
            catch (Exception error) {
                Exception = error;
                throw;
            }
        }
Ejemplo n.º 6
0
        public override async Task RunTaskAsync(string taskName, string taskSessionId)
        {
            using (var contextOutput = new DomainOutput()) {
                contextOutput.OnWrite     += (text, color) => Output.Write(text, color);
                contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color);
                contextOutput.OnWriteRaw  += (text) => Output.WriteRaw(text);

                var context = new AgentBuildContext {
                    Project          = Project,
                    Agent            = Agent,
                    AssemblyFilename = AssemblyFilename,
                    GitRefspec       = GitRefspec,
                    TaskName         = taskName,
                    WorkDirectory    = WorkDirectory,
                    ContentDirectory = ContentDirectory,
                    BinDirectory     = BinDirectory,
                    BuildNumber      = BuildNumber,
                    Output           = contextOutput,
                    Packages         = PackageClient,
                    ServerVariables  = ServerVariables,
                    AgentVariables   = AgentVariables,
                };

                var githubSource       = Project?.Source as ProjectGithubSource;
                var notifyGithub       = githubSource != null && githubSource.NotifyOrigin == NotifyOrigin.Agent && Commit != null;
                CommitStatusUpdater su = null;
                CommitStatus        status;

                if (notifyGithub)
                {
                    su = new CommitStatusUpdater {
                        Username  = githubSource.Username,
                        Password  = githubSource.Password,
                        StatusUrl = Commit.StatusesUrl,
                        Sha       = Commit.Sha,
                    };

                    status = new CommitStatus {
                        State       = CommitStates.Pending,
                        Context     = "Photon",
                        Description = "Build in progress..."
                    };

                    await su.Post(status);
                }

                status = new CommitStatus {
                    Context = "Photon",
                };

                try {
                    await Domain.RunBuildTask(context, TokenSource.Token);

                    if (notifyGithub)
                    {
                        status.State       = CommitStates.Success;
                        status.Description = "Build Successful.";
                        await su.Post(status);
                    }
                }
                catch (Exception error) {
                    Exception = error;

                    if (notifyGithub)
                    {
                        status.State       = CommitStates.Failure;
                        status.Description = "Build Failed!";
                        await su.Post(status);
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 7
0
        public ConfigTransform(IDomainContext context)
        {
            this.context = context;

            Output = context.Output;
        }