public async Task WordPressDockerComposeServiceShallShowInstallScreen() { var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)"Resources/ComposeTests/WordPress/docker-compose.yml"); // @formatter:off using (var svc = Fd .UseContainer() .UseCompose() .FromFile(file) .RemoveOrphans() .WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php") .Build().Start()) // @formatter:on { // We now have a running WordPress with a MySql database var installPage = await "http://localhost:8000/wp-admin/install.php".Wget(); Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1); Assert.AreEqual(1, svc.Hosts.Count); Assert.AreEqual(2, svc.Containers.Count); Assert.AreEqual(2, svc.Images.Count); Assert.AreEqual(5, svc.Services.Count); } }
private void AddRow(bool selected, string familyName, List <Parameter> parameters) { int col = 0; FamilyData fd; fd = new FamilyData(familyName); fd.Selected = false; foreach (Parameter p in parameters) { ParameterValue pv = new ParameterValue(p); if (Cd.ColumnSpecs[col].ColumnType == ColumnType.CHECKBOX) { Cd.ColumnSpecs[col].WidestCell = 1; } else { Cd.ColumnSpecs[col].WidestCell = pv.ParamValue.Length; } fd.ParameterValues.Add(new ParameterValue(p)); col++; } Fd.Add(fd); }
public void WaitLambdaWithReusedContainerShallGetInvoked() { _checkConnectionInvoked = false; using (var c1 = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .WithName("postgres") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ReuseIfExists() .WaitForPort("5432/tcp", TimeSpan.FromSeconds(30)) .Build() .Start()) { // Make sure to have named container running var config = c1.GetConfiguration(); AreEqual(ServiceRunningState.Running, c1.State); using (var c2 = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .WithName("postgres") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ReuseIfExists() .Wait("", (service, count) => CheckConnection(count, service)) .Build() .Start()) { IsTrue(_checkConnectionInvoked, "Is invoked even if reused container since Start drives the container state eventually to running"); } } }
public async Task ComposeWaitForCustomLambdaShallWork() { var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)"Resources/ComposeTests/WordPress/docker-compose.yml"); // @formatter:off using (Fd .UseContainer() .UseCompose() .FromFile(file) .RemoveOrphans() .Wait("wordpress", (service, cnt) => { if (cnt > 60) { throw new FluentDockerException("Failed to wait for wordpress service"); } var res = HttpExtensions.DoRequest("http://localhost:8000/wp-admin/install.php").Result; return(res.Code == HttpStatusCode.OK && res.Body.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1 ? 0 : 500); }) .Build().Start()) // @formatter:on { // Since we have waited - this shall now always work. var installPage = await "http://localhost:8000/wp-admin/install.php".Wget(); Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1); } }
public void ExportWithConditionDisposeShallWork() { var fullPath = (TemplateString)@"${TEMP}/fluentdockertest/${RND}/export.tar"; // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); // Probably the oppsite is reverse where the last statement in the using clause // would set failure = false - but this is a unit test ;) var failure = false; try { // ReSharper disable once AccessToModifiedClosure using (Fd.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ExportOnDispose(fullPath, svc => failure) .Build() .Start()) { failure = true; } IsTrue(File.Exists(fullPath)); } finally { if (File.Exists(fullPath)) { Directory.Delete(Path.GetDirectoryName(fullPath), true); } } }
public async Task VolumeMappingWithSpacesShallWork() { const string html = "<html><head>Hello World</head><body><h1>Hello world</h1></body></html>"; var hostPath = (TemplateString)@"${TEMP}/fluentdockertest/with space in path/${RND}"; Directory.CreateDirectory(hostPath); using ( var container = Fd.UseContainer() .UseImage("nginx:1.13.6-alpine") .ExposePort(80) .Mount(hostPath, "/usr/share/nginx/html", MountType.ReadOnly) .WaitForPort("80/tcp", 30000 /*30s*/) .Build() .Start()) { AreEqual(ServiceRunningState.Running, container.State); try { File.WriteAllText(Path.Combine(hostPath, "hello.html"), html); var response = await $"http://{container.ToHostExposedEndpoint("80/tcp")}/hello.html".Wget(); AreEqual(html, response); } finally { if (Directory.Exists(hostPath)) { Directory.Delete(hostPath, true); } } } }
public void BuildImageFromFileWithCopyAndRunInstructionShallWork() { using ( var image = Fd.DefineImage("mariotoffia/unittest:latest") .From("ubuntu:14.04") .Maintainer("Mario Toffia <*****@*****.**>") .Run("apt-get update") .Run("apt-get install -y software-properties-common python") .Run("add-apt-repository ppa:chris-lea/node.js") .Run("echo \"deb http://us.archive.ubuntu.com/ubuntu/ precise universe\" >> /etc/apt/sources.list") .Run("apt-get update") .Run("apt-get install -y nodejs") .Run("mkdir /var/www") .Add("emb:Ductus.FluentDocker.Tests/Ductus.FluentDocker.Tests.MultiContainerTestFiles/app.js", "/var/www/app.js") .Command("/usr/bin/node", "/var/www/app.js") .Build()) { var config = image.GetConfiguration(true); Assert.IsNotNull(config); Assert.AreEqual(2, config.Config.Cmd.Length); Assert.AreEqual("/usr/bin/node", config.Config.Cmd[0]); Assert.AreEqual("/var/www/app.js", config.Config.Cmd[1]); } }
public void VolumeShallNotDeletedWhenRemoveOnDisposeIsNotPresent() { string id = null; try { using (var vol = Fd.UseVolume("test-volume").Build()) { vol.GetConfiguration(true); // Will throw FluentDockerException if fails id = vol.Name; } var v = _docker.VolumeInspect(_certificates, id); Assert.IsTrue(v.Success); Assert.AreEqual(1, v.Data.Count); Assert.AreEqual(id, v.Data[0].Name); } finally { if (null != id) { _docker.VolumeRm(_certificates, force: true, volume: id); } } }
public void CopyBeforeDisposeContainerShallWork() { var fullPath = (TemplateString)@"${TEMP}/fluentdockertest/${RND}"; Directory.CreateDirectory(fullPath); try { using (Fd.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .CopyOnDispose("/", fullPath) .Build() .Start()) { } var files = Directory.EnumerateFiles(fullPath).ToArray(); IsTrue(files.Any(x => x.EndsWith(".dockerenv"))); } finally { if (Directory.Exists(fullPath)) { Directory.Delete(fullPath, true); } } }
public void KeepRunningsShallWorkForCompositeServices() { var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)"Resources/ComposeTests/WordPress/docker-compose.yml"); ICompositeService svc = null; IContainerService c1 = null; IContainerService c2 = null; try { svc = Fd .UseContainer() .UseCompose() .FromFile(file) .RemoveOrphans() .KeepRunning() .Build().Start(); c1 = svc.Containers.First(); c2 = svc.Containers.Skip(1).First(); svc.Dispose(); Assert.AreEqual(ServiceRunningState.Running, c1.State); Assert.AreEqual(ServiceRunningState.Running, c2.State); } finally { svc?.Dispose(); c1?.Remove(true); c2?.Remove(true); } }
public void Issue111_WaitForProcess() { using (var scope = Fd.EngineScope(EngineScopeType.Windows)) { using ( var container = Fd.DefineImage("mariotoffia/issue111").ReuseIfAlreadyExists() .From("mcr.microsoft.com/windows/servercore:ltsc2019") .Shell("powershell", "-Command", "$ErrorActionPreference = 'Stop';") .Run("Set-ExecutionPolicy Bypass -Scope Process -Force; " + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12") .Run("Invoke-WebRequest -OutFile install.ps1 https://www.chocolatey.org/install.ps1; " + "./install.ps1") .Run("choco feature enable --name=allowGlobalConfirmation") .Run("choco install python3") .Copy("Resources/Issue/111/server.py", "C:/") .ExposePorts(8000) .Command("python", "server.py") .Builder().UseContainer().UseImage("mariotoffia/issue111") .WaitForProcess("python.exe", (long)TimeSpan.FromSeconds(30).TotalMilliseconds) .Builder() .Build() .Start()) { var c = container.Containers.First(); var config = c.GetConfiguration(true); AreEqual(ServiceRunningState.Running, config.State.ToServiceState()); } } }
public void BuildAndStartContainerWithKeepContainerWillLeaveContainerInArchive() { string id; using ( var container = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .KeepContainer() .Build() .Start()) { id = container.Id; IsNotNull(id); } // We shall have the container as stopped by now. var cont = Fd.Discover() .Select(host => host.GetContainers().FirstOrDefault(x => x.Id == id)) .FirstOrDefault(container => null != container); IsNotNull(cont); cont.Remove(true); }
public void Initialize(IDictionary <string, object> settings = null) { if (null == settings) { _host = Fd.Native(); _source = "https://github.com/deviantony/docker-elk.git"; Target = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString()); return; } _source = settings.ContainsKey(SourceUrl) ? (string)settings[SourceUrl] : "https://github.com/deviantony/docker-elk.git"; Target = !settings.ContainsKey(TargetPath) ? Guid.NewGuid().ToString() : (string)settings[TargetPath]; _keepOnDispose = settings.ContainsKey(FeatureConstants.KeepOnDispose); _host = !settings.ContainsKey(FeatureConstants.HostService) ? Fd.Native() : (IHostService)settings[FeatureConstants.HostService]; if (!Path.IsPathRooted(Target)) { Target = Path.Combine(Directory.GetCurrentDirectory(), Target); } _apmServer = settings.ContainsKey(EnableApmServer) ? ((TemplateString)$"{Target}/extensions/apm-server/apm-server-compose.yml").Rendered : null; _logspout = settings.ContainsKey(EnableLogspout) ? ((TemplateString)$"{Target}/extensions/logspout/logspout-compose.yml").Rendered : null; _curator = settings.ContainsKey(EnableCurator) ? ((TemplateString)$"{Target}/extensions/curator/curator-compose.yml").Rendered : null; }
public void ExportToTarFileWhenDisposeShallWork() { var fullPath = (TemplateString)@"${TEMP}/fluentdockertest/${RND}/export.tar"; // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); try { using (Fd.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ExportOnDispose(fullPath) .Build() .Start()) { } IsTrue(File.Exists(fullPath)); } finally { if (File.Exists(fullPath)) { Directory.Delete(Path.GetDirectoryName(fullPath), true); } } }
public void ExportExploadedWhenDisposeShallWork() { var fullPath = (TemplateString)@"${TEMP}/fluentdockertest/${RND}"; Directory.CreateDirectory(fullPath); try { using (Fd.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ExportExploadedOnDispose(fullPath) .Build() .Start()) { } IsTrue(Directory.Exists(fullPath)); var files = Directory.GetFiles(fullPath).ToArray(); IsTrue(files.Any(x => x.Contains("docker-entrypoint.sh"))); } finally { if (Directory.Exists(fullPath)) { Directory.Delete(fullPath, true); } } }
static void commandHandler(Socket socket) { var ctx = new Context(); if (socket == null) { ctx.InitPipeServer(Fd.FromPosixFd(0), Fd.FromPosixFd(1)); } else { ctx.InitSocketServer(socket, SocketServerFlags.Accepted); } ctx.RegisterCommand("FOO", foo); ctx.RegisterCommand("BAR", bar); ctx.RegisterCommand("INPUT", null); ctx.RegisterCommand("OUTPUT", null); for (; ;) { try { ctx.Accept(); } catch (ErrorException ex) when(ex.Error.Code == ErrorCode.EOF) { break; } try { ctx.Process(); } catch (Exception ex) { Console.Error.WriteLine("Processing failed: {}", ex.Message); continue; } } }
public void BuildImageShallPerserveLineOrdering() { var dockerfile = Fd.Dockerfile() .UseParent("mcr.microsoft.com/windows/servercore:ltsc2019") .Shell("powershell", "-Command", "$ErrorActionPreference = 'Stop';") .Run("Set-ExecutionPolicy Bypass -Scope Process -Force; " + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12") .Run("Invoke-WebRequest -OutFile install.ps1 https://www.chocolatey.org/install.ps1; " + "./install.ps1") .Run("choco feature enable --name=allowGlobalConfirmation") .Run("choco install python3") .Copy("Resources/Issue/111/server.py", "C:/") .ExposePorts(8000) .Command("python", "server.py").ToDockerfileString(); var lines = dockerfile.Split(new[] { Environment.NewLine }, StringSplitOptions.None); Assert.AreEqual(10, lines.Length); Assert.AreEqual("FROM mcr.microsoft.com/windows/servercore:ltsc2019", lines[0]); Assert.AreEqual("SHELL [powershell-Command,$ErrorActionPreference = 'Stop';]", lines[1]); Assert.AreEqual("RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12", lines[2]); Assert.AreEqual("RUN Invoke-WebRequest -OutFile install.ps1 https://www.chocolatey.org/install.ps1; ./install.ps1", lines[3]); Assert.AreEqual("RUN choco feature enable --name=allowGlobalConfirmation", lines[4]); Assert.AreEqual("RUN choco install python3", lines[5]); Assert.AreEqual("COPY Resources/Issue/111/server.py C:/", lines[6]); Assert.AreEqual("EXPOSE 8000", lines[7]); Assert.AreEqual("CMD [pythonserver.py]", lines[8]); Assert.AreEqual(string.Empty, lines[9]); }
public void CustomResolverForContainerShallWork() { bool executedCustomResolver = false; using ( var container = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .ExposePort(5432) .UseCustomResolver(( ports, portAndProto, dockerUri) => { executedCustomResolver = true; if (null == ports || string.IsNullOrEmpty(portAndProto)) { return(null); } if (!ports.TryGetValue(portAndProto, out var endpoints)) { return(null); } if (null == endpoints || endpoints.Length == 0) { return(null); } if (CommandExtensions.IsNative()) { return(endpoints[0]); } if (CommandExtensions.IsEmulatedNative()) { return(CommandExtensions.IsDockerDnsAvailable() ? new IPEndPoint(CommandExtensions.EmulatedNativeAddress(), endpoints[0].Port) : new IPEndPoint(IPAddress.Loopback, endpoints[0].Port)); } if (Equals(endpoints[0].Address, IPAddress.Any) && null != dockerUri) { return(new IPEndPoint(IPAddress.Parse(dockerUri.Host), endpoints[0].Port)); } return(endpoints[0]); }) .WaitForPort("5432/tcp", 30000 /*30s*/) .Build() .Start()) { var state = container.GetConfiguration(true /*force*/).State.ToServiceState(); Assert.AreEqual(ServiceRunningState.Running, state); Assert.IsTrue(executedCustomResolver); } }
protected internal override void Disconnect0(int family) //unused { if (Fd == null || !Fd.Valid()) { return; // disconnect doesn't throw any exceptions } socketDisconnect(FdAccess.get(Fd)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private int checkAndReturnNativeFD() throws SocketException private int CheckAndReturnNativeFD() { if (Fd == null || !Fd.Valid()) { throw new SocketException("Socket closed"); } return(FdAccess.get(Fd)); }
protected internal override void DatagramSocketClose() { if (Fd == null || !Fd.Valid()) { return; // close doesn't throw any exceptions } socketClose(FdAccess.get(Fd)); FdAccess.set(Fd, -1); }
public async Task DockerComposePauseResumeShallWork() { var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)"Resources/ComposeTests/WordPress/docker-compose.yml"); // @formatter:off using (var svc = Fd .UseContainer() .UseCompose() .FromFile(file) .RemoveOrphans() .WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php") .Build().Start()) // @formatter:on { // We now have a running WordPress with a MySql database var installPage = await HttpExtensions.Wget("http://localhost:8000/wp-admin/install.php"); Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1); svc.Pause(); Assert.AreEqual(ServiceRunningState.Paused, svc.State); try { await HttpExtensions.Wget("http://localhost:8000/wp-admin/install.php"); Assert.Fail("The containers should be paused and thus no http get shall work"); } catch (Exception) { // We shall end up here } foreach (var container in svc.Containers) { Assert.AreEqual(ServiceRunningState.Paused, container.State); var cfg = container.GetConfiguration(true); Assert.AreEqual(ServiceRunningState.Paused, cfg.State.ToServiceState()); } svc.Start(); Assert.AreEqual(ServiceRunningState.Running, svc.State); installPage = await HttpExtensions.Wget("http://localhost:8000/wp-admin/install.php"); Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1); foreach (var container in svc.Containers) { Assert.AreEqual(ServiceRunningState.Running, container.State); var cfg = container.GetConfiguration(true); Assert.AreEqual(ServiceRunningState.Running, cfg.State.ToServiceState()); } } }
// Start is called before the first frame update void Start() { DontDestroyOnLoad(bgm); MenuHandlers.runningBgm = bgm; _splashStart = Time.realtimeSinceStartup; _sunSR = Sun.GetComponent <SpriteRenderer>(); _fdSR = Fd.GetComponent <SpriteRenderer>(); _shadowSR = Shadow.GetComponent <SpriteRenderer>(); }
public void BuildContainerRenderServiceInStoppedMode() { using ( var container = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .Build()) { AreEqual(ServiceRunningState.Stopped, container.State); } }
public void CreateSshConnectionToRemoteDockerAndCreateContainerShallWork() { using ( var container = Fd.UseHost() .UseSsh("192.168.1.34").WithName("remote-daemon") .WithSshUser("solo").WithSshKeyPath("${E_LOCALAPPDATA}/lxss/home/martoffi/.ssh/id_rsa") .UseContainer() .UseImage("postgres:9.6-alpine") .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .Build()) { Assert.AreEqual(ServiceRunningState.Stopped, container.State); } }
public void VolumeShallBeDeletedWhenRemoveOnDispose() { string id; using (var vol = Fd.UseVolume("test-volume").RemoveOnDispose().Build()) { vol.GetConfiguration(true); // Will throw FluentDockerException if fails id = vol.Name; } var v = _docker.VolumeInspect(_certificates, id); Assert.IsFalse(v.Success); }
public void SingleWaitLambdaShallGetInvoked() { _checkConnectionInvoked = false; using (var container = Fd.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .Wait("", (service, count) => CheckConnection(count, service)) .Build() .Start()) { IsTrue(_checkConnectionInvoked, "Invoked since container was created and thus run phase is executed"); } }
public void URLInCopyShallWork() { var dockerfile = Fd.Dockerfile() .UseParent("node:12.18.1") .Environment("NODE_ENV=production") .Run("npm install --production") .Copy( "https://raw.githubusercontent.com/mariotoffia/FluentDocker/master/Ductus.FluentDocker/Model/Builders/FileBuilder/CopyCommand.cs", "/server.js") .Copy("Resources/Issue/111/server.py", "/server.py") .Command("node", "server.js").ToDockerfileString(); var lines = dockerfile.Split(new[] { Environment.NewLine }, StringSplitOptions.None); }
public void ContainerWithUlimitsShallWork() { using ( var container = Fd.UseContainer() .UseImage("postgres:latest", true) .UseUlimit(Ulimit.NoFile, 2048, 2048) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .Build() .Start()) { var config = container.GetConfiguration(true); } }
public void UseStaticBuilderWillAlwaysRunDisposeOnContainer() { Fd.Container(c => c.UseContainer() .UseImage("postgres:9.6-alpine") .ExposePort(5432) .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") .WaitForPort("5432/tcp", TimeSpan.FromSeconds(30)), svc => { var config = svc.GetConfiguration(); AreEqual(ServiceRunningState.Running, svc.State); IsTrue(config.Config.Env.Any(x => x == "POSTGRES_PASSWORD=mysecretpassword")); }); }