/// <summary> /// Uploads multiple files given the globbing patterns provided by the selection properties. /// </summary> /// <param name="clientFactory"></param> /// <param name="deployment"></param> /// <param name="selection"></param> private async Task <IEnumerable <S3UploadResult> > UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection) { Guard.NotNull(deployment, "Deployment may not be null"); Guard.NotNull(selection, "Multi file selection properties may not be null"); Guard.NotNull(clientFactory, "Client factory must not be null"); var results = new List <S3UploadResult>(); var files = new RelativeGlobber((@base, pattern) => fileSystem.EnumerateFilesWithGlob(@base, pattern), deployment.StagingDirectory).EnumerateFilesWithGlob(selection.Pattern).ToList(); if (!files.Any()) { Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3."); return(results); } Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files"); var substitutionPatterns = selection.VariableSubstitutionPatterns?.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; if (substitutionPatterns.Any()) { substituteInFiles.Substitute(deployment, substitutionPatterns); } foreach (var matchedFile in files) { var request = CreateRequest(matchedFile.FilePath, $"{selection.BucketKeyPrefix}{matchedFile.MappedRelativePath}", selection); LogPutObjectRequest(matchedFile.FilePath, request); results.Add(await HandleUploadRequest(clientFactory(), request, WarnAndIgnoreException)); } return(results); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonVariableReplacer = new JsonConfigurationVariableReplacer(); ValidateArguments(); WriteVariableScriptToFile(); var conventions = new List <IConvention> { new StageScriptPackagesConvention(packageFile, fileSystem, new CombinedPackageExtractor(log)), // Substitute the script source file new DelegateInstallConvention(d => substituteInFiles.Substitute(d, ScriptFileTargetFactory(d).ToList())), // Substitute any user-specified files new DelegateInstallConvention(d => substituteInFiles.SubstituteBasedSettingsInSuppliedVariables(d)), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonVariableReplacer, fileSystem), new ExecuteScriptConvention(scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); var exitCode = variables.GetInt32(SpecialVariables.Action.Script.ExitCode); deploymentJournalWriter.AddJournalEntry(deployment, exitCode == 0, packageFile); return(exitCode.Value); }
public int Execute(string[] args) { var pathToPrimaryPackage = variables.GetPathToPrimaryPackage(fileSystem, false); var isEnableNoMatchWarningSet = variables.IsSet(PackageVariables.EnableNoMatchWarning); if (!isEnableNoMatchWarningSet && !string.IsNullOrEmpty(GetAdditionalFileSubstitutions())) { variables.Add(PackageVariables.EnableNoMatchWarning, "true"); } var runningDeployment = new RunningDeployment(pathToPrimaryPackage, variables); if (pathToPrimaryPackage != null) { extractPackage.ExtractToStagingDirectory(pathToPrimaryPackage); } var filesToSubstitute = GetFilesToSubstitute(); substituteInFiles.Substitute(runningDeployment, filesToSubstitute); InstallAsync(runningDeployment).GetAwaiter().GetResult(); return(0); }
public Task Execute(RunningDeployment context) { var filesToSubstitute = GetFilesToSubstitute(context.Variables); substituteInFiles.Substitute(context.CurrentDirectory, filesToSubstitute); return(this.CompletedTask()); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var configurationTransformer = ConfigurationTransformer.FromVariables(variables, log); var transformFileLocator = new TransformFileLocator(fileSystem, log); var replacer = new ConfigurationVariablesReplacer(variables, log); var allFileFormatReplacers = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log); var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log); ValidateArguments(); WriteVariableScriptToFile(); var conventions = new List <IConvention> { new StageScriptPackagesConvention(packageFile, fileSystem, new CombinedPackageExtractor(log)), // Substitute the script source file new DelegateInstallConvention(d => substituteInFiles.Substitute(d, ScriptFileTargetFactory(d).ToList())), // Substitute any user-specified files new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)), new ConfigurationTransformsConvention(new ConfigurationTransformsBehaviour(fileSystem, configurationTransformer, transformFileLocator, log)), new ConfigurationVariablesConvention(new ConfigurationVariablesBehaviour(fileSystem, replacer, log)), new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)), new ExecuteScriptConvention(scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); conventionRunner.RunConventions(); var exitCode = variables.GetInt32(SpecialVariables.Action.Script.ExitCode); deploymentJournalWriter.AddJournalEntry(deployment, exitCode == 0, packageFile); return(exitCode.Value); }
protected override void Execute(SubstituteInFilesCommandInputs inputs) { var targetPath = variables.GetRaw(inputs.TargetPathVariable); if (targetPath == null) { throw new CommandException($"Could not locate target path from variable {inputs.TargetPathVariable} for {nameof(SubstituteInFilesCommand)}"); } substituteInFiles.Substitute(targetPath, inputs.FilesToTarget); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); if (!File.Exists(pathToPackage)) { throw new CommandException("Could not find package file: " + pathToPackage); } ValidateRequiredVariables(); var conventions = new List <IConvention> { new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)), new StageScriptPackagesConvention(null, fileSystem, new CombinedPackageExtractor(log, variables, commandLineRunner), true), new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), // Any values.yaml files in any packages referenced by the step will automatically have variable substitution applied (we won't log a warning if these aren't present) new DelegateInstallConvention(d => substituteInFiles.Substitute(d, DefaultValuesFiles().ToList(), false)), // Any values files explicitly specified by the user will also have variable substitution applied new DelegateInstallConvention(d => substituteInFiles.Substitute(d, ExplicitlySpecifiedValuesFiles().ToList(), true)), new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new HelmUpgradeConvention(log, scriptEngine, commandLineRunner, fileSystem), new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)) }; var deployment = new RunningDeployment(pathToPackage, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); try { conventionRunner.RunConventions(); deploymentJournalWriter.AddJournalEntry(deployment, true, pathToPackage); } catch (Exception) { deploymentJournalWriter.AddJournalEntry(deployment, false, pathToPackage); throw; } return(0); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); if (!File.Exists(pathToPackage)) { throw new CommandException("Could not find package file: " + pathToPackage); } ValidateRequiredVariables(); var conventions = new List <IConvention> { new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)), new StageScriptPackagesConvention(null, fileSystem, new CombinedPackageExtractor(log), true), new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new DelegateInstallConvention(d => substituteInFiles.Substitute(d, FileTargetFactory().ToList())), new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new HelmUpgradeConvention(log, scriptEngine, commandLineRunner, fileSystem), new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)) }; var deployment = new RunningDeployment(pathToPackage, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); try { conventionRunner.RunConventions(); deploymentJournalWriter.AddJournalEntry(deployment, true, pathToPackage); } catch (Exception) { deploymentJournalWriter.AddJournalEntry(deployment, false, pathToPackage); throw; } return(0); }