Example #1
0
        private IEnumerable <string> AdditionalValuesFiles(RunningDeployment deployment)
        {
            var variables             = deployment.Variables;
            var packageReferenceNames = variables.GetIndexes(Deployment.SpecialVariables.Packages.PackageCollection);

            foreach (var packageReferenceName in packageReferenceNames)
            {
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageReferenceName);
                var paths = variables.GetPaths(SpecialVariables.Helm.Packages.ValuesFilePath(packageReferenceName));

                foreach (var providedPath in paths)
                {
                    var packageId    = variables.Get(Deployment.SpecialVariables.Packages.PackageId(packageReferenceName));
                    var version      = variables.Get(Deployment.SpecialVariables.Packages.PackageVersion(packageReferenceName));
                    var relativePath = Path.Combine(sanitizedPackageReferenceName, providedPath);
                    var files        = fileSystem.EnumerateFilesWithGlob(deployment.CurrentDirectory, relativePath).ToList();
                    if (!files.Any())
                    {
                        throw new CommandException($"Unable to find file `{providedPath}` for package {packageId} v{version}");
                    }

                    foreach (var file in files)
                    {
                        var relative = file.Substring(Path.Combine(deployment.CurrentDirectory, sanitizedPackageReferenceName).Length);
                        Log.Info($"Including values file `{relative}` from package {packageId} v{version}");
                        yield return(Path.GetFullPath(file));
                    }
                }
            }
        }
        public void SetUp()
        {
            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any <string>()).Returns(c => c.Arg <string>().Replace("!", ""));

            variables      = new CalamariVariables();
            extractPackage = new ExtractPackage(Substitute.For <ICombinedPackageExtractor>(), fileSystem, variables, new InMemoryLog());
        }
        public void SetUp()
        {
            extractor = Substitute.For <IPackageExtractor>();

            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any <string>()).Returns(c => c.Arg <string>().Replace("!", ""));

            variables  = new CalamariVariableDictionary();
            convention = new ExtractPackageToApplicationDirectoryConvention(extractor, fileSystem);
        }
Example #4
0
        string PackageDirectory(string packageReferenceName)
        {
            var packageRoot = packageReferenceName;

            if (string.IsNullOrEmpty(packageReferenceName))
            {
                packageRoot = variables.Get(PackageVariables.IndexedPackageId(packageReferenceName ?? ""));
            }
            return(fileSystem.RemoveInvalidFileNameChars(packageRoot ?? string.Empty));
        }
        public void SetUp()
        {
            extractor = Substitute.For<IPackageExtractor>();
            extractor.GetMetadata(PackageLocation).Returns(new PackageMetadata { Id = "Acme.Web", Version = "1.0.0" });

            fileSystem = Substitute.For<ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any<string>()).Returns(c => c.Arg<string>().Replace("!", ""));

            variables = new CalamariVariableDictionary();
            convention = new ExtractPackageToApplicationDirectoryConvention(extractor, fileSystem, new SystemSemaphore());
        }
        static string AppendTenantNameIfProvided(ICalamariFileSystem fileSystem, VariableDictionary variables, string root)
        {
            var tenant = variables.Get(SpecialVariables.Deployment.Tenant.Name);

            if (!string.IsNullOrWhiteSpace(tenant))
            {
                tenant = fileSystem.RemoveInvalidFileNameChars(tenant);
                root   = Path.Combine(root, tenant);
            }

            return(root);
        }
        string AppendEnvironmentNameIfProvided(VariableDictionary variables, string root)
        {
            var environment = variables.Get(SpecialVariables.Environment.Name);

            if (!string.IsNullOrWhiteSpace(environment))
            {
                environment = fileSystem.RemoveInvalidFileNameChars(environment);
                root        = Path.Combine(root, environment);
            }

            return(root);
        }
Example #8
0
        static string AppendEnvironmentNameIfProvided(ICalamariFileSystem fileSystem, IVariables variables, string root)
        {
            var environment = variables.Get(DeploymentEnvironment.Name);

            if (!string.IsNullOrWhiteSpace(environment))
            {
                environment = fileSystem.RemoveInvalidFileNameChars(environment);
                root        = Path.Combine(root, environment);
            }

            return(root);
        }
        public void SetUp()
        {
            extractor = Substitute.For <IPackageExtractor>();
            extractor.GetMetadata(PackageLocation).Returns(new PackageMetadata {
                Id = "Acme.Web", Version = "1.0.0"
            });

            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any <string>()).Returns(c => c.Arg <string>().Replace("!", ""));

            variables  = new CalamariVariableDictionary();
            convention = new ExtractPackageToApplicationDirectoryConvention(extractor, fileSystem, new SystemSemaphore());
        }
        IEnumerable <string> AdditionalValuesFiles(RunningDeployment deployment)
        {
            var variables             = deployment.Variables;
            var packageReferenceNames = variables.GetIndexes(PackageVariables.PackageCollection);

            foreach (var packageReferenceName in packageReferenceNames)
            {
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageReferenceName);
                var paths = variables.GetPaths(SpecialVariables.Helm.Packages.ValuesFilePath(packageReferenceName));

                foreach (var providedPath in paths)
                {
                    var packageId    = variables.Get(PackageVariables.IndexedPackageId(packageReferenceName));
                    var version      = variables.Get(PackageVariables.IndexedPackageVersion(packageReferenceName));
                    var relativePath = Path.Combine(sanitizedPackageReferenceName, providedPath);
                    var files        = fileSystem.EnumerateFilesWithGlob(deployment.CurrentDirectory, relativePath).ToList();

                    if (!files.Any() && string.IsNullOrEmpty(packageReferenceName)) // Chart archives have chart name root directory
                    {
                        log.Verbose($"Unable to find values files at path `{providedPath}`. " +
                                    $"Chart package contains root directory with chart name, so looking for values in there.");
                        var chartRelativePath = Path.Combine(fileSystem.RemoveInvalidFileNameChars(packageId), relativePath);
                        files = fileSystem.EnumerateFilesWithGlob(deployment.CurrentDirectory, chartRelativePath).ToList();
                    }

                    if (!files.Any())
                    {
                        throw new CommandException($"Unable to find file `{providedPath}` for package {packageId} v{version}");
                    }

                    foreach (var file in files)
                    {
                        var relative = file.Substring(Path.Combine(deployment.CurrentDirectory, sanitizedPackageReferenceName).Length);
                        log.Info($"Including values file `{relative}` from package {packageId} v{version}");
                        yield return(Path.GetFullPath(file));
                    }
                }
            }
        }
Example #11
0
        void StagePackageReferences(RunningDeployment deployment)
        {
            var variables = deployment.Variables;

            // No need to check for "default" package since it gets extracted in the current directory in previous step.
            var packageReferenceNames = variables.GetIndexes(PackageVariables.PackageCollection)
                                        .Where(i => !string.IsNullOrEmpty(i));

            foreach (var packageReferenceName in packageReferenceNames)
            {
                Log.Verbose($"Considering '{packageReferenceName}' for extraction");
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageReferenceName);

                var packageOriginalPath = variables.Get(PackageVariables.IndexedOriginalPath(packageReferenceName));

                if (string.IsNullOrWhiteSpace(packageOriginalPath))
                {
                    Log.Info($"Package '{packageReferenceName}' was not acquired or does not require staging");
                    continue;
                }

                packageOriginalPath = Path.GetFullPath(variables.Get(PackageVariables.IndexedOriginalPath(packageReferenceName)));

                // In the case of container images, the original path is not a file-path.  We won't try and extract or move it.
                if (!fileSystem.FileExists(packageOriginalPath))
                {
                    Log.Verbose($"Package '{packageReferenceName}' was not found at '{packageOriginalPath}', skipping extraction");
                    continue;
                }

                var shouldExtract = variables.GetFlag(PackageVariables.IndexedExtract(packageReferenceName));

                if (forceExtract || shouldExtract)
                {
                    var extractionPath = Path.Combine(deployment.CurrentDirectory, sanitizedPackageReferenceName);
                    ExtractPackage(packageOriginalPath, extractionPath);
                    Log.SetOutputVariable(SpecialVariables.Packages.ExtractedPath(packageReferenceName), extractionPath, variables);
                }
                else
                {
                    var localPackageFileName   = sanitizedPackageReferenceName + Path.GetExtension(packageOriginalPath);
                    var destinationPackagePath = Path.Combine(deployment.CurrentDirectory, localPackageFileName);
                    Log.Info($"Copying package: '{packageOriginalPath}' -> '{destinationPackagePath}'");
                    fileSystem.CopyFile(packageOriginalPath, destinationPackagePath);
                    Log.SetOutputVariable(SpecialVariables.Packages.PackageFilePath(packageReferenceName), destinationPackagePath, variables);
                    Log.SetOutputVariable(SpecialVariables.Packages.PackageFileName(packageReferenceName), localPackageFileName, variables);
                }
            }
        }
Example #12
0
        private IEnumerable <string> FileTargetFactory()
        {
            var packageReferenceNames = variables.GetIndexes(PackageVariables.PackageCollection);

            foreach (var packageReferenceName in packageReferenceNames)
            {
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageReferenceName);
                var paths = variables.GetPaths(SpecialVariables.Helm.Packages.ValuesFilePath(packageReferenceName));

                foreach (var path in paths)
                {
                    yield return(Path.Combine(sanitizedPackageReferenceName, path));
                }
            }
        }
Example #13
0
        public void SetUp()
        {
            extractor = Substitute.For <IPackageExtractor>();
            extractor.GetMetadata("C:\\Package.nupkg").Returns(new PackageMetadata {
                Id = "Acme.Web", Version = "1.0.0"
            });

            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any <string>()).Returns(c => new CalamariPhysicalFileSystem().RemoveInvalidFileNameChars(c.Arg <string>()));

            variables = new VariableDictionary();
            variables.Set("env:SystemDrive", "C:");

            convention = new ExtractPackageToApplicationDirectoryConvention(extractor, fileSystem, new SystemSemaphore());
        }
Example #14
0
        void StagePackageReferences(RunningDeployment deployment)
        {
            var variables = deployment.Variables;

            var packageReferenceNames = variables.GetIndexes(SpecialVariables.Packages.PackageCollection);

            foreach (var packageReferenceName in packageReferenceNames)
            {
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageReferenceName);

                var packageOriginalPath = variables.Get(SpecialVariables.Packages.OriginalPath(packageReferenceName));

                if (string.IsNullOrWhiteSpace(packageOriginalPath))
                {
                    Log.Info($"Package '{packageReferenceName}' was not acquired");
                    continue;
                }

                packageOriginalPath = Path.GetFullPath(variables.Get(SpecialVariables.Packages.OriginalPath(packageReferenceName)));

                // In the case of container images, the original path is not a file-path.  We won't try and extract or move it.
                if (!fileSystem.FileExists(packageOriginalPath))
                {
                    continue;
                }

                var shouldExtract = variables.GetFlag(SpecialVariables.Packages.Extract(packageReferenceName));

                if (forceExtract || shouldExtract)
                {
                    var extractionPath = Path.Combine(deployment.CurrentDirectory, sanitizedPackageReferenceName);
                    ExtractPackage(packageOriginalPath, extractionPath);
                    Log.SetOutputVariable(SpecialVariables.Packages.ExtractedPath(packageReferenceName), extractionPath, variables);
                }
                else
                {
                    var localPackageFileName   = sanitizedPackageReferenceName + Path.GetExtension(packageOriginalPath);
                    var destinationPackagePath = Path.Combine(deployment.CurrentDirectory, localPackageFileName);
                    Log.Info($"Copying package: '{packageOriginalPath}' -> '{destinationPackagePath}'");
                    fileSystem.CopyFile(packageOriginalPath, destinationPackagePath);
                    Log.SetOutputVariable(SpecialVariables.Packages.PackageFilePath(packageReferenceName), destinationPackagePath, variables);
                    Log.SetOutputVariable(SpecialVariables.Packages.PackageFileName(packageReferenceName), localPackageFileName, variables);
                }
            }
        }
Example #15
0
        IEnumerable <string> FileTargetFactory()
        {
            var packageReferenceNames = variables.GetIndexes(PackageVariables.PackageCollection);

            foreach (var packageReferenceName in packageReferenceNames)
            {
                var packageRoot = packageReferenceName;
                if (string.IsNullOrEmpty(packageReferenceName))
                {
                    packageRoot = variables.Get(PackageVariables.IndexedPackageId(packageReferenceName));
                }
                var sanitizedPackageReferenceName = fileSystem.RemoveInvalidFileNameChars(packageRoot ?? String.Empty);

                yield return(Path.Combine(sanitizedPackageReferenceName, "values.yaml"));

                var paths = variables.GetPaths(SpecialVariables.Helm.Packages.ValuesFilePath(packageReferenceName));

                foreach (var path in paths)
                {
                    yield return(Path.Combine(sanitizedPackageReferenceName, path));
                }
            }
        }