public async Task <VoidOperationResult> PushTaskAsync(BuildTask buildTask)
        {
            using var scope = logger.BeginScope($"[Agent {agentUri}");

            logger.LogInformation("Sending request POST /task/push to agent");

            var request = new HttpRequestMessage(HttpMethod.Post, new Uri(agentUri, "/task/push"));

            request.Headers.Accept.Clear();
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var bodyString = JsonConvert.SerializeObject(buildTask);

            request.Content = new StringContent(bodyString, Encoding.UTF8, "application/json");

            var responseMessage = await httpClient.SendAsync(request);

            logger.LogInformation($"Received response with status code {responseMessage.StatusCode} from agent");

            if ((int)responseMessage.StatusCode < 200 || (int)responseMessage.StatusCode > 299)
            {
                return(VoidOperationResult.Failed("Something gone wrong. Check agent's logs"));
            }

            var body = await responseMessage.Content.ReadAsStringAsync();

            if (string.IsNullOrWhiteSpace(body))
            {
                return(VoidOperationResult.Failed("Agent did not return value"));
            }


            return(JsonConvert.DeserializeObject <VoidOperationResult>(body));
        }
Пример #2
0
        private async Task <VoidOperationResult> BuildAgentAsync(GitRepository agentRepository)
        {
            var args = new ShellRunnerArgs(agentRepository.Directory,
                                           "docker", false, $"build -f {Path.Combine("Elevator.Agent", "Dockerfile")} -t agent .");
            var buildAgentResult = await shellRunner.RunAsync(args);

            if (!buildAgentResult.IsSuccessful)
            {
                return(VoidOperationResult.Failed($"Cannot build agent image. Error: '{buildAgentResult.Error}'"));
            }

            logger.LogInformation(await buildAgentResult.Value.Output.ReadToEndAsync());

            return(VoidOperationResult.Success());
        }
Пример #3
0
        public async Task <VoidOperationResult> CheckoutAsync(string branch)
        {
            using var scope = logger.BeginScope("Checkout");

            var shellRunnerArgs = new ShellRunnerArgs(Directory, "git", false, "checkout", branch);

            var checkoutProcessResult = await shellRunner.RunAsync(shellRunnerArgs);

            if (!checkoutProcessResult.IsSuccessful)
            {
                return(VoidOperationResult.Failed(checkoutProcessResult.Error));
            }

            logger.LogInformation(await checkoutProcessResult.Value.Error.ReadToEndAsync());

            return(VoidOperationResult.Success());
        }