public async Task TestRegistryBuildAsync() { using (var localRegistry = new LocalRegistry(5000)) { await localRegistry.StartAsync(); var properties = new Dictionary <string, string> { ["PublishProvider"] = "FibDotNet", ["FibPublishType"] = "Push", ["FibTargetRegistry"] = "localhost:5000", ["FibAllowInsecureRegistries"] = "True", ["FibPort"] = "80" }; string propertiesString = string.Join(" ", properties.Select(kvp => $"-p:{kvp.Key}={kvp.Value}")); string arguments = $"publish {TestProjectName} {propertiesString}"; var p = Process.Start( new ProcessStartInfo("dotnet", arguments) { UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true }); p.EnableRaisingEvents = true; var stdOutTask = p.StandardOutput.ReadToEndAsync(); var stdErrTask = p.StandardError.ReadToEndAsync(); var tcs = new TaskCompletionSource <int>(); p.Exited += (sender, args) => tcs.TrySetResult(p.ExitCode); if (!p.HasExited) { await tcs.Task; } TestContext.WriteLine(await stdOutTask); TestContext.WriteLine(await stdErrTask); Assert.AreEqual(0, p.ExitCode); string imageReference = "localhost:5000/" + TestProjectName.ToLowerInvariant() + ":" + TestProjectVersion; Command.Run("docker", "pull", imageReference); string dockerPortsEnv = Command.Run("docker", "inspect", imageReference, "-f", "{{.Config.ExposedPorts}}"); Assert.That(dockerPortsEnv, Does.Contain("80/tcp")); string dockerConfigEnv = Command.Run("docker", "inspect", "-f", "{{.Config.Env}}", imageReference); Assert.That(dockerConfigEnv, Does.Contain("ASPNETCORE_URLS=http://+:80")); string history = Command.Run("docker", "history", imageReference); Assert.That(history, Does.Contain("Fib.Net.MSBuild")); Command.Run("docker", "image", "rm", imageReference); } }
public static async Task StartLocalRegistryAsync() { try { await localRegistry.StartAsync().ConfigureAwait(false); } catch (Exception e) { await TestContext.Out.WriteLineAsync(e.ToString()).ConfigureAwait(false); throw new Exception(e.ToString(), e); } }
public async Task OneTimeSetUpAsync() { await localRegistry.StartAsync().ConfigureAwait(false); }
public async Task TestOfflineAsync() { SystemPath cacheDirectory = cacheFolder.GetRoot().ToPath(); ImageReference targetImageReferenceOnline = ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-online"); ImageReference targetImageReferenceOffline = ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-offline"); FibContainerBuilder fibContainerBuilder = FibContainerBuilder.From("localhost:5001/busybox").SetEntrypoint("echo", "Hello World"); // Should fail since Fib can't build to registry offline try { await fibContainerBuilder.ContainerizeAsync( Containerizer.To(RegistryImage.Named(targetImageReferenceOffline)).SetOfflineMode(true)).ConfigureAwait(false); Assert.Fail(); } catch (InvalidOperationException ex) { Assert.AreEqual("Cannot build to a container registry in offline mode", ex.Message); } // Should fail since Fib hasn't cached the base image yet try { await fibContainerBuilder.ContainerizeAsync( Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline)) .SetBaseImageLayersCache(cacheDirectory) .SetOfflineMode(true)).ConfigureAwait(false); Assert.Fail(); } catch (IOException ex) { Assert.AreEqual( "Cannot run Fib in offline mode; localhost:5001/busybox not found in local Fib cache", ex.Message); } using (LocalRegistry tempRegistry = new LocalRegistry(5001)) { await tempRegistry.StartAsync().ConfigureAwait(false); tempRegistry.PullAndPushToLocal("busybox", "busybox"); // Run online to cache the base image await fibContainerBuilder.ContainerizeAsync( Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOnline)) .SetBaseImageLayersCache(cacheDirectory) .SetAllowInsecureRegistries(true)).ConfigureAwait(false); } // Run again in offline mode, should succeed this time await fibContainerBuilder.ContainerizeAsync( Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline)) .SetBaseImageLayersCache(cacheDirectory) .SetOfflineMode(true)).ConfigureAwait(false); // Verify output Assert.AreEqual( "Hello World\n", new Command("docker", "run", "--rm", targetImageReferenceOffline.ToString()).Run()); }