public static void LinuxMode() { if (FdOs.IsWindows()) { Info.LinuxDaemon(null); } }
public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false) { if (forceResolve) { _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword); } var binary = _binaryResolver.Resolve(dockerCommand, preferMachine); if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None) { return(binary.FqPath); } string cmd; if (binary.Sudo == SudoMechanism.NoPassword) { cmd = $"sudo {binary.FqPath}"; } else { cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}"; } return(cmd); }
/// <summary> /// Sets the docker daemon to linux if on windows system. /// </summary> /// <param name="host">The uri to host, may be null for default.</param> /// <param name="certificates">The certificates to communicate, many be null.</param> public static void LinuxMode(this DockerUri host, ICertificatePaths certificates = null) { if (FdOs.IsWindows()) { host.LinuxDaemon(certificates); } }
private static string ToTargetOs(string str, bool handleWindowsPathIfNeeded) { if (string.IsNullOrEmpty(str) || str.StartsWith("emb:")) { return(str); } if (!FdOs.IsWindows() || !handleWindowsPathIfNeeded) { return(str); } var match = Urldetector.Match(str); if (!match.Success) { return(str.Replace('/', '\\')); } var res = ""; int idx = 0; while (match.Success) { res += str.Substring(idx, match.Index - idx).Replace('/', '\\'); res += str.Substring(match.Index, match.Length); idx = match.Index + match.Length; match = match.NextMatch(); } res += str.Substring(idx).Replace('/', '\\'); return(res); }
public static string ResolveBinary(this string dockerCommand, DockerBinariesResolver resolver, bool preferMachine = false) { var binary = resolver.Resolve(dockerCommand, preferMachine); if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None) { return(binary.FqPath); } string cmd; if (binary.Sudo == SudoMechanism.NoPassword) { cmd = $"sudo {binary.FqPath}"; } else { cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}"; } if (string.IsNullOrEmpty(cmd)) { if (!string.IsNullOrEmpty(dockerCommand) && dockerCommand.ToLower() == "docker-machine") { throw new FluentDockerException( $"Could not find {dockerCommand} make sure it is on your path. From 2.2.0 you have to seprately install it via https://github.com/docker/machine/releases"); } throw new FluentDockerException($"Could not find {dockerCommand}, make sure it is on your path."); } return(cmd); }
public async Task StartContainersForScenarioRun(String scenarioName) { String traceFolder = FdOs.IsWindows() ? $"C:\\home\\txnproc\\trace\\{scenarioName}" : $"/home/txnproc/trace/{scenarioName}"; Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; // Setup the container names this.SecurityServiceContainerName = $"securityservice{testGuid:N}"; this.TestNetwork = this.SetupTestNetwork(); this.SecurityServiceContainer = this.SetupSecurityServiceContainer(traceFolder); this.SecurityServicePort = this.SecurityServiceContainer.ToHostExposedEndpoint("5001/tcp").Port; Func <String, String> securityServiceBaseAddressResolver = api => $"https://localhost:{this.SecurityServicePort}"; HttpClient httpClient = new HttpClient(); this.SecurityServiceClient = new SecurityServiceClient(securityServiceBaseAddressResolver, httpClient); Console.Out.WriteLine($"Security Service Port is [{this.SecurityServicePort}]"); await Task.Delay(30000).ConfigureAwait(false); ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; }
public static string ToMsysPath(this string path) { if (!FdOs.IsWindows()) { return(path); } return("//" + char.ToLower(path[0]) + path.Substring(2).Replace('\\', '/')); }
private IContainerService SetupFileProcessorContainer(String imageName, List <INetworkService> networkService, Boolean forceLatestImage = false, Int32 securityServicePort = DockerHelper.SecurityServiceDockerPort, List <String> additionalEnvironmentVariables = null) { this.Logger.LogInformation("About to Start File Processor Container"); List <String> environmentVariables = new List <String>(); environmentVariables.Add($"EventStoreSettings:ConnectionString={this.GenerateEventStoreConnectionString()}"); environmentVariables.Add($"AppSettings:SecurityService=https://{this.SecurityServiceContainerName}:{securityServicePort}"); environmentVariables.Add($"SecurityConfiguration:Authority=https://{this.SecurityServiceContainerName}:{securityServicePort}"); environmentVariables.Add($"urls=http://*:{DockerHelper.FileProcessorDockerPort}"); environmentVariables.Add($"AppSettings:TransactionProcessorApi=http://{this.TransactionProcessorContainerName}:{DockerHelper.TransactionProcessorDockerPort}"); environmentVariables.Add($"AppSettings:EstateManagementApi=http://{this.EstateManagementContainerName}:{DockerHelper.EstateManagementDockerPort}"); environmentVariables.Add($"AppSettings:ClientId={this.ClientDetails.clientId}"); environmentVariables.Add($"AppSettings:ClientSecret={this.ClientDetails.clientSecret}"); environmentVariables .Add($"ConnectionStrings:EstateReportingReadModel=\"server={this.SqlServerDetails.sqlServerContainerName};user id={this.SqlServerDetails.sqlServerUserName};password={this.SqlServerDetails.sqlServerPassword};database=EstateReportingReadModel\""); var ciEnvVar = Environment.GetEnvironmentVariable("CI"); if ((String.IsNullOrEmpty(ciEnvVar) == false) && String.Compare(ciEnvVar, Boolean.TrueString, StringComparison.InvariantCultureIgnoreCase) == 0) { // we are running in CI environmentVariables.Add($"AppSettings:TemporaryFileLocation={"/home/runner/bulkfiles/temporary"}"); environmentVariables.Add($"AppSettings:FileProfiles:0:ListeningDirectory={"/home/runner/bulkfiles/safaricom"}"); environmentVariables.Add($"AppSettings:FileProfiles:1:ListeningDirectory={"/home/runner/bulkfiles/voucher"}"); } if (additionalEnvironmentVariables != null) { environmentVariables.AddRange(additionalEnvironmentVariables); } ContainerBuilder fileProcessorContainer = new Builder().UseContainer().WithName(this.FileProcessorContainerName).WithEnvironment(environmentVariables.ToArray()) .UseImage(imageName, forceLatestImage) .ExposePort(DockerHelper.FileProcessorDockerPort) .UseNetwork(networkService.ToArray()); fileProcessorContainer = MountHostFolder(fileProcessorContainer); fileProcessorContainer = SetDockerCredentials(fileProcessorContainer); // Mount the folder to upload files String uploadFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\specflow" : $"//home//txnproc//specflow"; fileProcessorContainer.Mount(uploadFolder, "/home/txnproc/bulkfiles", MountType.ReadWrite); // Now build and return the container IContainerService builtContainer = fileProcessorContainer.Build().Start().WaitForPort($"{DockerHelper.FileProcessorDockerPort}/tcp", 30000); this.Logger.LogInformation("File Processor Container Started"); return(builtContainer); }
private static string ToTargetOs(string str) { if (string.IsNullOrEmpty(str) || str.StartsWith("emb:")) { return(str); } return(!FdOs.IsWindows() ? str : str.Replace('/', '\\')); }
public ContainerBuilder Mount(string fqHostPath, string fqContainerPath, MountType access) { var hp = FdOs.IsWindows() && CommandExtensions.IsToolbox() ? ((TemplateString)fqHostPath).Rendered.ToMsysPath() : ((TemplateString)fqHostPath).Rendered; _config.CreateParams.Volumes = _config.CreateParams.Volumes.ArrayAdd($"{hp.EscapePath()}:{fqContainerPath.EscapePath()}:{access.ToDocker()}"); return(this); }
public void UrlAtTheBeginningOfStringShallNotBeAlteredOnWindows() { if (!FdOs.IsWindows()) { return; } var tst = new TemplateString("\"https://kalle.hoobe.net/hejohå.txt\" ${TEMP}/folder/${RND}"); Assert.IsTrue(tst.Rendered.IndexOf("\"https://kalle.hoobe.net/hejohå.txt\"", StringComparison.Ordinal) == 0); }
public void UrlAtTheEndOfStringShallNotBeAlteredOnWindows() { if (!FdOs.IsWindows()) { return; } var tst = new TemplateString("/foo/bar/cmd \"https://kalle.hoobe.net/hejohå.txt\""); Assert.IsTrue(tst.Rendered.IndexOf("\"https://kalle.hoobe.net/hejohå.txt\"", StringComparison.Ordinal) == 13); }
public void UrlWithinAPowershellExpressionOnWindowsShallLeaveUrlUntouched() { if (!FdOs.IsWindows()) { return; } var tst = new TemplateString("RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"); Assert.IsTrue(tst.Rendered.IndexOf("'https://chocolatey.org/install.ps1'", StringComparison.Ordinal) == 108); }
public void UnifiedSeparatorWillBeTranslatedOnWindows() { if (!FdOs.IsWindows()) { return; } var path = new TemplateString(@"${TEMP}/folder/${RND}"); Assert.IsTrue(path.ToString().IndexOf(@"\folder\", StringComparison.Ordinal) != -1); }
public void IsIsPossibleToHaveSeveralUrlsInSameStringNotAffectingWindowsPathSubstitution() { if (!FdOs.IsWindows()) { return; } var tst = new TemplateString("/foo/bar/cmd \"https://kalle.hoobe.net/hejohå.txt\" \"http://kalle.hoobe.net/hejohå.txt\""); var res = tst.Rendered.IndexOf("\"http://kalle.hoobe.net/hejohå.txt\"", StringComparison.Ordinal); Assert.IsTrue(tst.Rendered.IndexOf("\"https://kalle.hoobe.net/hejohå.txt\"", StringComparison.Ordinal) == 13); Assert.IsTrue(tst.Rendered.IndexOf("\"http://kalle.hoobe.net/hejohå.txt\"", StringComparison.Ordinal) == 50); }
public void ProcessShallPassCustomEnvironment() { var cmd = "Resources/Scripts/envtest." + (FdOs.IsWindows() ? "bat" : "sh"); var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)cmd); var executor = new ProcessExecutor <StringListResponseParser, IList <string> >(file, string.Empty); executor.Env["FD_CUSTOM_ENV"] = "My test environment variable"; var result = executor.Execute(); Assert.AreEqual("My test environment variable", result.Data[FdOs.IsWindows() ? 1 : 0]); }
public static CommandResponse <string> ManuallyDelete(this string machine) { var path = FdOs.IsWindows() ? ((TemplateString)("${E_HOMEDRIVE}${E_HOMEPATH}/.docker/machine/machines/" + machine)).Rendered : $"~/.docker/machine/machines/{machine}"; if (!Directory.Exists(path)) { return(new CommandResponse <string>(false, new string[0], $"Machine do not exist at path {path}")); } Directory.Delete(path, recursive: true); return(new CommandResponse <string>(true, new string[0])); }
/// <summary> /// Starts the containers for scenario run. /// </summary> /// <param name="scenarioName">Name of the scenario.</param> public override async Task StartContainersForScenarioRun(String scenarioName) { String traceFolder = FdOs.IsWindows() ? $"C:\\home\\txnproc\\trace\\{scenarioName}" : $"/home/txnproc/trace/{scenarioName}"; Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; (String, String, String)dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); // Setup the container names this.SecurityServiceContainerName = $"identity-server"; this.SecurityServiceTestUIContainerName = $"securityservicetestui{testGuid:N}"; INetworkService testNetwork = this.SetupTestNetwork(); this.TestNetworks.Add(testNetwork); IContainerService securityServiceContainer = SetupSecurityServiceContainer(this.SecurityServiceContainerName, this.Logger, "securityservice", testNetwork, 5001, dockerCredentials, traceFolder); this.SecurityServicePort = securityServiceContainer.ToHostExposedEndpoint("5001/tcp").Port; IContainerService securityServiceTestUIContainer = DockerHelper.SetupSecurityServiceTestUIContainer(this.SecurityServiceTestUIContainerName, this.SecurityServiceContainerName, this.SecurityServicePort, testNetwork, ("estateUIClient", "Secret1")); this.SecurityServiceTestUIPort = securityServiceTestUIContainer.ToHostExposedEndpoint("5004/tcp").Port; Func <String, String> securityServiceBaseAddressResolver = api => $"https://localhost:{this.SecurityServicePort}"; HttpClient httpClient = new HttpClient(); this.SecurityServiceClient = new SecurityServiceClient(securityServiceBaseAddressResolver, httpClient); this.Containers.AddRange(new List <IContainerService> { securityServiceContainer, securityServiceTestUIContainer }); }
/// <summary> /// Adds the entry to hosts file. /// </summary> /// <param name="ipaddress">The ipaddress.</param> /// <param name="hostname">The hostname.</param> private static void AddEntryToHostsFile(String ipaddress, String hostname) { if (FdOs.IsWindows()) { using (StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts"))) { w.WriteLine($"{ipaddress} {hostname}"); } } else if (FdOs.IsLinux()) { DockerHelper.ExecuteBashCommand($"echo {ipaddress} {hostname} | sudo tee -a /etc/hosts"); } }
public static string GetDockerHostEnvironmentPathOrDefault() { var env = Environment.GetEnvironmentVariable(DockerHost); if (null != env) { return(env); } if (FdOs.IsWindows()) { return(CommandExtensions.IsToolbox() ? DockerHostUrlLegacy : DockerHostUrlWindowsNative); } return(CommandExtensions.IsToolbox() ? DockerHostUrlLegacy : DockerHostUrlMacOrLinux); }
public void MissingDockerComposeShallThrowExceptionInResolveBinary() { var dockerFile = Path.Combine(Directory.GetCurrentDirectory(), FdOs.IsWindows() ? "docker.exe" : "docker"); try { using (StreamWriter outputFile = new StreamWriter(dockerFile)) { outputFile.WriteLine("fake docker client to satisfy DockerBinariesResolver"); } var resolver = new DockerBinariesResolver(SudoMechanism.None, "", Directory.GetCurrentDirectory()); "docker-compose".ResolveBinary(resolver, false); Assert.Fail("Shall never reach here since it shall throw a FluentDockerException"); } finally { System.IO.File.Delete(dockerFile); } }
public void EnsureWindowsDaemonShallWork() { if (!FdOs.IsWindows()) { // Only run this test on windows devices. return; } try { _docker.WindowsDaemon(_certificates); var mode = _docker.Version(_certificates); AreEqual("windows", mode.Data.ServerOs); } finally { _docker.LinuxDaemon(_certificates); } }
/// <summary> /// Starts the containers for scenario run. /// </summary> /// <param name="scenarioName">Name of the scenario.</param> public override async Task StartContainersForScenarioRun(String scenarioName) { this.HostTraceFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; this.Logger.LogInformation($"Test Id is {testGuid}"); // Setup the container names this.SecurityServiceContainerName = $"securityservice{testGuid:N}"; this.EstateManagementContainerName = $"estate{testGuid:N}"; this.EventStoreContainerName = $"eventstore{testGuid:N}"; this.EstateReportingContainerName = $"estatereporting{testGuid:N}"; this.TransactionProcessorContainerName = $"txnprocessor{testGuid:N}"; this.TestHostContainerName = $"testhosts{testGuid:N}"; this.VoucherManagementContainerName = $"vouchermanagement{testGuid:N}"; this.FileProcessorContainerName = $"fileprocessor{testGuid:N}"; String eventStoreAddress = $"http://{this.EventStoreContainerName}"; this.ClientDetails = ("serviceClient", "Secret1"); this.SqlServerDetails = (Setup.SqlServerContainerName, Setup.SqlUserName, Setup.SqlPassword); this.DockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); INetworkService testNetwork = DockerHelper.SetupTestNetwork(); this.TestNetworks.Add(testNetwork); IContainerService eventStoreContainer = this.SetupEventStoreContainer("eventstore/eventstore:21.10.0-buster-slim", testNetwork); this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint($"{DockerHelper.EventStoreHttpDockerPort}/tcp").Port; String insecureEventStoreEnvironmentVariable = "EventStoreSettings:Insecure=true"; String persistentSubscriptionPollingInSeconds = "AppSettings:PersistentSubscriptionPollingInSeconds=10"; String internalSubscriptionServiceCacheDuration = "AppSettings:InternalSubscriptionServiceCacheDuration=0"; String operationTimeoutEnvironmentVariable = "EventStoreSettings:OperationTimeoutInSeconds=60"; IContainerService estateManagementContainer = this.SetupEstateManagementContainer("stuartferguson/estatemanagement", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, true, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration }); IContainerService securityServiceContainer = this.SetupSecurityServiceContainer("stuartferguson/securityservice", testNetwork, true); IContainerService voucherManagementContainer = this.SetupVoucherManagementContainer("stuartferguson/vouchermanagement", new List <INetworkService> { testNetwork }, true, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration }); IContainerService transactionProcessorContainer = this.SetupTransactionProcessorContainer("stuartferguson/transactionprocessor", new List <INetworkService> { testNetwork }, true, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration, $"AppSettings:VoucherManagementApi=http://{this.VoucherManagementContainerName}:{DockerHelper.VoucherManagementDockerPort}" }); IContainerService estateReportingContainer = this.SetupEstateReportingContainer("stuartferguson/estatereporting", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, true, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration, }); IContainerService testhostContainer = this.SetupTestHostContainer("stuartferguson/testhosts", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, true); IContainerService fileProcessorContainer = this.SetupFileProcessorContainer("fileprocessor", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration, operationTimeoutEnvironmentVariable }); this.Containers.AddRange(new List <IContainerService> { eventStoreContainer, estateManagementContainer, securityServiceContainer, transactionProcessorContainer, estateReportingContainer, testhostContainer, voucherManagementContainer, fileProcessorContainer }); // Cache the ports this.EstateManagementApiPort = estateManagementContainer.ToHostExposedEndpoint("5000/tcp").Port; this.EstateReportingApiPort = estateReportingContainer.ToHostExposedEndpoint("5005/tcp").Port; this.SecurityServicePort = securityServiceContainer.ToHostExposedEndpoint("5001/tcp").Port; this.FileProcessorPort = fileProcessorContainer.ToHostExposedEndpoint("5009/tcp").Port; // Setup the base address resolvers String EstateManagementBaseAddressResolver(String api) => $"http://127.0.0.1:{this.EstateManagementApiPort}"; String SecurityServiceBaseAddressResolver(String api) => $"https://127.0.0.1:{this.SecurityServicePort}"; String FileProcessorBaseAddressResolver(String api) => $"http://127.0.0.1:{this.FileProcessorPort}"; String EstateReportingBaseAddressResolver(String api) => $"http://127.0.0.1:{this.EstateReportingApiPort}"; HttpClientHandler clientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => { return(true); } }; HttpClient httpClient = new HttpClient(clientHandler); this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient); this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); this.EstateReportingClient = new EstateReportingClient(EstateReportingBaseAddressResolver, httpClient); this.FileProcessorClient = new FileProcessorClient(FileProcessorBaseAddressResolver, httpClient); await this.LoadEventStoreProjections(this.EventStoreHttpPort).ConfigureAwait(false); }
public override async Task StartContainersForScenarioRun(String scenarioName) { String traceFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; this.Logger.LogInformation($"Test Id is {testGuid}"); // Setup the container names this.SecurityServiceContainerName = $"securityservice{testGuid:N}"; this.EstateManagementContainerName = $"estate{testGuid:N}"; this.EventStoreContainerName = $"eventstore{testGuid:N}"; this.EstateReportingContainerName = $"estatereporting{testGuid:N}"; this.SubscriptionServiceContainerName = $"subscription{testGuid:N}"; String eventStoreAddress = $"http://{this.EventStoreContainerName}"; (String, String, String)dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); INetworkService testNetwork = DockerHelper.SetupTestNetwork(); this.TestNetworks.Add(testNetwork); IContainerService eventStoreContainer = DockerHelper.SetupEventStoreContainer(this.EventStoreContainerName, this.Logger, "eventstore/eventstore:20.10.0-buster-slim", testNetwork, traceFolder); this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint($"{DockerHelper.EventStoreHttpDockerPort}/tcp").Port; await Retry.For(async() => { await this.PopulateSubscriptionServiceConfiguration().ConfigureAwait(false); }, retryFor : TimeSpan.FromMinutes(2), retryInterval : TimeSpan.FromSeconds(30)); IContainerService estateManagementContainer = DockerHelper.SetupEstateManagementContainer(this.EstateManagementContainerName, this.Logger, "estatemanagement", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, traceFolder, null, this.SecurityServiceContainerName, eventStoreAddress, (Setup.SqlServerContainerName, "sa", "thisisalongpassword123!"), ("serviceClient", "Secret1")); IContainerService securityServiceContainer = DockerHelper.SetupSecurityServiceContainer(this.SecurityServiceContainerName, this.Logger, "stuartferguson/securityservice", testNetwork, traceFolder, dockerCredentials, true); IContainerService estateReportingContainer = DockerHelper.SetupEstateReportingContainer(this.EstateReportingContainerName, this.Logger, "stuartferguson/estatereporting", new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, traceFolder, dockerCredentials, this.SecurityServiceContainerName, eventStoreAddress, (Setup.SqlServerContainerName, "sa", "thisisalongpassword123!"), ("serviceClient", "Secret1"), true); this.Containers.AddRange(new List <IContainerService> { eventStoreContainer, estateManagementContainer, securityServiceContainer, estateReportingContainer, }); // Cache the ports this.EstateManagementPort = estateManagementContainer.ToHostExposedEndpoint($"{DockerHelper.EstateManagementDockerPort}/tcp").Port; this.SecurityServicePort = securityServiceContainer.ToHostExposedEndpoint($"{DockerHelper.SecurityServiceDockerPort}/tcp").Port; this.EstateReportingPort = estateReportingContainer.ToHostExposedEndpoint($"{DockerHelper.EstateReportingDockerPort}/tcp").Port; // Setup the base address resolvers String EstateManagementBaseAddressResolver(String api) => $"http://127.0.0.1:{this.EstateManagementPort}"; String SecurityServiceBaseAddressResolver(String api) => $"https://127.0.0.1:{this.SecurityServicePort}"; HttpClientHandler clientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => { return(true); } }; HttpClient httpClient = new HttpClient(clientHandler); this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient); this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); // TODO: Load up the projections await this.LoadEventStoreProjections().ConfigureAwait(false); }
/// <summary> /// The fully qualified path to the key file to use when doing SSH authentication. /// </summary> /// <param name="path">The fully qualified path to the key file for SSH communication.</param> /// <returns>Itself for fluent access.</returns> public RemoteSshHostBuilder WithSshKeyPath(TemplateString path) { _sshKeyPath = FdOs.IsWindows() ? path.Rendered.Replace('\\', '/') : path.Rendered; return(this); }
/// <summary> /// Starts the containers for scenario run. /// </summary> /// <param name="scenarioName">Name of the scenario.</param> public override async Task StartContainersForScenarioRun(String scenarioName) { String traceFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; this.Logger.LogInformation($"Test Id is {testGuid}"); // Setup the container names this.SecurityServiceContainerName = $"securityservice{testGuid:N}"; this.EventStoreContainerName = $"eventstore{testGuid:N}"; this.MessagingServiceContainerName = $"messagingservice{testGuid:N}"; String eventStoreAddress = $"http://{this.EventStoreContainerName}"; (String, String, String)dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); INetworkService testNetwork = DockerHelper.SetupTestNetwork(); this.TestNetworks.Add(testNetwork); IContainerService eventStoreContainer = DockerHelper.SetupEventStoreContainer(this.EventStoreContainerName, this.Logger, "eventstore/eventstore:20.10.0-buster-slim", testNetwork, traceFolder, true); IContainerService securityServiceContainer = DockerHelper.SetupSecurityServiceContainer(this.SecurityServiceContainerName, this.Logger, "stuartferguson/securityservice", testNetwork, traceFolder, dockerCredentials, true); IContainerService messagingServiceContainer = DockerHelper.SetupMessagingServiceContainer(this.MessagingServiceContainerName, this.Logger, "messagingservice", new List <INetworkService> { testNetwork }, traceFolder, dockerCredentials, this.SecurityServiceContainerName, eventStoreAddress, ("serviceClient", "Secret1")); this.Containers.AddRange(new List <IContainerService> { eventStoreContainer, securityServiceContainer, messagingServiceContainer }); // Cache the ports this.SecurityServicePort = securityServiceContainer.ToHostExposedEndpoint("5001/tcp").Port; this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint("2113/tcp").Port; this.MessagingServicePort = messagingServiceContainer.ToHostExposedEndpoint("5006/tcp").Port; // Setup the base address resolvers String SecurityServiceBaseAddressResolver(String api) => $"https://127.0.0.1:{this.SecurityServicePort}"; String MessagingServiceBaseAddressResolver(String api) => $"http://127.0.0.1:{this.MessagingServicePort}"; HttpClientHandler clientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => { return(true); } }; HttpClient httpClient = new HttpClient(clientHandler); this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); this.MessagingServiceClient = new MessagingServiceClient(MessagingServiceBaseAddressResolver, httpClient); }
/// <summary> /// Starts the containers for scenario run. /// </summary> /// <param name="scenarioName">Name of the scenario.</param> public override async Task StartContainersForScenarioRun(String scenarioName) { this.HostTraceFolder = null; if (DockerHelper.GetDockerEnginePlatform() == DockerEnginePlatform.Linux) { this.HostTraceFolder = FdOs.IsWindows() ? $"F:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; } Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; this.Logger.LogInformation($"Test Id is {testGuid}"); // Setup the container names this.SecurityServiceContainerName = $"sferguson.ddns.net"; this.EstateManagementContainerName = $"estate{testGuid:N}"; this.EstateReportingContainerName = $"estatereporting{testGuid:N}"; this.EstateManagementUiContainerName = $"estateadministrationui{testGuid:N}"; this.EventStoreContainerName = $"eventstore{testGuid:N}"; String eventStoreAddress = $"http://{this.EventStoreContainerName}"; this.ClientDetails = ("serviceClient", "Secret1"); this.SqlServerDetails = (Setup.SqlServerContainerName, Setup.SqlUserName, Setup.SqlPassword); this.DockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); INetworkService testNetwork = DockerHelper.SetupTestNetwork($"testnetwork{this.TestId:N}"); this.TestNetworks.Add(testNetwork); // Setup the docker image names String eventStoreImageName = "eventstore/eventstore:21.2.0-buster-slim"; String estateMangementImageName = "stuartferguson/estatemanagement"; String estateReportingImageName = "stuartferguson/estatereporting"; DockerEnginePlatform enginePlatform = DockerHelper.GetDockerEnginePlatform(); if (enginePlatform == DockerEnginePlatform.Windows) { estateMangementImageName = "stuartferguson/estatemanagementwindows"; estateReportingImageName = "stuartferguson/estatereportingwindows"; eventStoreImageName = "stuartferguson/eventstore"; } IContainerService eventStoreContainer = this.SetupEventStoreContainer(eventStoreImageName, testNetwork); this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint($"{DockerHelper.EventStoreHttpDockerPort}/tcp").Port; String insecureEventStoreEnvironmentVariable = "EventStoreSettings:Insecure=true"; String persistentSubscriptionPollingInSeconds = "AppSettings:PersistentSubscriptionPollingInSeconds=10"; String internalSubscriptionServiceCacheDuration = "AppSettings:InternalSubscriptionServiceCacheDuration=0"; List <String> estateManagementVariables = new List <String>(); estateManagementVariables.Add($"SecurityConfiguration:ApiName=estateManagement{this.TestId.ToString("N")}"); estateManagementVariables.Add($"EstateRoleName=Estate{this.TestId.ToString("N")}"); estateManagementVariables.Add($"MerchantRoleName=Merchant{this.TestId.ToString("N")}"); estateManagementVariables.AddRange(new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration }); IContainerService estateManagementContainer = this.SetupEstateManagementContainer(estateMangementImageName, new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, securityServicePort: 55001, additionalEnvironmentVariables: estateManagementVariables, forceLatestImage: true); IContainerService estateReportingContainer = this.SetupEstateReportingContainer(estateReportingImageName, new List <INetworkService> { testNetwork, Setup.DatabaseServerNetwork }, true, additionalEnvironmentVariables: new List <String> { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration }); IContainerService estateManagementUiContainer = SetupEstateManagementUIContainer(this.EstateManagementUiContainerName, this.Logger, "estateadministrationui", new List <INetworkService> { testNetwork }, this.EstateManagementContainerName, this.EstateReportingContainerName, this.HostTraceFolder, this.DockerCredentials, ($"estateUIClient{this.TestId.ToString("N")}", "Secret1")); this.Containers.AddRange(new List <IContainerService> { eventStoreContainer, estateManagementContainer, estateReportingContainer, estateManagementUiContainer }); // Cache the ports this.EstateManagementApiPort = estateManagementContainer.ToHostExposedEndpoint("5000/tcp").Port; this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint("2113/tcp").Port; this.EstateManagementUIPort = estateManagementUiContainer.ToHostExposedEndpoint("5004/tcp").Port; // Setup the base address resolvers String EstateManagementBaseAddressResolver(String api) => $"http://127.0.0.1:{this.EstateManagementApiPort}"; HttpClientHandler clientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => { return(true); } }; HttpClient httpClient = new HttpClient(clientHandler); this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient); Func <String, String> securityServiceBaseAddressResolver = api => $"https://sferguson.ddns.net:55001"; this.SecurityServiceClient = new SecurityServiceClient(securityServiceBaseAddressResolver, httpClient); await LoadEventStoreProjections().ConfigureAwait(false); }