Example #1
0
        public async Task TyeBuild_SinglePhase_ExistingDockerfile()
        {
            var projectName = "single-phase-dockerfile";
            var environment = "production";
            var imageName   = "test/single-phase-dockerfile";

            await DockerAssert.DeleteDockerImagesAsync(output, imageName);

            using var projectDirectory = CopyTestProjectDirectory(projectName);
            Assert.True(File.Exists(Path.Combine(projectDirectory.DirectoryPath, "Dockerfile")), "Dockerfile should exist.");


            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            application.Registry = new ContainerRegistry("test");

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                var publishOutput = Assert.Single(application.Services.Single().Outputs.OfType <ProjectPublishOutput>());
                Assert.False(Directory.Exists(publishOutput.Directory.FullName), $"Directory {publishOutput.Directory.FullName} should be deleted.");

                await DockerAssert.AssertImageExistsAsync(output, imageName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, imageName);
            }
        }
Example #2
0
        public async Task FrontendBackendBuildTest()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test/backend");

            await DockerAssert.DeleteDockerImagesAsync(output, "test/frontend");

            var projectName = "frontend-backend";
            var environment = "production";

            using var projectDirectory = CopyTestProjectDirectory(projectName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            application.Registry = new ContainerRegistry("test");

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                await DockerAssert.AssertImageExistsAsync(output, "test/backend");

                await DockerAssert.AssertImageExistsAsync(output, "test/frontend");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test/backend");

                await DockerAssert.DeleteDockerImagesAsync(output, "test/frontend");
            }
        }
Example #3
0
        public async Task SingleProjectGenerateTest()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");

            var projectName = "single-project";
            var environment = "production";

            using var projectDirectory = CopyTestProjectDirectory(projectName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            // Need to add docker registry for generate
            application.Registry = new ContainerRegistry("test");

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{projectName}-generate-{environment}.yaml"));

                var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{projectName}.yaml");

                YamlAssert.Equals(expectedContent, content, output);

                await DockerAssert.AssertImageExistsAsync(output, "test/test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");
            }
        }
Example #4
0
        public async Task Generate_NamedBinding()
        {
            var applicationName = "generate-named-binding";
            var projectName     = "frontend";
            var environment     = "production";

            await DockerAssert.DeleteDockerImagesAsync(output, projectName);

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory(applicationName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{applicationName}-generate-{environment}.yaml"));

                var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.yaml");

                YamlAssert.Equals(expectedContent, content, output);

                await DockerAssert.AssertImageExistsAsync(output, projectName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, projectName);
            }
        }
Example #5
0
        public async Task Generate_DaprApplication()
        {
            var applicationName = "dapr_test_application";
            var projectName     = "dapr_test_project";
            var environment     = "production";

            await DockerAssert.DeleteDockerImagesAsync(output, projectName);

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory("dapr");

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content         = File.ReadAllText(Path.Combine(projectDirectory.DirectoryPath, $"{applicationName}-generate-{environment}.yaml"));
                var expectedContent = File.ReadAllText($"testassets/generate/dapr.yaml");

                Assert.Equal(expectedContent.NormalizeNewLines(), content.NormalizeNewLines());

                await DockerAssert.AssertImageExistsAsync(output, projectName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, projectName);
            }
        }
Example #6
0
        public async Task SingleProjectGenerateTest()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");

            var projectName = "single-project";
            var environment = "production";

            var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", projectName));

            using var tempDirectory = TempDirectory.Create();
            DirectoryCopy.Copy(projectDirectory.FullName, tempDirectory.DirectoryPath);

            var projectFile = new FileInfo(Path.Combine(tempDirectory.DirectoryPath, "tye.yaml"));

            var application = ConfigFactory.FromFile(projectFile);

            // Need to add docker registry for generate
            application.Registry = "test";

            try
            {
                await GenerateHost.ExecuteGenerateAsync(new OutputContext(sink, Verbosity.Debug), application, environment, interactive : false);

                // name of application is the folder
                var content         = File.ReadAllText(Path.Combine(tempDirectory.DirectoryPath, $"{projectName}-generate-{environment}.yaml"));
                var expectedContent = File.ReadAllText($"testassets/generate/{projectName}.yaml");

                Assert.Equal(expectedContent, content);
                await DockerAssert.AssertImageExistsAsync(output, "test/test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");
            }
        }
Example #7
0
        public async Task FrontendBackendBuildTest()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test/backend");

            await DockerAssert.DeleteDockerImagesAsync(output, "test/frontend");

            var projectName = "frontend-backend";
            var environment = "production";

            var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", projectName));

            using var tempDirectory = TempDirectory.Create();
            DirectoryCopy.Copy(projectDirectory.FullName, tempDirectory.DirectoryPath);

            var projectFile = new FileInfo(Path.Combine(tempDirectory.DirectoryPath, "tye.yaml"));

            var application = ConfigFactory.FromFile(projectFile);

            application.Registry = "test";

            try
            {
                await BuildHost.ExecuteBuildAsync(new OutputContext(sink, Verbosity.Debug), application, environment, interactive : false);

                await DockerAssert.AssertImageExistsAsync(output, "test/backend");

                await DockerAssert.AssertImageExistsAsync(output, "test/frontend");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test/backend");

                await DockerAssert.DeleteDockerImagesAsync(output, "test/frontend");
            }
        }
Example #8
0
        public async Task GenerateWorksWithoutRegistry()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test-project");

            var projectName = "single-project";
            var environment = "production";

            var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", projectName));

            using var tempDirectory = TempDirectory.Create();
            DirectoryCopy.Copy(projectDirectory.FullName, tempDirectory.DirectoryPath);

            var projectFile = new FileInfo(Path.Combine(tempDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content         = File.ReadAllText(Path.Combine(tempDirectory.DirectoryPath, $"{projectName}-generate-{environment}.yaml"));
                var expectedContent = File.ReadAllText($"testassets/generate/{projectName}-noregistry.yaml");

                Assert.Equal(expectedContent.NormalizeNewLines(), content.NormalizeNewLines());

                await DockerAssert.AssertImageExistsAsync(output, "test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test-project");
            }
        }
Example #9
0
        public async Task TyeBuild_SinglePhase_ExistingDockerfileWithBuildArgs()
        {
            var projectName = "single-phase-dockerfile-args";
            var environment = "production";
            var imageName   = "test/web";

            await DockerAssert.DeleteDockerImagesAsync(output, imageName);

            using var projectDirectory = CopyTestProjectDirectory(projectName);
            Assert.True(File.Exists(Path.Combine(projectDirectory.DirectoryPath, "Dockerfile")), "Dockerfile should exist.");

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            application.Registry = new ContainerRegistry("test");

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                Assert.Single(application.Services.Single().Outputs.OfType <DockerImageOutput>());
                var builder   = (DockerFileServiceBuilder)application.Services.First();
                var valuePair = builder.BuildArgs.First();
                Assert.Equal("pat", valuePair.Key);
                Assert.Equal("thisisapat", valuePair.Value);

                await DockerAssert.AssertImageExistsAsync(output, imageName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, imageName);
            }
        }
Example #10
0
        public async Task BuildDoesNotRequireRegistry()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test-project");

            var projectName = "single-project";
            var environment = "production";

            var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", projectName));

            using var tempDirectory = TempDirectory.Create();
            DirectoryCopy.Copy(projectDirectory.FullName, tempDirectory.DirectoryPath);

            var projectFile   = new FileInfo(Path.Combine(tempDirectory.DirectoryPath, "tye.yaml"));
            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                await DockerAssert.AssertImageExistsAsync(output, "test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test-project");
            }
        }
Example #11
0
        public async Task TyeBuild_MultipleTargetFrameworks_YamlBuildProperties()
        {
            var projectName = "multi-targetframeworks";
            var environment = "production";
            var imageName   = "test/multi-targetframeworks";

            await DockerAssert.DeleteDockerImagesAsync(output, imageName);

            using var projectDirectory = CopyTestProjectDirectory(projectName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye-with-netcoreapp31.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile, "netcoreapp3.1");

            application.Registry = new ContainerRegistry("test");

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                var publishOutput = Assert.Single(application.Services.Single().Outputs.OfType <ProjectPublishOutput>());
                Assert.False(Directory.Exists(publishOutput.Directory.FullName), $"Directory {publishOutput.Directory.FullName} should be deleted.");

                await DockerAssert.AssertImageExistsAsync(output, imageName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, imageName);
            }
        }
Example #12
0
        public async Task Generate_Ingress()
        {
            var applicationName = "apps-with-ingress";
            var environment     = "production";

            await DockerAssert.DeleteDockerImagesAsync(output, "appa");

            await DockerAssert.DeleteDockerImagesAsync(output, "appa");

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory(applicationName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{applicationName}-generate-{environment}.yaml"));

                if (await KubectlDetector.GetKubernetesServerVersion(outputContext) >= new Version(1, 19))
                {
                    var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.1.19.yaml");

                    YamlAssert.Equals(expectedContent, content, output);
                }
                else
                {
                    var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.1.18.yaml");

                    YamlAssert.Equals(expectedContent, content, output);
                }

                await DockerAssert.AssertImageExistsAsync(output, "appa");

                await DockerAssert.AssertImageExistsAsync(output, "appb");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "appa");

                await DockerAssert.DeleteDockerImagesAsync(output, "appb");
            }
        }
Example #13
0
        public async Task BuildDoesNotRequireRegistry()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test-project");

            var projectName = "single-project";
            var environment = "production";

            using var projectDirectory = CopySampleProjectDirectory(projectName);

            var projectFile   = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));
            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await BuildHost.ExecuteBuildAsync(outputContext, application, environment, interactive : false);

                await DockerAssert.AssertImageExistsAsync(output, "test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test-project");
            }
        }