Esempio n. 1
0
        private bool IsEnabledForMultiPlatformBuild(IProgrammingPlatform platform, DockerfileContext ctx)
        {
            if (ctx.DisableMultiPlatformBuild)
            {
                return(false);
            }

            return(platform.IsEnabledForMultiPlatformBuild(ctx));
        }
Esempio n. 2
0
        public string GenerateDockerfile(DockerfileContext ctx)
        {
            var buildImageTag       = "lts-versions";
            var runImage            = string.Empty;
            var runImageTag         = string.Empty;
            var compatiblePlatforms = GetCompatiblePlatforms(ctx);

            if (!compatiblePlatforms.Any())
            {
                throw new UnsupportedPlatformException(Labels.UnableToDetectPlatformMessage);
            }

            foreach (var platformAndDetectorResult in compatiblePlatforms)
            {
                var platform       = platformAndDetectorResult.Key;
                var detectorResult = platformAndDetectorResult.Value;
                if (!_slimPlatformVersions.ContainsKey(platform.Name) ||
                    (!_slimPlatformVersions[platform.Name].Any(v => detectorResult.PlatformVersion.StartsWith(v)) &&
                     !_slimPlatformVersions[platform.Name].Any(v => v.StartsWith(detectorResult.PlatformVersion))))
                {
                    buildImageTag = "latest";
                    runImageTag   = GenerateRuntimeTag(detectorResult.PlatformVersion);
                }
                else
                {
                    runImageTag = _slimPlatformVersions[platform.Name]
                                  .Where(v => detectorResult.PlatformVersion.StartsWith(v)).FirstOrDefault();
                }

                runImage = ConvertToRuntimeName(platform.Name);
            }

            var properties = new DockerfileProperties()
            {
                RuntimeImageName = runImage,
                RuntimeImageTag  = runImageTag,
                BuildImageTag    = buildImageTag,
            };

            return(TemplateHelper.Render(
                       TemplateHelper.TemplateResource.Dockerfile,
                       properties,
                       _logger));
        }
Esempio n. 3
0
        public string GenerateDockerfile(DockerfileContext ctx)
        {
            var buildImageTag       = "slim";
            var runImage            = string.Empty;
            var runImageTag         = string.Empty;
            var compatiblePlatforms = GetCompatiblePlatforms(ctx);

            if (!compatiblePlatforms.Any())
            {
                throw new UnsupportedLanguageException(Labels.UnableToDetectLanguageMessage);
            }

            foreach (var platformAndVersion in compatiblePlatforms)
            {
                var platform = platformAndVersion.Key;
                var version  = platformAndVersion.Value;
                if (!_slimPlatformVersions.ContainsKey(platform.Name) ||
                    !_slimPlatformVersions[platform.Name].Any(v => version.StartsWith(v)))
                {
                    buildImageTag = "latest";
                }

                runImage    = platform.Name == "dotnet" ? "dotnetcore" : platform.Name;
                runImageTag = GenerateRuntimeTag(version);
            }

            var properties = new DockerfileProperties()
            {
                RuntimeImageName = runImage,
                RuntimeImageTag  = runImageTag,
                BuildImageTag    = buildImageTag,
            };

            return(TemplateHelper.Render(
                       TemplateHelper.TemplateResource.Dockerfile,
                       properties,
                       _logger));
        }
Esempio n. 4
0
 private IDictionary <IProgrammingPlatform, string> GetCompatiblePlatforms(DockerfileContext ctx)
 {
     return(_platformDetector.GetCompatiblePlatforms(ctx, ctx.Platform, ctx.PlatformVersion));
 }
Esempio n. 5
0
 private IDictionary <IProgrammingPlatform, PlatformDetectorResult> GetCompatiblePlatforms(DockerfileContext ctx)
 {
     return(_platformDetector.GetCompatiblePlatforms(ctx));
 }
        public string GenerateDockerfile(DockerfileContext ctx)
        {
            var dockerfileBuildImageName = "build";
            var dockerfileBuildImageTag  = "azfunc-jamstack";

            var dockerfileRuntimeImage = !string.IsNullOrEmpty(this.commonOptions.RuntimePlatformName) ?
                                         ConvertToRuntimeName(this.commonOptions.RuntimePlatformName) : string.Empty;
            var dockerfileRuntimeImageTag = !string.IsNullOrEmpty(this.commonOptions.RuntimePlatformVersion) ?
                                            this.commonOptions.RuntimePlatformVersion : string.Empty;
            var compatiblePlatforms = this.GetCompatiblePlatforms(ctx);

            if (!compatiblePlatforms.Any())
            {
                throw new UnsupportedPlatformException(Labels.UnableToDetectPlatformMessage);
            }

            foreach (var platformAndDetectorResult in compatiblePlatforms)
            {
                var platform = platformAndDetectorResult.Key;
                var platformDetectorResult = platformAndDetectorResult.Value;
                var detectedRuntimeName    = ConvertToRuntimeName(platform.Name);

                // If the runtime platform name wasn't previously provided, see if we can use the current detected platform as the runtime image.
                if (string.IsNullOrEmpty(dockerfileRuntimeImage))
                {
                    // If the detected platform isn't in our currently list of runtime versions, skip it with a notice to the user.
                    if (!this.supportedRuntimeVersions.ContainsKey(detectedRuntimeName))
                    {
                        this.logger.LogDebug($"The detected platform {platform.Name} does not currently have a supported runtime image." +
                                             $"If this Dockerfile command or image is outdated, please provide the runtime platform name manually.");
                        continue;
                    }

                    dockerfileRuntimeImage = detectedRuntimeName;
                }

                // If the runtime platform version wasn't previously provided, see if we can detect one from the current detected platform.
                // Note: we first need to ensure that the current detected platform is the same as the runtime platform name previously set or pvodied.
                if (!string.IsNullOrEmpty(dockerfileRuntimeImage) && dockerfileRuntimeImage.Equals(detectedRuntimeName, StringComparison.OrdinalIgnoreCase) &&
                    string.IsNullOrEmpty(dockerfileRuntimeImageTag))
                {
                    dockerfileRuntimeImageTag = this.ConvertToRuntimeVersion(dockerfileRuntimeImage, platformDetectorResult.PlatformVersion);
                }

                // If the runtime image has been set manually or by the platform detection result, stop searching.
                if (!string.IsNullOrEmpty(dockerfileRuntimeImage))
                {
                    break;
                }
            }

            var properties = new DockerfileProperties()
            {
                RuntimeImageName = dockerfileRuntimeImage,
                RuntimeImageTag  = dockerfileRuntimeImageTag,
                BuildImageName   = dockerfileBuildImageName,
                BuildImageTag    = dockerfileBuildImageTag,
            };

            return(TemplateHelper.Render(
                       TemplateHelper.TemplateResource.Dockerfile,
                       properties,
                       this.logger));
        }