Skip to content

Commit

Permalink
Implemented small improvements based on feedback (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhamburg authored Jan 11, 2022
1 parent 349aeae commit 78847de
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 151 deletions.
24 changes: 22 additions & 2 deletions Airbyte.Cdk/InitCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ await AnsiConsole.Status()
await CheckDotnet();
await CheckDocker();
await CheckIfDockerIsRunning();
});

string connectorname = AnsiConsole.Ask<string>("Connector name:");
Expand All @@ -52,9 +53,9 @@ await AnsiConsole.Status()
var location = Path.Combine(MoveToUpperPath(Assembly.GetExecutingAssembly().Location, 5, true), "airbyte-integrations", "connectors", $"{connectortype.Split('-')[0]}-{connectorname}");
if (location.Any(Path.GetInvalidPathChars().Contains))
throw new Exception($"Path is invalid: " + location);
//if (!AnsiConsole.Confirm("Is this destination correct? " + location))
// return;

if (Directory.Exists(location))
throw new Exception($"Destination path already exists: {location}");
var dir = Directory.CreateDirectory(location);

await AnsiConsole.Status()
Expand Down Expand Up @@ -318,6 +319,25 @@ private static async Task CheckDocker()
}
}

private static async Task CheckIfDockerIsRunning()
{
ToConsole(Check, "Validating Docker is running...");
var stdOutBuffer = new StringBuilder();
var stdOutError = new StringBuilder();
var cmd = Cli.Wrap("docker")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdOutError))
.WithValidation(CommandResultValidation.None)
.WithArguments("version") | stdOutBuffer;
await cmd.ExecuteAsync();
if(stdOutError.Length == 0)
ToConsole(Check, "Docker is running...", Emoji.Known.CheckMark);
else
{
ToConsole(Check, "Docker is running...", Emoji.Known.CrossMark);
throw new Exception("Docker is currently not running, please start docker first!");
}
}

private static void ToConsole(params string[] lines) => AnsiConsole.MarkupLine(string.Concat(lines));
}
}
28 changes: 28 additions & 0 deletions Airbyte.Cdk/Publish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static async Task Process(PublishOptions options)
throw new Exception("Could not acquire semver from changelog");

await CheckDocker();
await CheckIfDockerIsRunning();
if (!await TryBuildAndPush(connectorpath, semver, image, !options.IsBuildOnly))
throw new Exception("Failed to build and publish connector image");
}
Expand Down Expand Up @@ -112,6 +113,10 @@ private static string[] GetConnectorsFromChanges(string[] filechanges) =>
filechanges.Where(x => x.StartsWith("airbyte-integrations/connectors/"))
.Select(x => x.Split("connectors/").Last().Split("/").First()).Distinct().ToArray();

/// <summary>
/// TODO: this should be a generic check, InitCli has the same implementation
/// </summary>
/// <exception cref="Exception"></exception>
private static async Task CheckDocker()
{
ToConsole(Check, "Validating Docker...");
Expand All @@ -126,6 +131,29 @@ private static async Task CheckDocker()
throw new Exception("Could not find docker, please download at: https://docs.docker.com/get-docker/");
}
}

/// <summary>
/// TODO: this should be a generic check, InitCli has the same implementation
/// </summary>
/// <exception cref="Exception"></exception>
private static async Task CheckIfDockerIsRunning()
{
ToConsole(Check, "Validating Docker is running...");
var stdOutBuffer = new StringBuilder();
var stdOutError = new StringBuilder();
var cmd = Cli.Wrap("docker")
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdOutError))
.WithValidation(CommandResultValidation.None)
.WithArguments("version") | stdOutBuffer;
await cmd.ExecuteAsync();
if(stdOutError.Length == 0)
ToConsole(Check, "Docker is running...", Emoji.Known.CheckMark);
else
{
ToConsole(Check, "Docker is running...", Emoji.Known.CrossMark);
throw new Exception("Docker is currently not running, please start docker first!");
}
}

private static async Task<bool> TryBuildAndPush(string folderpath, string semver, string connectorname,
bool pushimages)
Expand Down
Loading

0 comments on commit 78847de

Please sign in to comment.