Пример #1
0
        public string GetProductVersion(DotNetImageType imageType, DockerHelper dockerHelper)
        {
            string version;
            string imageName     = GetImage(imageType, dockerHelper);
            string containerName = GetIdentifier($"GetProductVersion-{imageType}");

            switch (imageType)
            {
            case DotNetImageType.SDK:
                version = dockerHelper.Run(imageName, containerName, "dotnet --version");
                break;

            case DotNetImageType.Runtime:
                version = GetRuntimeVersion(imageName, containerName, "Microsoft.NETCore.App", dockerHelper);
                break;

            case DotNetImageType.Aspnet:
                version = GetRuntimeVersion(imageName, containerName, "Microsoft.AspNetCore.App", dockerHelper);
                break;

            default:
                throw new NotSupportedException($"Unsupported image type '{imageType}'");
            }

            return(version);
        }
Пример #2
0
        private string GetTagName(DotNetImageType imageType)
        {
            Version imageVersion;
            string  os;

            switch (imageType)
            {
            case DotNetImageType.Runtime:
            case DotNetImageType.Aspnet:
            case DotNetImageType.Runtime_Deps:
                imageVersion = Version;
                os           = OS;
                break;

            case DotNetImageType.SDK:
                imageVersion = Version;
                os           = SdkOS;
                break;

            default:
                throw new NotSupportedException($"Unsupported image type '{imageType}'");
            }

            return(this.GetTagName(imageVersion.ToString(2), os));
        }
Пример #3
0
        private string BuildTestAppImage(string stageTarget, string contextDir, params string[] customBuildArgs)
        {
            string tag = _imageData.GetIdentifier(stageTarget);

            List <string> buildArgs = new List <string>();

            buildArgs.Add($"sdk_image={_imageData.GetImage(DotNetImageType.SDK, _dockerHelper)}");

            DotNetImageType runtimeImageType = _isWeb ? DotNetImageType.Aspnet : DotNetImageType.Runtime;

            buildArgs.Add($"runtime_image={_imageData.GetImage(runtimeImageType, _dockerHelper)}");

            if (DockerHelper.IsLinuxContainerModeEnabled)
            {
                buildArgs.Add($"runtime_deps_image={_imageData.GetImage(DotNetImageType.Runtime_Deps, _dockerHelper)}");
            }

            if (customBuildArgs != null)
            {
                buildArgs.AddRange(customBuildArgs);
            }

            _dockerHelper.Build(
                tag: tag,
                target: stageTarget,
                contextDir: contextDir,
                buildArgs: buildArgs.ToArray());

            return(tag);
        }
Пример #4
0
        public static void Validate(
            IEnumerable <EnvironmentVariableInfo> variables,
            DotNetImageType imageType,
            ProductImageData imageData,
            DockerHelper dockerHelper)
        {
            const char           delimiter = '|';
            IEnumerable <string> echoParts;
            string invokeCommand;
            char   delimiterEscape;

            if (DockerHelper.IsLinuxContainerModeEnabled)
            {
                echoParts       = variables.Select(envVar => $"${envVar.Name}");
                invokeCommand   = $"/bin/sh -c";
                delimiterEscape = '\\';
            }
            else
            {
                echoParts       = variables.Select(envVar => $"%{envVar.Name}%");
                invokeCommand   = $"CMD /S /C";
                delimiterEscape = '^';
            }

            string combinedValues = dockerHelper.Run(
                image: imageData.GetImage(imageType, dockerHelper),
                name: imageData.GetIdentifier($"env"),
                command: $"{invokeCommand} \"echo {string.Join($"{delimiterEscape}{delimiter}", echoParts)}\"");

            string[] values = combinedValues.Split(delimiter);
            Assert.Equal(variables.Count(), values.Count());

            for (int i = 0; i < values.Count(); i++)
            {
                EnvironmentVariableInfo variable = variables.ElementAt(i);

                string actualValue;
                // Process unset variables in Windows
                if (!DockerHelper.IsLinuxContainerModeEnabled &&
                    string.Equals(values[i], $"%{variable.Name}%", StringComparison.Ordinal))
                {
                    actualValue = string.Empty;
                }
                else
                {
                    actualValue = values[i];
                }

                if (variable.AllowAnyValue)
                {
                    Assert.NotEmpty(actualValue);
                }
                else
                {
                    Assert.Equal(variable.ExpectedValue, actualValue);
                }
            }
        }
Пример #5
0
        public string GetImage(DotNetImageType imageType, DockerHelper dockerHelper)
        {
            string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');
            string tag         = GetTagName(imageType);
            string imageName   = GetProductImageName(tag, variantName);

            PullImageIfNecessary(imageName, dockerHelper);

            return(imageName);
        }
Пример #6
0
        public static string GetBuildVersion(DotNetImageType imageType, string dotnetVersion)
        {
            if (imageType == DotNetImageType.Runtime_Deps)
            {
                throw new NotSupportedException("Runtime deps has no associated build version");
            }

            return(GetVariableValue(
                       $"{imageType.ToString().ToLower()}|{dotnetVersion}|build-version",
                       (JObject)ManifestVersions.Value["variables"]));
        }
Пример #7
0
        public string GetProductVersion(DotNetImageType imageType, DockerHelper dockerHelper)
        {
            string imageName     = GetImage(imageType, dockerHelper);
            string containerName = GetIdentifier($"GetProductVersion-{imageType}");

            return(imageType switch
            {
                DotNetImageType.SDK => dockerHelper.Run(imageName, containerName, "dotnet --version"),
                DotNetImageType.Runtime => GetRuntimeVersion(imageName, containerName, "Microsoft.NETCore.App", dockerHelper),
                DotNetImageType.Aspnet => GetRuntimeVersion(imageName, containerName, "Microsoft.AspNetCore.App", dockerHelper),
                _ => throw new NotSupportedException($"Unsupported image type '{imageType}'"),
            });
Пример #8
0
        private void VerifyCommonRuntimeEnvironmentVariables(DotNetImageType imageType, ImageData imageData)
        {
            List <EnvironmentVariableInfo> variables = new List <EnvironmentVariableInfo>();

            variables.AddRange(GetCommonEnvironmentVariables());
            variables.Add(new EnvironmentVariableInfo("ASPNETCORE_URLS", "http://+:80"));

            if (imageData.OS.StartsWith(Tests.OS.AlpinePrefix))
            {
                variables.Add(new EnvironmentVariableInfo("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "true"));
            }

            EnvironmentVariableInfo.Validate(variables, imageType, imageData, _dockerHelper);
        }
Пример #9
0
        public string GetImage(DotNetImageType imageType, ImageData imageData)
        {
            string imageName = $"{s_repoName}:{imageData.GetTag(imageType)}";

            if (s_isLocalRun)
            {
                Assert.True(DockerHelper.ImageExists(imageName), $"`{imageName}` could not be found on disk.");
            }
            else
            {
                _dockerHelper.Pull(imageName);
            }

            return(imageName);
        }
Пример #10
0
        public string GetImage(DotNetImageType imageType, DockerHelper dockerHelper)
        {
            string imageName = GetImageName(imageType);

            if (!Config.IsLocalRun && !_pulledImages.Contains(imageName))
            {
                dockerHelper.Pull(imageName);
                _pulledImages.Add(imageName);
            }
            else
            {
                Assert.True(DockerHelper.ImageExists(imageName), $"`{imageName}` could not be found on disk.");
            }

            return(imageName);
        }
Пример #11
0
        public string GetDotNetImage(DotNetImageType imageType, ImageData imageData)
        {
            string imageVersion;
            string osVariant;
            string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');

            switch (imageType)
            {
            case DotNetImageType.Runtime:
            case DotNetImageType.AspNetCore_Runtime:
                imageVersion = imageData.DotNetVersion;
                osVariant    = imageData.OsVariant;
                break;

            case DotNetImageType.Runtime_Deps:
                imageVersion = imageData.RuntimeDepsVersion;
                osVariant    = imageData.OsVariant;
                break;

            case DotNetImageType.SDK:
                imageVersion = imageData.SdkVersion;
                osVariant    = imageData.SdkOsVariant;
                break;

            default:
                throw new NotSupportedException($"Unsupported image type '{variantName}'");
            }

            string imageName = $"{s_repoName}:{imageVersion}-{variantName}-{osVariant}";

            if (imageData.IsArm)
            {
                imageName += $"-arm32v7";
            }

            if (s_isLocalRun)
            {
                Assert.True(DockerHelper.ImageExists(imageName), $"`{imageName}` could not be found on disk.");
            }
            else
            {
                _dockerHelper.Pull(imageName);
            }

            return(imageName);
        }
Пример #12
0
        public static string GetDotNetImage(
            string imageVersion, DotNetImageType imageType, string osVariant, bool isArm = false)
        {
            string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');
            string imageName   = $"microsoft/dotnet:{imageVersion}-{variantName}";

            if (!string.IsNullOrEmpty(osVariant))
            {
                imageName += $"-{osVariant}";
            }

            if (isArm)
            {
                imageName += $"-arm32v7";
            }

            return(imageName);
        }
Пример #13
0
        private string GetImageName(DotNetImageType imageType)
        {
            string repoSuffix  = Config.IsNightlyRepo ? "-nightly" : string.Empty;
            string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');

            Version imageVersion;
            string  os;

            switch (imageType)
            {
            case DotNetImageType.Runtime:
            case DotNetImageType.Aspnet:
                imageVersion = Version;
                os           = OS;
                break;

            case DotNetImageType.Runtime_Deps:
                imageVersion = RuntimeDepsVersion;
                os           = OS;
                break;

            case DotNetImageType.SDK:
                imageVersion = SdkVersion;
                os           = SdkOS;
                break;

            default:
                throw new NotSupportedException($"Unsupported image type '{variantName}'");
            }

            string arch = string.Empty;

            if (Arch == Arch.Arm)
            {
                arch = "-arm32v7";
            }
            else if (Arch == Arch.Arm64)
            {
                arch = "-arm64v8";
            }

            return($"{Config.Registry}/{Config.RepoPrefix}dotnet/core{repoSuffix}/{variantName}:{imageVersion.ToString(2)}-{os}{arch}");
        }
Пример #14
0
        public static string GetDotNetImage(
            string imageVersion, DotNetImageType imageType, string osVariant, bool isArm = false)
        {
            string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');
            string imageName   = $"microsoft/dotnet:{imageVersion}-{variantName}";

            if (!string.IsNullOrEmpty(osVariant))
            {
                imageName += $"-{osVariant}";
            }

            if (isArm)
            {
                imageName += $"-arm32v7";
            }

            Assert.True(DockerHelper.ImageExists(imageName), $"`{imageName}` could not be found on disk.");

            return(imageName);
        }
Пример #15
0
        private string GetImageName(DotNetImageType imageType)
        {
            Version imageVersion;
            string  os;
            string  variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');

            switch (imageType)
            {
            case DotNetImageType.Runtime:
            case DotNetImageType.AspNetCore_Runtime:
                imageVersion = Version;
                os           = OS;
                break;

            case DotNetImageType.Runtime_Deps:
                imageVersion = RuntimeDepsVersion;
                os           = OS;
                break;

            case DotNetImageType.SDK:
                imageVersion = SdkVersion;
                os           = SdkOS;
                break;

            default:
                throw new NotSupportedException($"Unsupported image type '{variantName}'");
            }

            string arch = string.Empty;

            if (Arch == Arch.Arm)
            {
                arch = DockerHelper.IsLinuxContainerModeEnabled ? $"-arm32v7" : "-arm32";
            }
            else if (Arch == Arch.Arm64)
            {
                arch = $"-arm64v8";
            }

            return($"{Config.RepoName}:{imageVersion.ToString(2)}-{variantName}-{os}{arch}");
        }
Пример #16
0
        /// <summary>
        /// Builds a helper image intended to test distroless scenarios.
        /// </summary>
        /// <remarks>
        /// Because distroless containers do not contain a shell, and potentially other packages necessary for testing,
        /// this helper image adds the necessary packages to a distroless image.
        /// </remarks>
        public string BuildDistrolessHelper(DotNetImageType imageType, ProductImageData imageData, params string[] requiredPackages)
        {
            string dockerfile;

            if (imageData.OS.Contains("mariner"))
            {
                dockerfile = Path.Combine(TestArtifactsDir, "Dockerfile.cbl-mariner-distroless");
            }
            else
            {
                throw new NotImplementedException($"Distroless helper not implemented for OS '{imageData.OS}'");
            }

            string baseImageTag      = imageData.GetImage(imageType, this);
            string installerImageTag = baseImageTag.Replace("-distroless", string.Empty);

            string tag = imageData.GetIdentifier("distroless-helper");

            Build(tag, dockerfile, null, TestArtifactsDir, false,
                  $"installer_image={installerImageTag}",
                  $"base_image={baseImageTag}",
                  $"\"required_packages={string.Join(" ", requiredPackages)}\"");
            return(tag);
        }