Skip to content

Commit

Permalink
docs: Add information about running Testcontainers in specific CI env…
Browse files Browse the repository at this point in the history
…ironments (#895)
  • Loading branch information
HofmeisterAn authored May 17, 2023
1 parent 0526d73 commit e27f537
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/api/create_docker_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Testcontainers for .NET uses the builder design pattern to configure, create and
Builds and tags a new container image. The Dockerfile is located inside the solution (`.sln`) directory.

```csharp
await new ImageFromDockerfileBuilder()
var futureImage = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), string.Empty)
.WithDockerfile("Dockerfile")
.Build()
.CreateAsync()
.Build();

await futureImage.CreateAsync()
.ConfigureAwait(false);
```

Expand Down Expand Up @@ -42,8 +43,7 @@ Testcontainers offers convenient features to detect common directories in .NET p
```csharp
_ = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), string.Empty)
.WithDockerfile("Dockerfile")
.Build();
.WithDockerfile("Dockerfile");
```

As the tarball's content is based on `/Users/testcontainers/WeatherForecast/`, all paths inside the Dockerfile must be relative to this path. For example, Docker's `COPY` instruction copies all files inside the `WeatherForecast/` directory to the image.
Expand Down
22 changes: 22 additions & 0 deletions docs/cicd/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Continuous Integration

To use Testcontainers in your CI/CD environment, you only require Docker installed. A local installation of Docker is not mandatory; you can also use a remote Docker installation.

## Azure Pipelines

[Microsoft-hosted agents](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops) come with Docker pre-installed, there is no need for any additional configuration. It is important to note that Windows agents use the Docker Windows engine and cannot run Linux containers. If you are using Windows agents, ensure that the image you are using matches the agent's architecture and operating system version [^1)^](https://docs.docker.com/build/building/multi-platform/) [^2)^](https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility).

## GitHub Actions

GitHub-hosted runners have the same configuration as Microsoft-hosted agents. The configuration is similar to what is described in the section Azure Pipelines.

## GitLab CI/CD

To configure the Docker service in GitLab CI ([Docker-in-Docker](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker)), you need to define the service in your `.gitlab-ci.yml` file and expose the Docker host address `docker:2375` by setting the `DOCKER_HOST` environment variable.

```yml title=".gitlab-ci.yml file"
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
```
33 changes: 33 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

![Testcontainers Banner](banner.png)

```console title="Install the NuGet dependency"
dotnet add package Testcontainers
```

```csharp title="Run the Hello World container"
// Create a new instance of a container.
var container = new ContainerBuilder()
// Set the image for the container to "testcontainers/helloworld:1.1.0".
.WithImage("testcontainers/helloworld:1.1.0")
// Bind port 8080 of the container to a random port on the host.
.WithPortBinding(8080, true)
// Build the container configuration.
.Build();

// Start the container.
await container.StartAsync()
.ConfigureAwait(false);

// Create a new instance of HttpClient to send HTTP requests.
var httpClient = new HttpClient();

// Construct the request URI by specifying the scheme, hostname, assigned random host port, and the endpoint "uuid".
var requestUri = new UriBuilder(Uri.UriSchemeHttp, container.Hostname, container.GetMappedPublicPort(8080), "uuid").ToString();

// Send an HTTP GET request to the specified URI and retrieve the response as a string.
var guid = await httpClient.GetStringAsync(requestUri).ConfigureAwait(false);

// Ensure that the retrieved UUID is a valid GUID.
Debug.Assert(Guid.TryParse(guid, out _));
```

<p style="text-align:center">
<strong>Not using .NET? Here are other supported languages!</strong>
</p>
Expand Down Expand Up @@ -35,6 +66,8 @@ Testcontainers for .NET is a library to support tests with throwaway instances o

Choose from existing pre-configured modules and start containers within a second, to support and run your tests. Or create your own container images with Dockerfiles and run your containers and tests immediately afterward.

For more detailed instructions and guidance, please refer to the Testcontainers' [Getting Started](https://testcontainers.com/guides/introducing-testcontainers/) guide. If you are specifically interested in using Testcontainers for .NET, you find a dedicated follow-up guide [here](https://testcontainers.com/guides/getting-started-with-testcontainers-for-dotnet/). These resources will provide you with comprehensive information to help you get started and make the most out of Testcontainers.

## Supported operating systems

Testcontainers supports Windows, Linux, and macOS as host systems. Linux Docker containers are supported on all three operating systems. Native Windows Docker containers are only supported on Windows. Windows requires the host operating system version to match the container operating system version. You will find further information about Windows container version compatibility [here][windows-container-version-compatibility].
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ markdown_extensions:
- pymdownx.superfences
nav:
- index.md
- cicd/index.md
- custom_configuration/index.md
- api/create_docker_image.md
- api/create_docker_container.md
Expand Down

0 comments on commit e27f537

Please sign in to comment.