Beispiel #1
0
        private static void Run(Options options)
        {
            var appPath = Directory.GetCurrentDirectory() + options.BuildDir;
            var files   = Directory.EnumerateFiles(appPath).ToList();

            // Set connection string if there's a web config
            SetConnectionStrings(files);

            // Result.JSON
            var obj = GenerateOutputMetadata(files);

            File.WriteAllText(Directory.GetCurrentDirectory() + options.OutputMetadata, JsonConvert.SerializeObject(obj));

            var buildCacheDir = Directory.GetCurrentDirectory() + options.BuildArtifactsCacheDir;

            Directory.CreateDirectory(buildCacheDir);

            var outputCache = Directory.GetCurrentDirectory() + options.OutputBuildArtifactsCache;

            TarGZFile.CreateFromDirectory(buildCacheDir, outputCache);

            // create droplet
            var outputDropletPath = Directory.GetCurrentDirectory() + options.OutputDroplet;

            TarGZFile.CreateFromDirectory(appPath, outputDropletPath);
        }
Beispiel #2
0
        private static void Run(Options options)
        {
            var appPath = Directory.GetCurrentDirectory() + options.BuildDir;
            var files   = Directory.EnumerateFiles(appPath).ToList();

            // Set connection string if there's a web config
            SetConnectionStrings(files);

            // Result.JSON
            var obj = GenerateOutputMetadata(files);

            File.WriteAllText(Directory.GetCurrentDirectory() + options.OutputMetadata, JsonConvert.SerializeObject(obj));

            // creates an empty output cache directory otherwise, containerizer will throw
            // an exception everytime the rep tries to stream out the directory
            var outputCacheDir = Directory.GetCurrentDirectory() + options.OutputBuildArtifactsCache;

            Directory.CreateDirectory(outputCacheDir);

            // create droplet
            var outputDropletPath = Directory.GetCurrentDirectory() + options.OutputDroplet;

            TarGZFile.CreateFromDirectory(appPath, outputDropletPath);
        }
        private static void Run(Options options)
        {
            var rootDir = Directory.GetCurrentDirectory();

            var appPath       = rootDir + options.BuildDir;
            var buildpacksDir = rootDir + options.BuildpacksDir;

            var buildCacheDir = rootDir + options.BuildArtifactsCacheDir;

            Directory.CreateDirectory(buildCacheDir);

            var outputCache       = rootDir + options.OutputBuildArtifactsCache;
            var outputDropletPath = rootDir + options.OutputDroplet;

            string detectedBuildpack    = "";
            string detectedBuildpackDir = "";
            string detectOutput         = "";
            bool   buildpackDetected    = false;

            var buildpacks = new string[0];

            if (options.BuildpackOrder != null)
            {
                buildpacks = options.BuildpackOrder.Split(new char[] { ',' });
            }

            DownloadBuildpacks(buildpacks, buildpacksDir);

            foreach (var buildpackName in buildpacks)
            {
                var buildpackDir = Path.Combine(buildpacksDir, GetBuildpackDirName(buildpackName));

                if (!IsWindowsBuildpack(buildpackDir))
                {
                    continue;
                }

                if (options.SkipDetect == OptionBool.False)
                {
                    var detectPath = GetExecutable(Path.Combine(buildpackDir, "bin"), "detect");

                    var outputStream = new StringWriter();
                    var exitCode     = RunBuildpackProcess(detectPath, appPath, outputStream, Console.Error);
                    detectOutput = outputStream.ToString();

                    detectOutput = detectOutput.TrimEnd(new char[] { '\n', '\r' });

                    if (exitCode == 0)
                    {
                        detectedBuildpack    = buildpackName;
                        detectedBuildpackDir = buildpackDir;
                        buildpackDetected    = true;
                        break;
                    }
                }
                else
                {
                    detectedBuildpack    = buildpackName;
                    detectedBuildpackDir = buildpackDir;
                    buildpackDetected    = true;
                    break;
                }
            }

            if (!buildpackDetected)
            {
                Console.WriteLine("None of the buildpacks detected a compatible application");
                Environment.Exit(222);
            }

            var compilePath = GetExecutable(Path.Combine(detectedBuildpackDir, "bin"), "compile");

            var compoileExitCode = RunBuildpackProcess(compilePath, appPath + " " + buildCacheDir, Console.Out, Console.Error);

            if (compoileExitCode != 0)
            {
                Console.WriteLine("Failed to compile droplet");
                Environment.Exit(223);
            }

            Dictionary <string, string> procfileProcessTypes = GetProcfileProcessTypes(Directory.EnumerateFiles(appPath).ToList());

            var releaseBinPath = GetExecutable(Path.Combine(detectedBuildpackDir, "bin"), "release");

            var releaseStream   = new StringWriter();
            var releaseExitCode = RunBuildpackProcess(releaseBinPath, appPath, releaseStream, Console.Error);

            if (releaseExitCode != 0)
            {
                Console.WriteLine("Failed to build droplet release");
                Environment.Exit(224);
            }

            var         releaseOutput = releaseStream.ToString();
            ReleaseInfo releaseInfo   = new Deserializer(ignoreUnmatched: true).Deserialize <ReleaseInfo>(new StringReader(releaseOutput));

            var outputMetadata = new OutputMetadata()
            {
                LifecycleType     = "buildpack",
                LifecycleMetadata = new LifecycleMetadata()
                {
                    BuildpackKey      = detectedBuildpack,
                    DetectedBuildpack = detectOutput
                },
                ProcessTypes      = procfileProcessTypes ?? releaseInfo.defaultProcessTypes,
                ExecutionMetadata = ""
            };

            File.WriteAllText(rootDir + options.OutputMetadata, JsonConvert.SerializeObject(outputMetadata));

            TarGZFile.CreateFromDirectory(buildCacheDir + "\\", outputCache);
            TarGZFile.CreateFromDirectory(appPath, outputDropletPath);
        }