Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 5 additions & 68 deletions .github/workflows/healthchecks_network_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,71 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
#services:
# ftp:
# image: bogem/ftp
# ports:
# - 21:21
# - 47400-47470:47400-47470
# env:
# FTP_USER: bob
# FTP_PASS: 12345
# PASV_ADDRESS: 127.0.0.1
# sftp:
# image: atmoz/sftp
# ports:
# - 22:22
# volumes:
# - ${{ github.workspace }}/build/docker-services/certificate/id_rsa.pub:/home/foo/.ssh/keys/id_rsa.pub #:ro
# - ${{ github.workspace }}/build/docker-services/sftp/users.conf:/etc/sftp/users.conf #:ro
# mail:
# image: tvial/docker-mailserver:latest
# options: --hostname mail --container_name mail --domainname healthchecks.com
# ports:
# - 25:25
# - 143:143
# - 465:465
# - 587:587
# - 993:993
# - 995:995
# env:
# SSL_TYPE: self-signed
# DMS_DEBUG: 1
# volumes:
# - ${{ github.workspace }}/build/docker-services/mail/:/tmp/docker-mailserver/
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore
run: |
dotnet restore ./src/HealthChecks.Network/HealthChecks.Network.csproj &&
dotnet restore ./test/HealthChecks.Network.Tests/HealthChecks.Network.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Network/HealthChecks.Network.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Network.Tests/HealthChecks.Network.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Network/HealthChecks.Network.csproj &&
dotnet build --no-restore ./test/HealthChecks.Network.Tests/HealthChecks.Network.Tests.csproj
#- name: Test
# run: >
# dotnet test
# ./test/HealthChecks.Network.Tests/HealthChecks.Network.Tests.csproj
# --no-restore
# --no-build
# --collect "XPlat Code Coverage"
# --results-directory .coverage
# --
# DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
#- name: Upload Coverage
# uses: codecov/codecov-action@v3
# with:
# flags: Network
# directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Network/HealthChecks.Network.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Network.Tests/HealthChecks.Network.Tests.csproj
CODECOV_FLAGS: Network
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;

namespace HealthChecks.Network.Tests.Fixtures;

public class DockerMailServerContainerFixture : IAsyncLifetime
{
protected const string Registry = "docker.io";

protected const string Image = "mailserver/docker-mailserver";

protected const string Tag = "15.1.0";

protected const int ExplicitTlsSmtpPort = 587;

protected const int ImplicitTlsSmtpPort = 465;

protected const int ExplicitTlsImapPort = 143;

protected const int ImplicitTlsImapPort = 993;

protected const string Email = "[email protected]";

protected const string Password = "password";

public IContainer? Container { get; private set; }

public (string Host, int ExplicitTlsPort, int ImplicitTlsPort, string Username, string Password) GetSmtpConnectionProperties()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}

return (
Container.Hostname,
Container.GetMappedPublicPort(ExplicitTlsSmtpPort),
Container.GetMappedPublicPort(ImplicitTlsSmtpPort),
Email,
Password
);
}

public (string Host, int ExplicitTlsPort, int ImplicitTlsPort, string Username, string Password) GetImapConnectionProperties()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}

return (
Container.Hostname,
Container.GetMappedPublicPort(ExplicitTlsImapPort),
Container.GetMappedPublicPort(ImplicitTlsImapPort),
Email,
Password
);
}

public async Task InitializeAsync() => Container = await CreateContainerAsync();

public Task DisposeAsync() => Container?.DisposeAsync().AsTask() ?? Task.CompletedTask;

protected virtual ContainerBuilder Configure(ContainerBuilder builder) => builder;

private async Task<IContainer> CreateContainerAsync()
{
var waitStrategy = Wait
.ForUnixContainer()
.UntilCommandIsCompleted("setup", "email", "add", Email, Password)
.UntilMessageIsLogged(".+ is up and running")
.UntilMessageIsLogged(".+daemon started.+")
.UntilPortIsAvailable(ImplicitTlsSmtpPort)
.UntilPortIsAvailable(ExplicitTlsSmtpPort);

var builder = new ContainerBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.WithEnvironment("OVERRIDE_HOSTNAME", "mail.beatpulse.com")
.WithEnvironment("POSTFIX_INET_PROTOCOLS", "ipv4")
.WithEnvironment("DOVECOT_INET_PROTOCOLS", "ipv4")
.WithEnvironment("ENABLE_CLAMAV", "0")
.WithEnvironment("ENABLE_AMAVIS", "0")
.WithEnvironment("ENABLE_RSPAMD", "0")
.WithEnvironment("ENABLE_OPENDKIM", "0")
.WithEnvironment("ENABLE_OPENDMARC", "0")
.WithEnvironment("ENABLE_POLICYD_SPF", "0")
.WithEnvironment("ENABLE_SPAMASSASSIN", "0")
.WithPortBinding(ExplicitTlsSmtpPort, true)
.WithPortBinding(ImplicitTlsSmtpPort, true)
.WithPortBinding(ExplicitTlsImapPort, true)
.WithPortBinding(ImplicitTlsImapPort, true)
.WithWaitStrategy(waitStrategy);

builder = Configure(builder);

var container = builder.Build();

await container.StartAsync();

return container;
}
}

public class SecureDockerMailServerContainerFixture : DockerMailServerContainerFixture
{
protected override ContainerBuilder Configure(ContainerBuilder builder)
{
var certsPath = new DirectoryInfo(Path.Combine(
Directory.GetCurrentDirectory(),
"Resources",
"docker-mailserver",
"certs"));

return builder
.WithEnvironment("SSL_TYPE", "manual")
.WithResourceMapping(certsPath, "/tmp/docker-mailserver/certs")
.WithEnvironment("SSL_CERT_PATH", "/tmp/docker-mailserver/certs/public.crt")
.WithEnvironment("SSL_KEY_PATH", "/tmp/docker-mailserver/certs/private.key");
}
}
Loading