/// <summary> /// Determines the version of the runtime image to use in the Dockerfile using the following logic: /// (1) If both the platform name and version are provided, attempt to find the maximum satisfying version /// from the supported runtime version list that meets the version spec "~{VERSION}". If no version can be found, /// default to using the latest version in the list of supported runtime versions. /// (2) If only the platform name is provided, default to using the latest version in the list of supported runtime versions. /// (3) If neither the platform name nor version are provided, default to using the "dynamic" runtime tag. /// </summary> /// <param name="platformName">The name of the platform detected or provided.</param> /// <param name="platformVersion">The version of the platform detected or provided.</param> /// <returns>The converted platform runtime image version.</returns> private string ConvertToRuntimeVersion(string platformName, string platformVersion) { if (!string.IsNullOrEmpty(platformName)) { var runtimeVersions = this.supportedRuntimeVersions[platformName]; if (runtimeVersions == null || !runtimeVersions.Any()) { return(DynamicRuntimeImageTag); } this.logger.LogDebug($"Supported runtime image tags for platform {platformName}: {string.Join(',', runtimeVersions)}"); if (!string.IsNullOrEmpty(platformVersion)) { // We need to check if the detected platform version is in the form of a version spec or not. if (SemanticVersionResolver.IsValidVersion(platformVersion)) { // If it's a valid version, add a semver range specifier. platformVersion = $"~{platformVersion}"; } return(SemanticVersionResolver.GetMaxSatisfyingVersion(platformVersion, runtimeVersions) ?? runtimeVersions.LastOrDefault()); } return(runtimeVersions.LastOrDefault()); } return(DynamicRuntimeImageTag); }
/// <summary> /// Gets a matching version for the platform given a version in SemVer format. /// If the given version is not supported, an exception is thrown. /// </summary> /// <returns>The maximum version that satisfies the requested version spec.</returns> private string GetMatchingTargetVersion(IProgrammingPlatform platform, string targetVersionSpec) { string targetVersion; var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion( targetVersionSpec, platform.SupportedVersions); if (string.IsNullOrEmpty(maxSatisfyingVersion)) { var exc = new UnsupportedVersionException(platform.Name, targetVersionSpec, platform.SupportedVersions); _logger.LogError(exc, $"Exception caught, the given version '{targetVersionSpec}' is not supported for platform '{platform.Name}'."); throw exc; } else { targetVersion = maxSatisfyingVersion; } return(targetVersion); }
/// <summary> /// Gets a matching version for the platform given a version in SemVer format. /// If the given version is not supported, an exception is thrown. /// </summary> /// <returns>The maximum version that satisfies the requested version spec.</returns> private string GetMatchingTargetVersion(IProgrammingPlatform platform, string targetVersionSpec) { string targetVersion; var maxSatisfyingVersion = SemanticVersionResolver.GetMaxSatisfyingVersion( targetVersionSpec, platform.SupportedLanguageVersions); if (string.IsNullOrEmpty(maxSatisfyingVersion)) { var exc = new UnsupportedVersionException( $"The '{platform.Name}' version '{targetVersionSpec}' is not supported. " + $"Supported versions are: {string.Join(", ", platform.SupportedLanguageVersions)}"); _logger.LogError(exc, "Exception caught"); throw exc; } else { targetVersion = maxSatisfyingVersion; } return(targetVersion); }