-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathWeatherForecastImage.cs
65 lines (51 loc) · 1.68 KB
/
WeatherForecastImage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Threading;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;
using Xunit;
namespace WeatherForecast.Tests;
[UsedImplicitly]
public sealed class WeatherForecastImage : IImage, IAsyncLifetime
{
public const ushort HttpsPort = 443;
public const string CertificateFilePath = "certificate.crt";
public const string CertificatePassword = "password";
private readonly SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1);
private readonly IImage _image = new DockerImage("localhost/testcontainers", "weather-forecast", DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString());
public async Task InitializeAsync()
{
await _semaphoreSlim.WaitAsync()
.ConfigureAwait(false);
try
{
await new ImageFromDockerfileBuilder()
.WithName(this)
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), string.Empty)
.WithDockerfile("Dockerfile")
.WithBuildArgument("RESOURCE_REAPER_SESSION_ID", ResourceReaper.DefaultSessionId.ToString("D")) // https://github.com/testcontainers/testcontainers-dotnet/issues/602.
.WithDeleteIfExists(false)
.Build()
.CreateAsync()
.ConfigureAwait(false);
}
finally
{
_semaphoreSlim.Release();
}
}
public Task DisposeAsync()
{
return Task.CompletedTask;
}
public string Repository => _image.Repository;
public string Name => _image.Name;
public string Tag => _image.Tag;
public string FullName => _image.FullName;
public string GetHostname()
{
return _image.GetHostname();
}
}