string GetFetchScript(string workingDirectory, ScriptSyntax syntax) { AssemblyEmbeddedResources embeddedResources = new AssemblyEmbeddedResources(); string contextFile; switch (syntax) { case ScriptSyntax.Bash: contextFile = "helmFetch.sh"; break; case ScriptSyntax.PowerShell: contextFile = "HelmFetch.ps1"; break; default: throw new InvalidOperationException("No kubernetes context wrapper exists for " + syntax); } var k8sContextScriptFile = Path.Combine(workingDirectory, $"Octopus.{contextFile}"); var contextScript = embeddedResources.GetEmbeddedResourceText(Assembly.GetExecutingAssembly(), $"Calamari.Integration.Packages.Download.Scripts.{contextFile}"); fileSystem.OverwriteFile(k8sContextScriptFile, contextScript); return(k8sContextScriptFile); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); JavaRuntime.VerifyExists(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariableFiles, sensitiveVariablesPassword); var commandOutput = new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)); var commandLineRunner = new CommandLineRunner(commandOutput); var embeddedResources = new AssemblyEmbeddedResources(); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new JavaStepConvention(actionType, new JavaRunner(commandLineRunner, variables)), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(null, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(pathToPackage, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(pathToPackage)) { throw new CommandException("Could not find package file: " + pathToPackage); } Log.Info("Deploying package: " + pathToPackage); var account = new AzureAccount(variables); var fileSystem = new WindowsPhysicalFileSystem(); var embeddedResources = new AssemblyEmbeddedResources(); var azurePackageUploader = new AzurePackageUploader(log); var certificateStore = new CalamariCertificateStore(); var cloudCredentialsFactory = new SubscriptionCloudCredentialsFactory(certificateStore); var cloudServiceConfigurationRetriever = new AzureCloudServiceConfigurationRetriever(); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonVariablesReplacer = new JsonConfigurationVariableReplacer(); var conventions = new List <IConvention> { new SwapAzureDeploymentConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)), new FindCloudServicePackageConvention(fileSystem), new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem), new ExtractAzureCloudServicePackageConvention(log, fileSystem), new ChooseCloudServiceConfigurationFileConvention(fileSystem), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(log, DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfigureAzureCloudServiceConvention(account, fileSystem, cloudCredentialsFactory, cloudServiceConfigurationRetriever, certificateStore), new DelegateInstallConvention(d => substituteInFiles.SubstituteBasedSettingsInSuppliedVariables(d)), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonVariablesReplacer, fileSystem), new PackagedScriptConvention(log, DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new RePackageCloudServiceConvention(fileSystem), new UploadAzureCloudServicePackageConvention(fileSystem, azurePackageUploader, cloudCredentialsFactory), new DeployAzureCloudServicePackageConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), new PackagedScriptConvention(log, DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(pathToPackage, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
static EmbeddedResource DecryptAssemblyResource(string val, out AssemblyEmbeddedResources entry) { entry = null; string[] parts = val.Split('_'); if (parts.Length != 3) { return(null); } Encoding enc = Encoding.UTF8; string asmNameHash = parts [0]; string resNameHash = parts [1]; bool debug = parts [2] == "t"; try { _embeddedResourcesLock.EnterReadLock(); if (!_embeddedResources.TryGetValue(asmNameHash, out entry) || entry == null) { return(null); } EmbeddedResource res; if (!entry.Resources.TryGetValue(resNameHash, out res) || res == null) { #if SYSTEM_WEB_EXTENSIONS if (!debug) { return(null); } if (!entry.Resources.TryGetValue(resNameHash.Substring(0, resNameHash.Length - 1), out res)) { return(null); } #else return(null); #endif } return(res); } finally { _embeddedResourcesLock.ExitReadLock(); } }
// MUST be called with the _embeddedResourcesLock taken in the upgradeable read lock mode static AssemblyEmbeddedResources GetAssemblyEmbeddedResource(KeyedHashAlgorithm kha, Assembly assembly, string assemblyNameHash, string assemblyName) { AssemblyEmbeddedResources entry; if (!_embeddedResources.TryGetValue(assemblyNameHash, out entry) || entry == null) { try { _embeddedResourcesLock.EnterWriteLock(); entry = new AssemblyEmbeddedResources() { AssemblyName = assemblyName }; InitEmbeddedResourcesUrls(kha, assembly, assemblyName, assemblyNameHash, entry); _embeddedResources.Add(assemblyNameHash, entry); } finally { _embeddedResourcesLock.ExitWriteLock(); } } return(entry); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); JavaRuntime.VerifyExists(); var embeddedResources = new AssemblyEmbeddedResources(); var conventions = new List <IConvention> { new JavaStepConvention(actionType, new JavaRunner(commandLineRunner, variables)), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(null, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
static string GetResourceUrl (KeyedHashAlgorithm kha, Assembly assembly, string resourceName, bool notifyScriptLoaded) { string assemblyName = assembly == currAsm ? "s" : assembly.GetName ().FullName; string assemblyNameHash = GetStringHash (kha, assemblyName); string resourceNameHash = GetStringHash (kha, resourceName); bool debug = false; string url; AssemblyEmbeddedResources entry; try { _embeddedResourcesLock.EnterUpgradeableReadLock (); if (!_embeddedResources.TryGetValue (assemblyNameHash, out entry) || entry == null) { try { _embeddedResourcesLock.EnterWriteLock (); entry = new AssemblyEmbeddedResources () { AssemblyName = assemblyName }; InitEmbeddedResourcesUrls (kha, assembly, assemblyName, assemblyNameHash, entry); _embeddedResources.Add (assemblyNameHash, entry); } finally { _embeddedResourcesLock.ExitWriteLock (); } } string lookupKey; #if SYSTEM_WEB_EXTENSIONS debug = resourceName.EndsWith (".debug.js", StringComparison.OrdinalIgnoreCase); string dbgTail = debug ? "d" : String.Empty; lookupKey = resourceNameHash + (notifyScriptLoaded ? "t" : "f") + dbgTail; #else lookupKey = resourceNameHash; #endif EmbeddedResource res; if (entry.Resources.TryGetValue (lookupKey, out res) && res != null) url = res.Url; else { #if SYSTEM_WEB_EXTENSIONS if (debug) { resourceNameHash = GetStringHash (kha, resourceName.Substring (0, resourceName.Length - 9) + ".js"); lookupKey = resourceNameHash + (notifyScriptLoaded ? "t" : "f"); if (entry.Resources.TryGetValue (lookupKey, out res) && res != null) url = res.Url; else url = null; } else #endif url = null; } } finally { _embeddedResourcesLock.ExitUpgradeableReadLock (); } if (url == null) url = CreateResourceUrl (kha, assemblyName, assemblyNameHash, assembly.Location, resourceNameHash, debug, notifyScriptLoaded); return url; }
static EmbeddedResource DecryptAssemblyResource (string val, out AssemblyEmbeddedResources entry) { entry = null; string[] parts = val.Split ('_'); if (parts.Length != 3) return null; Encoding enc = Encoding.UTF8; string asmNameHash = parts [0]; string resNameHash = parts [1]; bool debug = parts [2] == "t"; try { _embeddedResourcesLock.EnterReadLock (); if (!_embeddedResources.TryGetValue (asmNameHash, out entry) || entry == null) return null; EmbeddedResource res; if (!entry.Resources.TryGetValue (resNameHash, out res) || res == null) { #if SYSTEM_WEB_EXTENSIONS if (!debug) return null; if (!entry.Resources.TryGetValue (resNameHash.Substring (0, resNameHash.Length - 1), out res)) return null; #else return null; #endif } return res; } finally { _embeddedResourcesLock.ExitReadLock (); } }
static void InitEmbeddedResourcesUrls (KeyedHashAlgorithm kha, Assembly assembly, string assemblyName, string assemblyHash, AssemblyEmbeddedResources entry) { WebResourceAttribute [] attrs = (WebResourceAttribute []) assembly.GetCustomAttributes (typeof (WebResourceAttribute), false); WebResourceAttribute attr; string apath = assembly.Location; for (int i = 0; i < attrs.Length; i++) { attr = attrs [i]; string resourceName = attr.WebResource; if (!String.IsNullOrEmpty (resourceName)) { string resourceNameHash = GetStringHash (kha, resourceName); #if SYSTEM_WEB_EXTENSIONS bool debug = resourceName.EndsWith (".debug.js", StringComparison.OrdinalIgnoreCase); string dbgTail = debug ? "d" : String.Empty; string rkNoNotify = resourceNameHash + "f" + dbgTail; string rkNotify = resourceNameHash + "t" + dbgTail; if (!entry.Resources.ContainsKey (rkNoNotify)) { var er = new EmbeddedResource () { Name = resourceName, Attribute = attr, Url = CreateResourceUrl (kha, assemblyName, assemblyHash, apath, rkNoNotify, debug, false) }; entry.Resources.Add (rkNoNotify, er); } if (!entry.Resources.ContainsKey (rkNotify)) { var er = new EmbeddedResource () { Name = resourceName, Attribute = attr, Url = CreateResourceUrl (kha, assemblyName, assemblyHash, apath, rkNotify, debug, true) }; entry.Resources.Add (rkNotify, er); } #else if (!entry.Resources.ContainsKey (resourceNameHash)) { var er = new EmbeddedResource () { Name = resourceName, Attribute = attr, Url = CreateResourceUrl (kha, assemblyName, assemblyHash, apath, resourceNameHash, false, false) }; entry.Resources.Add (resourceNameHash, er); } #endif } } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(packageFile)) { throw new CommandException("Could not find package file: " + packageFile); } Log.Info("Deploying package: " + packageFile); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); fileSystem.FreeDiskSpaceOverrideInMegaBytes = variables.GetInt32(SpecialVariables.FreeDiskSpaceOverrideInMegaBytes); fileSystem.SkipFreeDiskSpaceCheck = variables.GetFlag(SpecialVariables.SkipFreeDiskSpaceCheck); var featureClasses = new List <IFeature>(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var generator = new JsonConfigurationVariableReplacer(); var substituter = new FileSubstituter(fileSystem); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var embeddedResources = new AssemblyEmbeddedResources(); #if IIS_SUPPORT var iis = new InternetInformationServer(); featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() }); #endif var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new ContributePreviousSuccessfulInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), new ExtractPackageToApplicationDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem), new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(generator, fileSystem), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), #if IIS_SUPPORT new LegacyIisWebSiteConvention(fileSystem, iis), #endif new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(archiveFile, "No archive file was specified. Please pass --archive YourPackage.jar"); JavaRuntime.VerifyExists(); if (!File.Exists(archiveFile)) { throw new CommandException("Could not find archive file: " + archiveFile); } Log.Info("Deploying: " + archiveFile); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var substituter = new FileSubstituter(fileSystem); var commandOutput = new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)); var commandLineRunner = new CommandLineRunner(commandOutput); var jsonReplacer = new JsonConfigurationVariableReplacer(); var jarTools = new JarTool(commandLineRunner, commandOutput, variables); var packageExtractor = new JavaPackageExtractor(jarTools); var embeddedResources = new AssemblyEmbeddedResources(); var javaRunner = new JavaRunner(commandLineRunner, variables); var featureClasses = new List <IFeature> { new TomcatFeature(javaRunner), new WildflyFeature(javaRunner) }; var deployExploded = variables.GetFlag(SpecialVariables.Action.Java.DeployExploded); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new ContributePreviousSuccessfulInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), // If we are deploying the package exploded then extract directly to the application directory. // Else, if we are going to re-pack, then we extract initially to a temporary directory deployExploded ? (IInstallConvention) new ExtractPackageToApplicationDirectoryConvention(packageExtractor, fileSystem) : new ExtractPackageToStagingDirectoryConvention(packageExtractor, fileSystem), new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new SubstituteInFilesConvention(fileSystem, substituter), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), new RePackArchiveConvention(fileSystem, jarTools), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(archiveFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }
public KubernetesContextScriptWrapper(CalamariVariableDictionary variables) { this.fileSystem = new WindowsPhysicalFileSystem(); this.embeddedResources = new AssemblyEmbeddedResources(); this.variables = variables; }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(packageFile)) { throw new CommandException("Could not find package file: " + packageFile); } if (variablesFile != null && !File.Exists(variablesFile)) { throw new CommandException("Could not find variables file: " + variablesFile); } Log.Info("Deploying package: " + packageFile); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); var fileSystem = new WindowsPhysicalFileSystem(); var embeddedResources = new AssemblyEmbeddedResources(); var scriptEngine = new CombinedScriptEngine(); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var azurePackageUploader = new AzurePackageUploader(); var certificateStore = new CalamariCertificateStore(); var cloudCredentialsFactory = new SubscriptionCloudCredentialsFactory(certificateStore); var cloudServiceConfigurationRetriever = new AzureCloudServiceConfigurationRetriever(); var substituter = new FileSubstituter(fileSystem); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonVariablesReplacer = new JsonConfigurationVariableReplacer(); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new SwapAzureDeploymentConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractor(), fileSystem), new FindCloudServicePackageConvention(fileSystem), new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem), new ExtractAzureCloudServicePackageConvention(fileSystem), new ChooseCloudServiceConfigurationFileConvention(fileSystem), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfigureAzureCloudServiceConvention(fileSystem, cloudCredentialsFactory, cloudServiceConfigurationRetriever), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonVariablesReplacer, fileSystem), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new RePackageCloudServiceConvention(fileSystem, SemaphoreFactory.Get()), new UploadAzureCloudServicePackageConvention(fileSystem, azurePackageUploader, cloudCredentialsFactory), new DeployAzureCloudServicePackageConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(archiveFile, "No archive file was specified. Please pass --archive YourPackage.jar"); JavaRuntime.VerifyExists(); if (!File.Exists(archiveFile)) { throw new CommandException("Could not find archive file: " + archiveFile); } Log.Info("Deploying: " + archiveFile); var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var allFileFormatReplacers = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log); var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log); var jarTools = new JarTool(commandLineRunner, log, variables); var packageExtractor = new JarPackageExtractor(jarTools); var embeddedResources = new AssemblyEmbeddedResources(); var javaRunner = new JavaRunner(commandLineRunner, variables); var featureClasses = new List <IFeature> { new TomcatFeature(javaRunner), new WildflyFeature(javaRunner) }; var deployExploded = variables.GetFlag(SpecialVariables.Action.Java.DeployExploded); var conventions = new List <IConvention> { new AlreadyInstalledConvention(log, journal), // If we are deploying the package exploded then extract directly to the application directory. // Else, if we are going to re-pack, then we extract initially to a temporary directory deployExploded ? (IInstallConvention) new DelegateInstallConvention(d => extractPackage.ExtractToApplicationDirectory(archiveFile, packageExtractor)) : new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(archiveFile, packageExtractor)), new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new PackagedScriptConvention(new PreDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)), new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)), new RePackArchiveConvention(log, fileSystem, jarTools), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(new DeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(new PostDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new RollbackScriptConvention(log, DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(archiveFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(pathToPackage, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(pathToPackage)) { throw new CommandException("Could not find package file: " + pathToPackage); } Log.Info("Deploying package: " + pathToPackage); var featureClasses = new List <IFeature>(); var replacer = new ConfigurationVariablesReplacer(variables, log); var allFileFormatReplacers = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log); var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log); var configurationTransformer = ConfigurationTransformer.FromVariables(variables, log); var transformFileLocator = new TransformFileLocator(fileSystem, log); var embeddedResources = new AssemblyEmbeddedResources(); #if IIS_SUPPORT var iis = new InternetInformationServer(); featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() }); #endif if (!CalamariEnvironment.IsRunningOnWindows) { featureClasses.Add(new NginxFeature(NginxServer.AutoDetect(), fileSystem)); } var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var conventions = new List <IConvention> { new AlreadyInstalledConvention(log, journal), new DelegateInstallConvention(d => extractPackage.ExtractToApplicationDirectory(pathToPackage)), new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new PackagedScriptConvention(new PreDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), 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 CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(new DeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), #if IIS_SUPPORT new LegacyIisWebSiteConvention(fileSystem, iis), #endif new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(new PostDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)), new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new RollbackScriptConvention(log, DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(pathToPackage, variables); var conventionRunner = new ConventionProcessor(deployment, conventions, log); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }
static void InitEmbeddedResourcesUrls(KeyedHashAlgorithm kha, Assembly assembly, string assemblyName, string assemblyHash, AssemblyEmbeddedResources entry) { WebResourceAttribute [] attrs = (WebResourceAttribute [])assembly.GetCustomAttributes(typeof(WebResourceAttribute), false); WebResourceAttribute attr; string apath = assembly.Location; for (int i = 0; i < attrs.Length; i++) { attr = attrs [i]; string resourceName = attr.WebResource; if (!String.IsNullOrEmpty(resourceName)) { string resourceNameHash = GetStringHash(kha, resourceName); #if SYSTEM_WEB_EXTENSIONS bool debug = resourceName.EndsWith(".debug.js", StringComparison.OrdinalIgnoreCase); string dbgTail = debug ? "d" : String.Empty; string rkNoNotify = resourceNameHash + "f" + dbgTail; string rkNotify = resourceNameHash + "t" + dbgTail; if (!entry.Resources.ContainsKey(rkNoNotify)) { var er = new EmbeddedResource() { Name = resourceName, Attribute = attr, Url = CreateResourceUrl(kha, assemblyName, assemblyHash, apath, rkNoNotify, debug, false, true) }; entry.Resources.Add(rkNoNotify, er); } if (!entry.Resources.ContainsKey(rkNotify)) { var er = new EmbeddedResource() { Name = resourceName, Attribute = attr, Url = CreateResourceUrl(kha, assemblyName, assemblyHash, apath, rkNotify, debug, true, true) }; entry.Resources.Add(rkNotify, er); } #else if (!entry.Resources.ContainsKey(resourceNameHash)) { var er = new EmbeddedResource() { Name = resourceName, Attribute = attr, Url = CreateResourceUrl(kha, assemblyName, assemblyHash, apath, resourceNameHash, false, false, true) }; entry.Resources.Add(resourceNameHash, er); } #endif } } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); if (!ServiceFabricHelper.IsServiceFabricSdkKeyInRegistry()) { throw new CommandException("Could not find the Azure Service Fabric SDK on this server. This SDK is required before running Service Fabric commands."); } Guard.NotNullOrWhiteSpace(pathToPackage, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(pathToPackage)) { throw new CommandException("Could not find package file: " + pathToPackage); } Log.Info("Deploying package: " + pathToPackage); var fileSystem = new WindowsPhysicalFileSystem(); var embeddedResources = new AssemblyEmbeddedResources(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonReplacer = new JsonConfigurationVariableReplacer(); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var conventions = new List <IConvention> { new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)), // PreDeploy stage new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(log, DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), // Standard variable and transform replacements new DelegateInstallConvention(d => substituteInFiles.SubstituteBasedSettingsInSuppliedVariables(d)), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), // Deploy stage new PackagedScriptConvention(log, DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), // Variable replacement new SubstituteVariablesInAzureServiceFabricPackageConvention(fileSystem, fileSubstituter), // Main Service Fabric deployment script execution new EnsureCertificateInstalledInStoreConvention(certificateStore, SpecialVariables.Action.ServiceFabric.ClientCertVariable, SpecialVariables.Action.ServiceFabric.CertificateStoreLocation, SpecialVariables.Action.ServiceFabric.CertificateStoreName), new DeployAzureServiceFabricAppConvention(log, fileSystem, embeddedResources, scriptEngine, commandLineRunner), // PostDeploy stage new PackagedScriptConvention(log, DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), }; var deployment = new RunningDeployment(pathToPackage, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
// MUST be called with the _embeddedResourcesLock taken in the upgradeable read lock mode static AssemblyEmbeddedResources GetAssemblyEmbeddedResource (KeyedHashAlgorithm kha, Assembly assembly, string assemblyNameHash, string assemblyName) { AssemblyEmbeddedResources entry; if (!_embeddedResources.TryGetValue (assemblyNameHash, out entry) || entry == null) { try { _embeddedResourcesLock.EnterWriteLock (); entry = new AssemblyEmbeddedResources () { AssemblyName = assemblyName }; InitEmbeddedResourcesUrls (kha, assembly, assemblyName, assemblyNameHash, entry); _embeddedResources.Add (assemblyNameHash, entry); } finally { _embeddedResourcesLock.ExitWriteLock (); } } return entry; }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); if (!ServiceFabricHelper.IsServiceFabricSdkKeyInRegistry()) { throw new CommandException("Could not find the Azure Service Fabric SDK on this server. This SDK is required before running Service Fabric commands."); } Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(packageFile)) { throw new CommandException("Could not find package file: " + packageFile); } if (variablesFile != null && !File.Exists(variablesFile)) { throw new CommandException("Could not find variables file: " + variablesFile); } Log.Info("Deploying package: " + packageFile); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); var fileSystem = new WindowsPhysicalFileSystem(); var embeddedResources = new AssemblyEmbeddedResources(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonReplacer = new JsonConfigurationVariableReplacer(); var substituter = new FileSubstituter(fileSystem); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem), // PreDeploy stage new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), // Standard variable and transform replacements new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), // Deploy stage new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), // Variable replacement new SubstituteVariablesInAzureServiceFabricPackageConvention(fileSystem, substituter), // Main Service Fabric deployment script execution new EnsureServiceFabricCertificateExistsInStoreConvention(), new DeployAzureServiceFabricAppConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), // PostDeploy stage new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
static string GetResourceUrl(KeyedHashAlgorithm kha, Assembly assembly, string resourceName, bool notifyScriptLoaded) { string assemblyName = assembly == currAsm ? "s" : assembly.GetName().FullName; string assemblyNameHash = GetStringHash(kha, assemblyName); string resourceNameHash = GetStringHash(kha, resourceName); bool debug = false; string url; AssemblyEmbeddedResources entry; try { #if NET_2_0 _embeddedResourcesLock.EnterUpgradeableReadLock(); if (!_embeddedResources.TryGetValue(assemblyNameHash, out entry) || entry == null) #else _embeddedResourcesLock.AcquireReaderLock(-1); if ((entry = _embeddedResources [assemblyNameHash] as AssemblyEmbeddedResources) == null) #endif { #if !NET_2_0 LockCookie lc = new LockCookie(); #endif try { #if NET_2_0 _embeddedResourcesLock.EnterWriteLock(); #else lc = _embeddedResourcesLock.UpgradeToWriterLock(-1); #endif entry = new AssemblyEmbeddedResources() { AssemblyName = assemblyName }; InitEmbeddedResourcesUrls(kha, assembly, assemblyName, assemblyNameHash, entry); _embeddedResources.Add(assemblyNameHash, entry); } finally { #if NET_2_0 _embeddedResourcesLock.ExitWriteLock(); #else _embeddedResourcesLock.DowngradeFromWriterLock(ref lc); #endif } } string lookupKey; #if SYSTEM_WEB_EXTENSIONS debug = resourceName.EndsWith(".debug.js", StringComparison.OrdinalIgnoreCase); string dbgTail = debug ? "d" : String.Empty; lookupKey = resourceNameHash + (notifyScriptLoaded ? "t" : "f") + dbgTail; #else lookupKey = resourceNameHash; #endif EmbeddedResource res; #if NET_2_0 if (entry.Resources.TryGetValue(lookupKey, out res) && res != null) #else if ((res = entry.Resources [lookupKey] as EmbeddedResource) != null) #endif { url = res.Url; } else { #if SYSTEM_WEB_EXTENSIONS if (debug) { resourceNameHash = GetStringHash(kha, resourceName.Substring(0, resourceName.Length - 9) + ".js"); lookupKey = resourceNameHash + (notifyScriptLoaded ? "t" : "f"); if (entry.Resources.TryGetValue(lookupKey, out res) && res != null) { url = res.Url; } else { url = null; } } else #endif url = null; } } finally { #if NET_2_0 _embeddedResourcesLock.ExitUpgradeableReadLock(); #else _embeddedResourcesLock.ReleaseReaderLock(); #endif } if (url == null) { url = CreateResourceUrl(kha, assemblyName, assemblyNameHash, assembly.Location, resourceNameHash, debug, notifyScriptLoaded); } return(url); }