// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace AutomationTool.Tasks
{
///
/// Parameters for a Docker-Compose task
///
public class DockerComposeDownTaskParameters
{
///
/// Path to the docker-compose file
///
[TaskParameter]
public string File { get; set; }
///
/// Arguments for the command
///
[TaskParameter(Optional = true)]
public string Arguments { get; set; }
}
///
/// Spawns Docker and waits for it to complete.
///
[TaskElement("Docker-Compose-Down", typeof(DockerComposeDownTaskParameters))]
public class DockerComposeDownTask : SpawnTaskBase
{
///
/// Parameters for this task
///
readonly DockerComposeDownTaskParameters _parameters;
///
/// Construct a Docker-Compose task
///
/// Parameters for the task
public DockerComposeDownTask(DockerComposeDownTaskParameters parameters)
{
_parameters = parameters;
}
///
/// ExecuteAsync the task.
///
/// Information about the current job
/// Set of build products produced by this node.
/// Mapping from tag names to the set of files they include
public override async Task ExecuteAsync(JobContext job, HashSet buildProducts, Dictionary> tagNameToFileSet)
{
StringBuilder arguments = new StringBuilder("--ansi never ");
if (!String.IsNullOrEmpty(_parameters.File))
{
arguments.Append($"--file {_parameters.File.QuoteArgument()} ");
}
arguments.Append("down");
if (!String.IsNullOrEmpty(_parameters.Arguments))
{
arguments.Append($" {_parameters.Arguments}");
}
Logger.LogInformation("Running docker compose {Arguments}", arguments.ToString());
using (LogIndentScope scope = new LogIndentScope(" "))
{
await SpawnTaskBase.ExecuteAsync("docker-compose", arguments.ToString());
}
}
///
/// Output this task out to an XML writer.
///
public override void Write(XmlWriter writer)
{
Write(writer, _parameters);
}
///
/// Find all the tags which are used as inputs to this task
///
/// The tag names which are read by this task
public override IEnumerable FindConsumedTagNames()
{
return Enumerable.Empty();
}
///
/// Find all the tags which are modified by this task
///
/// The tag names which are modified by this task
public override IEnumerable FindProducedTagNames()
{
return Enumerable.Empty();
}
}
}