Example #1
0
        private static async Task <int> Main(string[] args)
        {
            int exitCode;

            using (App app = await App.CreateAsync(args).ConfigureAwait(false))
            {
                NuGetPackageInstallResult nuGetPackageInstallResult = await app.ExecuteAsync(args.ToImmutableArray()).ConfigureAwait(false);

                exitCode = nuGetPackageInstallResult.SemanticVersion is {} && nuGetPackageInstallResult.PackageDirectory is {} ? 0 : 1;
Example #2
0
        private static async Task <int> Main(string[] args)
        {
            int exitCode;

            using (BootstrapperApp bootstrapperApp = await BootstrapperApp.CreateAsync(args).ConfigureAwait(false))
            {
                NuGetPackageInstallResult nuGetPackageInstallResult =
                    await bootstrapperApp.ExecuteAsync(args.ToImmutableArray()).ConfigureAwait(false);

                exitCode = nuGetPackageInstallResult.SemanticVersion is {} &&
Example #3
0
        private static async Task <int> Main(string[] args)
        {
            int exitCode;

            using (BootstrapperApp bootstrapperApp = await BootstrapperApp.CreateAsync(args).ConfigureAwait(false))
            {
                using var cts = new CancellationTokenSource(GetTimeout(args));

                NuGetPackageInstallResult nuGetPackageInstallResult =
                    await bootstrapperApp.ExecuteAsync(args.ToImmutableArray(), cts.Token).ConfigureAwait(false);

                exitCode = nuGetPackageInstallResult.SemanticVersion is {} &&
Example #4
0
        public async Task DownloadAsync()
        {
            string[] args = { Constants.AllowPreRelease, Constants.DownloadOnly };

            using Logger logger = new LoggerConfiguration()
                                  .WriteTo.Debug()
                                  .MinimumLevel.Verbose()
                                  .CreateLogger();
            using BootstrapperApp bootstrapperApp = await BootstrapperApp.CreateAsync(args, logger);

            NuGetPackageInstallResult nuGetPackageInstallResult =
                await bootstrapperApp.ExecuteAsync(args.ToImmutableArray());

            Assert.NotNull(nuGetPackageInstallResult);
            Assert.NotNull(nuGetPackageInstallResult.NuGetPackageId);
            Assert.NotNull(nuGetPackageInstallResult.PackageDirectory);
            Assert.NotNull(nuGetPackageInstallResult.SemanticVersion);
        }
Example #5
0
        private static async Task <int> Main(string[] args)
        {
            int exitCode;

            using (App app = await App.CreateAsync(args).ConfigureAwait(false))
            {
                using (var cts = new CancellationTokenSource(GetTimeout(args)))
                {
                    NuGetPackageInstallResult nuGetPackageInstallResult =
                        await app.ExecuteAsync(args.ToImmutableArray(), cancellationToken : cts.Token).ConfigureAwait(false);

                    exitCode = nuGetPackageInstallResult.SemanticVersion != null &&
                               nuGetPackageInstallResult.PackageDirectory != null
                        ? 0
                        : 1;
                }
            }

            return(exitCode);
        }
Example #6
0
        public async Task <ExitCode> ExecuteAsync(
            DeploymentTask deploymentTask,
            ILogger logger,
            CancellationToken cancellationToken = default)
        {
            string jobId = "MDep_" + Guid.NewGuid();

            logger.Information("Starting job {JobId}", jobId);

            DeploymentTarget deploymentTarget =
                await GetDeploymentTarget(deploymentTask.DeploymentTargetId, cancellationToken);

            Environment.SetEnvironmentVariable(ConfigurationConstants.AllowPreReleaseEnabled,
                                               "true"); // TODO try to remove

            SetLogging();

            string targetDirectoryPath = GetTargetDirectoryPath(deploymentTarget, jobId, deploymentTask);

            string targetEnvironmentConfigName =
                deploymentTarget.EnvironmentConfiguration;

            var arguments = new List <string>();

            logger.Information("Using manifest file for job {JobId}", jobId);

            string publishSettingsFile = deploymentTarget.PublishSettingFile;

            string deploymentTargetParametersFile = deploymentTarget.ParameterFile;

            var tempManifestFile = new FileInfo(Path.Combine(Path.GetTempPath(), $"{jobId}.manifest"));

            deploymentTask.TempFiles.Add(tempManifestFile);

            ImmutableDictionary <string, string[]> parameterDictionary;

            if (!string.IsNullOrWhiteSpace(deploymentTargetParametersFile) &&
                !Path.IsPathRooted(deploymentTargetParametersFile))
            {
                throw new DeployerAppException(
                          $"The deployment target {deploymentTarget} parameter file '{deploymentTargetParametersFile}' is not a rooted path");
            }

            if (!string.IsNullOrWhiteSpace(deploymentTargetParametersFile) &&
                File.Exists(deploymentTargetParametersFile))
            {
                string parametersJson = File.ReadAllText(deploymentTargetParametersFile, Encoding.UTF8);

                parameterDictionary = JsonConvert
                                      .DeserializeObject <Dictionary <string, string[]> >(parametersJson).ToImmutableDictionary();

                logger.Information("Using WebDeploy parameters from file {DeploymentTargetParametersFile}",
                                   deploymentTargetParametersFile);
            }
            else
            {
                logger.Information("No WebDeploy parameters file exists ('{DeploymentTargetParametersFile}')",
                                   deploymentTargetParametersFile);

                parameterDictionary = deploymentTarget.Parameters;
            }

            ImmutableDictionary <string, string[]> parameters = parameterDictionary;

            if (deploymentTarget.PublishSettingsXml.HasValue())
            {
                string tempFileName = Path.GetTempFileName();

                await File.WriteAllTextAsync(tempFileName,
                                             deploymentTarget.PublishSettingsXml,
                                             Encoding.UTF8,
                                             cancellationToken);

                deploymentTask.TempFiles.Add(new FileInfo(tempFileName));

                publishSettingsFile = tempFileName;
            }

            if (!File.Exists(publishSettingsFile))
            {
                const string secretKeyPrefix = "publish-settings";

                string id = deploymentTarget.Id;

                const string usernameKey     = secretKeyPrefix + ":username";
                const string passwordKey     = secretKeyPrefix + ":password";
                const string publishUrlKey   = secretKeyPrefix + ":publish-url";
                const string msdeploySiteKey = secretKeyPrefix + ":msdeploySite";

                string username     = _credentialReadService.GetSecret(id, usernameKey);
                string password     = _credentialReadService.GetSecret(id, passwordKey);
                string publishUrl   = _credentialReadService.GetSecret(id, publishUrlKey);
                string msdeploySite = _credentialReadService.GetSecret(id, msdeploySiteKey);

                if (StringUtils.AllHaveValues(username, password, publishUrl, msdeploySite))
                {
                    FileInfo fileInfo = CreateTempPublishFile(deploymentTarget,
                                                              username,
                                                              password,
                                                              publishUrl);

                    deploymentTask.TempFiles.Add(fileInfo);

                    publishSettingsFile = fileInfo.FullName;
                }
                else
                {
                    Log.Warning("Could not get secrets for deployment target id {DeploymentTargetId}", id);
                }
            }

            var definitions = new
            {
                definitions = new object[]
                {
                    new
                    {
                        deploymentTask.PackageId,
                        targetDirectoryPath,
                        isPreRelease      = deploymentTask.SemanticVersion.IsPrerelease,
                        environmentConfig = targetEnvironmentConfigName,
                        publishSettingsFile,
                        parameters,
                        deploymentTarget.NuGetConfigFile,
                        deploymentTarget.NuGetPackageSource,
                        semanticVersion    = deploymentTask.SemanticVersion.ToNormalizedString(),
                        iisSiteName        = deploymentTarget.IisSiteName,
                        webConfigTransform = deploymentTarget.WebConfigTransform
                    }
                }
            };

            string json = JsonConvert.SerializeObject(definitions, Formatting.Indented);

            logger.Information("Using definitions JSON: {Json}", json);

            logger.Information("Using temp manifest file '{ManifestFile}'", tempManifestFile.FullName);

            await File.WriteAllTextAsync(tempManifestFile.FullName, json, Encoding.UTF8, cancellationToken);

            arguments.Add($"\"{tempManifestFile.FullName}\"");

            //TODO propagate properties by direct command or default
            Environment.SetEnvironmentVariable("urn:milou-deployer:tools:nuget:exe-path",
                                               _keyValueConfiguration["urn:milou-deployer:tools:nuget:exe-path"]);

            arguments.Add(Bootstrapper.Common.Constants.AllowPreRelease);
            arguments.Add(Milou.Deployer.Core.LoggingConstants.PlainOutputFormatEnabled);

            string[] deployerArgs = arguments.ToArray();

            logger.Verbose("Running Milou Deployer bootstrapper");

            HttpClient httpClient = _clientFactory.CreateClient("Bootstrapper");

            using (Bootstrapper.Common.App deployerApp =
                       await Bootstrapper.Common.App.CreateAsync(deployerArgs,
                                                                 logger,
                                                                 httpClient,
                                                                 false))
            {
                NuGetPackageInstallResult result =
                    await deployerApp.ExecuteAsync(deployerArgs.ToImmutableArray(), cancellationToken);

                if (result.PackageDirectory is null || result.SemanticVersion is null)
                {
                    logger.Warning("Milou.Deployer failed");
                    return(ExitCode.Failure);
                }
            }

            ClearTemporaryDirectoriesAndFiles(deploymentTask);

            return(ExitCode.Success);
        }