private IisManager( ServerManager serverManager, DeployerConfiguration configuration, ILogger logger, DeploymentExecutionDefinition deploymentExecutionDefinition) { _serverManager = serverManager; _configuration = configuration; _logger = logger; _deploymentExecutionDefinition = deploymentExecutionDefinition; }
public async Task <MayBe <InstalledPackage> > InstallPackageAsync( DeploymentExecutionDefinition deploymentExecutionDefinition, DirectoryInfo tempDirectory, bool includeVersion = true, SemanticVersion explicitVersion = null, CancellationToken cancellationToken = default) { if (deploymentExecutionDefinition == null) { throw new ArgumentNullException(nameof(deploymentExecutionDefinition)); } if (tempDirectory == null) { throw new ArgumentNullException(nameof(tempDirectory)); } string executePath = deploymentExecutionDefinition.NuGetExePath.WithDefault(_deployerConfiguration.NuGetExePath); if (string.IsNullOrWhiteSpace(executePath)) { throw new InvalidOperationException("The NuGet executable file path is not defined"); } if (!File.Exists(executePath)) { throw new InvalidOperationException($"The NuGet executable file '{executePath}' does not exist"); } var arguments = new List <string> { "install", deploymentExecutionDefinition.PackageId }; void AddVersion(string value) { arguments.Add("-Version"); arguments.Add(value); } if (explicitVersion != null) { AddVersion(explicitVersion.ToNormalizedString()); } else if (deploymentExecutionDefinition.SemanticVersion is {})
public static IisManager Create( [NotNull] DeployerConfiguration configuration, [NotNull] ILogger logger, [NotNull] DeploymentExecutionDefinition deploymentExecutionDefinition) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (deploymentExecutionDefinition is null) { throw new ArgumentNullException(nameof(deploymentExecutionDefinition)); } return(new IisManager(new ServerManager(), configuration, logger, deploymentExecutionDefinition)); }
public static string SetVersionFile( [NotNull] InstalledPackage installedPackage, [NotNull] DirectoryInfo targetDirectoryInfo, [NotNull] DeploymentExecutionDefinition deploymentExecutionDefinition, [NotNull] IEnumerable <string> xmlTransformedFiles, [NotNull] IEnumerable <string> replacedFiles, [NotNull] EnvironmentPackageResult environmentPackageResult, ILogger logger) { if (installedPackage == null) { throw new ArgumentNullException(nameof(installedPackage)); } if (targetDirectoryInfo == null) { throw new ArgumentNullException(nameof(targetDirectoryInfo)); } if (deploymentExecutionDefinition == null) { throw new ArgumentNullException(nameof(deploymentExecutionDefinition)); } if (xmlTransformedFiles == null) { throw new ArgumentNullException(nameof(xmlTransformedFiles)); } if (replacedFiles == null) { throw new ArgumentNullException(nameof(replacedFiles)); } if (environmentPackageResult == null) { throw new ArgumentNullException(nameof(environmentPackageResult)); } string applicationMetadataJsonFilePath = Path.Combine(targetDirectoryInfo.FullName, ConfigurationKeys.ApplicationMetadataFileName); var existingKeys = new List <KeyValue>(); if (File.Exists(applicationMetadataJsonFilePath)) { logger?.Debug("Appending existing metadata file {Path}", applicationMetadataJsonFilePath); string json = File.ReadAllText(applicationMetadataJsonFilePath, Encoding.UTF8); ConfigurationItems configurationItems = JsonConfigurationSerializer.Deserialize(json); if (!configurationItems.Keys.IsDefaultOrEmpty) { existingKeys.AddRange(configurationItems.Keys); } } var version = new KeyValue(ConfigurationKeys.SemVer2Normalized, installedPackage.Version.ToNormalizedString(), null); var packageId = new KeyValue(ConfigurationKeys.PackageId, installedPackage.PackageId, null); var deployStartTimeUtc = new KeyValue( ConfigurationKeys.DeployStartTimeUtc, DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture), null); var deployedFromMachine = new KeyValue( ConfigurationKeys.DeployerDeployedFromMachine, Environment.MachineName, null); var deployerAssemblyVersion = new KeyValue( ConfigurationKeys.DeployerAssemblyVersion, GetAssemblyVersion(), null); var deployerAssemblyFileVersion = new KeyValue( ConfigurationKeys.DeployerAssemblyFileVersion, GetAssemblyFileVersion(), null); var environmentConfiguration = new KeyValue( ConfigurationKeys.DeployerEnvironmentConfiguration, deploymentExecutionDefinition.EnvironmentConfig, null); var keys = new List <KeyValue>(existingKeys) { version, deployStartTimeUtc, deployerAssemblyVersion, deployerAssemblyFileVersion, packageId }.ToImmutableArray(); if (environmentPackageResult.Version != null) { keys.Add(environmentConfiguration); } string serialized = JsonConfigurationSerializer.Serialize(new ConfigurationItems("1.0", keys)); File.WriteAllText(applicationMetadataJsonFilePath, serialized, Encoding.UTF8); logger?.Debug("Metadata file update {Path}", applicationMetadataJsonFilePath); return(applicationMetadataJsonFilePath); }
public static void Transform([NotNull] DeploymentExecutionDefinition deploymentExecutionDefinition, [NotNull] DirectoryInfo contentDirectory, [NotNull] ILogger logger) { if (deploymentExecutionDefinition is null) { throw new ArgumentNullException(nameof(deploymentExecutionDefinition)); } if (contentDirectory is null) { throw new ArgumentNullException(nameof(contentDirectory)); } if (logger is null) { throw new ArgumentNullException(nameof(logger)); } try { if (string.IsNullOrWhiteSpace(deploymentExecutionDefinition.WebConfigTransformFile)) { return; } logger.Debug( "Found web config transformation {Transformation} for deployment execution definition {Deployment}", deploymentExecutionDefinition.WebConfigTransformFile, deploymentExecutionDefinition); var transformFile = new FileInfo(deploymentExecutionDefinition.WebConfigTransformFile); if (transformFile.Exists) { string tempFileName = Path.GetRandomFileName(); var webConfig = new FileInfo(Path.Combine(contentDirectory.FullName, "web.config")); if (webConfig.Exists) { using var x = new XmlTransformableDocument { PreserveWhitespace = true }; x.Load(webConfig.FullName); using var transform = new Microsoft.Web.XmlTransform.XmlTransformation(transformFile.FullName); bool succeed = transform.Apply(x); if (succeed) { using var fsDestFileStream = new FileStream(tempFileName, FileMode.OpenOrCreate); x.Save(fsDestFileStream); } } var tempFileInfo = new FileInfo(tempFileName); if (tempFileInfo.Exists && tempFileInfo.Length > 0) { logger.Information( "Successfully transformed web.config with transformation {Transformation}", deploymentExecutionDefinition.WebConfigTransformFile); tempFileInfo.CopyTo(webConfig.FullName, true); } else { logger.Warning( "Failed to transform web.config with transformation {Transformation}", deploymentExecutionDefinition.WebConfigTransformFile); } tempFileInfo.Delete(); } } catch (Exception ex) when(!ex.IsFatal()) { logger.Error(ex, "Could not apply web.config transform with {Transform}", deploymentExecutionDefinition.WebConfigTransformFile); throw; } }