private string RunStartupScriptGeneratorForPlatform(
            IProgrammingPlatform platform,
            RunScriptGeneratorContext ctx)
        {
            var scriptGenPath = FilePaths.RunScriptGeneratorDir + "/" + platform.Name;
            var scriptGenArgs = new List <string>();

            // 'create-script' is only supported for these platform as of now
            if (platform is NodePlatform || platform is PythonPlatform)
            {
                scriptGenArgs.Add("create-script");
            }

            scriptGenArgs.AddRange(new[] { "-appPath", ctx.SourceRepo.RootPath, "-output", _tempScriptPath });

            if (ctx.PassThruArguments != null)
            {
                scriptGenArgs.AddRange(ctx.PassThruArguments);
            }

            (int exitCode, string stdout, string stderr) = ProcessHelper.RunProcess(
                scriptGenPath, scriptGenArgs, Environment.CurrentDirectory, RunScriptGeneratorTimeout);

            if (exitCode != ProcessConstants.ExitSuccess)
            {
                _logger.LogError("Generated run script returned exit code '{exitCode}'", exitCode);
                throw new Exception($"{scriptGenPath} failed");
            }

            return(File.ReadAllText(_tempScriptPath));
        }
Exemple #2
0
        private bool IsEnabledForMultiPlatformBuild(IProgrammingPlatform platform, DockerfileContext ctx)
        {
            if (ctx.DisableMultiPlatformBuild)
            {
                return(false);
            }

            return(platform.IsEnabledForMultiPlatformBuild(ctx));
        }
Exemple #3
0
        private bool IsEnabledForMultiPlatformBuild(IProgrammingPlatform platform, BuildScriptGeneratorContext context)
        {
            if (context.DisableMultiPlatformBuild)
            {
                return(false);
            }

            return(platform.IsEnabledForMultiPlatformBuild(context));
        }
        private bool IsEnabledForMultiPlatformBuild(IProgrammingPlatform platform, RepositoryContext ctx)
        {
            if (_commonOptions.EnableMultiPlatformBuild)
            {
                return(platform.IsEnabledForMultiPlatformBuild(ctx));
            }

            return(false);
        }
        public string GenerateBashScript(RunScriptGeneratorContext ctx)
        {
            if (ctx.SourceRepo == null)
            {
                throw new ArgumentNullException(nameof(ctx.SourceRepo), "Source repository must be supplied.");
            }

            IProgrammingPlatform targetPlatform = null;

            if (!string.IsNullOrEmpty(ctx.Platform))
            {
                targetPlatform = _programmingPlatforms
                                 .Where(p => p.Name.EqualsIgnoreCase(ctx.Platform))
                                 .FirstOrDefault();

                if (targetPlatform == null)
                {
                    throw new UnsupportedPlatformException($"Platform '{ctx.Platform}' is not supported.");
                }
            }
            else
            {
                _logger.LogDebug("No platform provided for run-script command; attempting to determine platform...");
                foreach (var platform in _programmingPlatforms)
                {
                    _logger.LogDebug($"Checking if platform '{platform.Name}' is compatible...");
                    var detectionResult = platform.Detect(ctx);
                    if (detectionResult != null)
                    {
                        _logger.LogDebug($"Detected platform '{detectionResult.Language}' with version '{detectionResult.LanguageVersion}'.");
                        if (string.IsNullOrEmpty(detectionResult.LanguageVersion))
                        {
                            throw new UnsupportedVersionException($"Couldn't detect a version for platform '{detectionResult.Language}' in the repo.");
                        }

                        targetPlatform = platform;
                        break;
                    }
                }

                if (targetPlatform == null)
                {
                    throw new UnsupportedPlatformException("Unable to determine the platform for the given repo.");
                }
            }

            return(RunStartupScriptGeneratorForPlatform(targetPlatform, ctx));
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        private string RunStartupScriptGeneratorForPlatform(IProgrammingPlatform plat, RunScriptGeneratorOptions opts)
        {
            var scriptGenPath = FilePaths.RunScriptGeneratorDir + "/" + plat.Name;

            var scriptGenArgs = new List <string> {
                "-appPath", opts.SourceRepo.RootPath, "-output", _tempScriptPath
            };

            scriptGenArgs.AddRange(opts.PassThruArguments);

            (int exitCode, string stdout, string stderr) = ProcessHelper.RunProcess(
                scriptGenPath, scriptGenArgs, Environment.CurrentDirectory, RunScriptGeneratorTimeout);

            if (exitCode != ProcessConstants.ExitSuccess)
            {
                _logger.LogError("{scriptGenPath} returned {exitCode}", scriptGenPath, exitCode);
                throw new Exception("{scriptGenPath} failed");
            }

            return(File.ReadAllText(_tempScriptPath));
        }
Exemple #8
0
        /// <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);
        }
 private DefaultBuildScriptGenerator CreateDefaultScriptGenerator(IProgrammingPlatform platform)
 {
     return(CreateDefaultScriptGenerator(new[] { platform }));
 }
 private DefaultBuildScriptGenerator CreateDefaultScriptGenerator(
     IProgrammingPlatform platform,
     BuildScriptGeneratorOptions commonOptions)
 {
     return(CreateDefaultScriptGenerator(new[] { platform }, commonOptions, checkers: null));
 }
Exemple #11
0
        public IList <Tuple <IProgrammingPlatform, string> > GetCompatiblePlatforms(BuildScriptGeneratorContext ctx)
        {
            var resultPlatforms = new List <Tuple <IProgrammingPlatform, string> >();

            var enabledPlatforms = _programmingPlatforms.Where(p =>
            {
                if (!p.IsEnabled(ctx))
                {
                    _logger.LogDebug("{platformName} has been disabled", p.Name);
                    return(false);
                }
                return(true);
            });

            // If a user supplied the language explicitly, check if the platform is enabled for that
            IProgrammingPlatform userSuppliedPlatform = null;
            string platformVersion = null;

            if (!string.IsNullOrEmpty(ctx.Language))
            {
                var selectedPlatform = enabledPlatforms
                                       .Where(p => string.Equals(ctx.Language, p.Name, StringComparison.OrdinalIgnoreCase))
                                       .FirstOrDefault();

                if (selectedPlatform == null)
                {
                    ThrowInvalidLanguageProvided(ctx);
                }

                userSuppliedPlatform = selectedPlatform;

                platformVersion = ctx.LanguageVersion;
                if (string.IsNullOrEmpty(platformVersion))
                {
                    var detectionResult = userSuppliedPlatform.Detect(ctx.SourceRepo);
                    if (detectionResult == null || string.IsNullOrEmpty(detectionResult.LanguageVersion))
                    {
                        throw new UnsupportedVersionException(
                                  $"Couldn't detect a version for the platform '{userSuppliedPlatform.Name}' in the repo.");
                    }

                    platformVersion = detectionResult.LanguageVersion;
                }

                resultPlatforms.Add(Tuple.Create(userSuppliedPlatform, platformVersion));

                // if the user explicitly supplied a platform and if that platform does not want to be part of
                // multi-platform builds, then short-circuit immediately ignoring going through other platforms
                if (!IsEnabledForMultiPlatformBuild(userSuppliedPlatform, ctx))
                {
                    return(resultPlatforms);
                }
            }

            // Ignore processing the same platform again
            if (userSuppliedPlatform != null)
            {
                enabledPlatforms = enabledPlatforms.Where(p => !ReferenceEquals(p, userSuppliedPlatform));
            }

            foreach (var platform in enabledPlatforms)
            {
                string targetVersionSpec = null;

                _logger.LogDebug("Detecting platform using {platformName}", platform.Name);
                var detectionResult = platform.Detect(ctx.SourceRepo);
                if (detectionResult != null)
                {
                    _logger.LogDebug(
                        "Detected {platformName} version {platformVersion} for app in repo",
                        platform.Name,
                        detectionResult.LanguageVersion);

                    targetVersionSpec = detectionResult.LanguageVersion;
                    if (string.IsNullOrEmpty(targetVersionSpec))
                    {
                        throw new UnsupportedVersionException(
                                  $"Couldn't detect a version for the platform '{platform.Name}' in the repo.");
                    }

                    resultPlatforms.Add(Tuple.Create(platform, targetVersionSpec));

                    if (!IsEnabledForMultiPlatformBuild(platform, ctx))
                    {
                        return(resultPlatforms);
                    }
                }
            }

            return(resultPlatforms);
        }
Exemple #12
0
 private DefaultDockerfileGenerator CreateDefaultDockerfileGenerator(IProgrammingPlatform platform)
 {
     return(CreateDefaultDockerfileGenerator(new[] { platform }));
 }
 private DefaultBuildScriptGenerator CreateDefaultScriptGenerator(
     IProgrammingPlatform generator)
 {
     return(new DefaultBuildScriptGenerator(new[] { generator }, new TestEnvironmentSettingsProvider(), NullLogger <DefaultBuildScriptGenerator> .Instance));
 }
 private DefaultDockerfileGenerator CreateDefaultDockerfileGenerator(
     IProgrammingPlatform platform,
     BuildScriptGeneratorOptions commonOptions)
 {
     return(CreateDefaultDockerfileGenerator(new[] { platform }, commonOptions));
 }
Exemple #15
0
 /// <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)
 {
     return(platform.GetMaxSatisfyingVersionAndVerify(targetVersionSpec));
 }