-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Generate Docker client from OpenAPI specifications
- Loading branch information
1 parent
c798c81
commit 9c54684
Showing
9 changed files
with
25,294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root = true |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="NSwag.MSBuild" Version="13.20.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<Target Name="NSwag" BeforeTargets="CoreCompile"> | ||
<Exec Command="$(NSwagExe_Net60) run NSwag.json"/> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"runtime": "Net60", | ||
"documentGenerator": { | ||
"fromDocument": { | ||
"url": "https://docs.docker.com/reference/engine/v1.43.yaml" | ||
} | ||
}, | ||
"codeGenerators": { | ||
"openApiToCSharpClient": { | ||
"className": "DockerClient", | ||
"namespace": "DockerEngine", | ||
"jsonLibrary": "SystemTextJson", | ||
"generateImmutableArrayProperties": true, | ||
"generateImmutableDictionaryProperties": true, | ||
"output": "DockerClient.cs" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace DockerEngine; | ||
|
||
public sealed class DockerClientTest : IAsyncLifetime | ||
{ | ||
private const string DockerHost = "0.0.0.0"; | ||
|
||
private const ushort DockerPort = 2375; | ||
|
||
private readonly IContainer _dockerContainer = new ContainerBuilder() | ||
.WithImage("docker:24.0.5-dind") | ||
.WithEntrypoint("dockerd") | ||
.WithCommand("--host", "tcp://" + DockerHost + ":" + DockerPort, "--debug") | ||
.WithPortBinding(DockerPort, true) | ||
.WithPrivileged(true) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("API listen on \\[::\\]:" + DockerPort)) | ||
.Build(); | ||
|
||
public System.Threading.Tasks.Task InitializeAsync() | ||
{ | ||
return _dockerContainer.StartAsync(); | ||
} | ||
|
||
public System.Threading.Tasks.Task DisposeAsync() | ||
{ | ||
return _dockerContainer.DisposeAsync().AsTask(); | ||
} | ||
|
||
[Fact] | ||
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] | ||
public async System.Threading.Tasks.Task EstablishesConnection() | ||
{ | ||
// Given | ||
const string repository = "alpine"; | ||
|
||
const string tag = "latest"; | ||
|
||
// TODO: Add support for additional schemes such as TCP, SSH, Unix, and Named Pipes (npipe) daemon socket. | ||
var dockerClient = new DockerClient(new UriBuilder(Uri.UriSchemeHttp, _dockerContainer.Hostname, _dockerContainer.GetMappedPublicPort(DockerPort)).ToString(), new HttpClient()); | ||
|
||
// When | ||
// TODO: Consider creating request and response objects instead of using a lengthy list of arguments. | ||
await dockerClient.ImageCreateAsync(repository, null, null, tag, null, string.Empty, null, null, null); | ||
|
||
// TODO: Somehow, the HTTP request terminates too early, and the Docker image cannot be used or is not available right away. The container creation operation returns: no such image. | ||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(3)); | ||
|
||
// TODO: Try to avoid wrapping the actual content within an additional (unnecessary) body type, like `Body : ContainerConfig`. | ||
var response = await dockerClient.ContainerCreateAsync(null, null, new Body { Image = repository + ":" + tag }); | ||
|
||
// Then | ||
Assert.Equal(64, response.Id.Length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2"/> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"/> | ||
<PackageReference Include="xunit" Version="2.5.0"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SolutionDir)src/DockerEngine/DockerEngine.csproj"/> | ||
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/> | ||
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
global using System; | ||
global using System.Net.Http; | ||
global using DotNet.Testcontainers.Builders; | ||
global using DotNet.Testcontainers.Commons; | ||
global using DotNet.Testcontainers.Containers; | ||
global using Xunit; |