Esempio n. 1
0
        public bool InitializeAdminBuildpack(StagingStartRequestAdminBuildpack adminBuildpack, string adminBuildpackDir, bool checkWindowsCompatibility)
        {
            var dir            = Path.Combine(adminBuildpackDir, adminBuildpack.Key);
            var buildpackMutex = new Mutex(false, AdminBuildpackMutexName(adminBuildpack.Key));

            try
            {
                buildpackMutex.WaitOne();

                DownloadAdminBuildpack(adminBuildpack, adminBuildpackDir);

                if (checkWindowsCompatibility)
                {
                    var winBuildpack = BuildpackHasWindowsCompatibleBinaries(dir);
                    if (!winBuildpack)
                    {
                        Logger.Info("Ignoring buildpack {1}. Staging task {0}. Unable to detect compatible windows executables in buildpack bin.", this.Properties.TaskId, dir);
                        return(false);
                    }
                }

                DEAUtilities.DirectoryCopy(dir, Path.Combine(this.Workspace.TempDir, "buildpack"), true);
            }

            finally
            {
                buildpackMutex.ReleaseMutex();
                buildpackMutex.Dispose();
            }

            return(true);
        }
Esempio n. 2
0
        public void PrepareStagingDirs()
        {
            string appDir  = Path.Combine(this.Workspace.StagedDir, "app");
            string logsDir = Path.Combine(this.Workspace.StagedDir, "logs");
            string tmpDir  = Path.Combine(this.Workspace.StagedDir, "tmp");

            Directory.CreateDirectory(appDir);
            Directory.CreateDirectory(logsDir);
            Directory.CreateDirectory(tmpDir);
            DEAUtilities.DirectoryCopy(this.Workspace.UnstagedDir, appDir, true);
        }
Esempio n. 3
0
        public void GetBuildpack(StagingStartMessageRequest message, string gitPath, string buildpacksDir)
        {
            if (message.Properties.Buildpack != null)
            {
                Logger.Info("Staging task {0}: Downloading buildpack from {1}", this.Properties.TaskId, message.Properties.Buildpack);
                Directory.CreateDirectory(Path.Combine(this.Workspace.TempDir, "buildpacks"));
                string buildpackPath = Path.Combine(this.Workspace.TempDir, "buildpacks", Path.GetFileName(new Uri(message.Properties.Buildpack).LocalPath));
                string command       = string.Format("\"{0}\" clone --quiet --recursive {1} {2}", gitPath, message.Properties.Buildpack, buildpackPath);
                Logger.Debug(command);
                int success = Command.ExecuteCommand(command, this.Workspace.TempDir);
                if (success != 0)
                {
                    throw new Exception(string.Format("Failed to git clone buildpack. Exit code: {0}", success));
                }
                this.Buildpack = new Buildpack(buildpackPath, Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);

                bool detected = this.Buildpack.Detect(this.Container);
                if (!detected)
                {
                    throw new Exception("Buildpack does not support this application.");
                }
            }
            else
            {
                Logger.Info("Staging task {0}: Detecting buildpack", this.Properties.TaskId);
                foreach (string dir in Directory.EnumerateDirectories(buildpacksDir))
                {
                    DEAUtilities.DirectoryCopy(dir, Path.Combine(this.Workspace.TempDir, "buildpack"), true);
                    Buildpack bp      = new Buildpack(Path.Combine(this.Workspace.TempDir, "buildpack"), Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);
                    bool      success = bp.Detect(this.Container);
                    if (success)
                    {
                        this.Buildpack = bp;
                        break;
                    }
                    else
                    {
                        Directory.Delete(Path.Combine(this.Workspace.TempDir, "buildpack"), true);
                    }
                }

                if (this.Buildpack == null)
                {
                    throw new Exception("Unable to detect a supported application type");
                }
                Logger.Info("Staging task {0}: Detected buildpack {1}", this.Properties.TaskId, this.Buildpack.Name);
            }
            this.Properties.DetectedBuildpack = this.Buildpack.Name;
        }
Esempio n. 4
0
        public void GetBuildpack(StagingStartMessageRequest message, string gitPath, string buildpacksDir, string adminBuildpackDir)
        {
            string buildpackUrl = message.Properties.Buildpack ?? message.Properties.BuildpackGitUrl;

            if (buildpackUrl != null)
            {
                Logger.Info("Staging task {0}: Downloading buildpack from {1}", this.Properties.TaskId, message.Properties.Buildpack);
                Directory.CreateDirectory(Path.Combine(this.Workspace.TempDir, "buildpacks"));
                string buildpackPath = Path.Combine(this.Workspace.TempDir, "buildpacks", Path.GetFileName(new Uri(message.Properties.Buildpack).LocalPath));
                string command       = string.Format("set GIT_TERMINAL_PROMPT=0& \"{0}\" clone --quiet --recursive {1} {2}", gitPath, message.Properties.Buildpack, buildpackPath);
                Logger.Debug(command);
                int success = Command.ExecuteCommand(command, this.Workspace.TempDir);
                if (success != 0)
                {
                    throw new Exception(string.Format("Failed to git clone buildpack. Exit code: {0}", success));
                }
                this.Buildpack = new Buildpack(buildpackPath, Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);

                bool detected = this.Buildpack.Detect(this.Container);
                if (!detected)
                {
                    throw new Exception("Buildpack does not support this application.");
                }
            }
            else if (message.Properties.BuildpackKey != null)
            {
                Logger.Info("Staging task {0}: Using admin buildpack {1}", this.Properties.TaskId, message.Properties.BuildpackKey);

                TryCleanupUnusedAdminBuildpacks(message.AdminBuildpacks, adminBuildpackDir);
                var adminBuildpack = message.AdminBuildpacks.First(i => i.Key == message.Properties.BuildpackKey);

                InitializeAdminBuildpack(adminBuildpack, adminBuildpackDir, false);

                this.Buildpack = new Buildpack(Path.Combine(this.Workspace.TempDir, "buildpack"), Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);

                bool detected = this.Buildpack.Detect(this.Container);
                if (!detected)
                {
                    throw new InvalidOperationException("Buildpack does not support this application.");
                }
            }
            else
            {
                Logger.Info("Staging task {0}: Detecting buildpack", this.Properties.TaskId);

                if (message.AdminBuildpacks != null)
                {
                    TryCleanupUnusedAdminBuildpacks(message.AdminBuildpacks, adminBuildpackDir);

                    foreach (var adminBuildpack in message.AdminBuildpacks)
                    {
                        if (!InitializeAdminBuildpack(adminBuildpack, adminBuildpackDir, true))
                        {
                            continue;
                        }

                        Buildpack bp      = new Buildpack(Path.Combine(this.Workspace.TempDir, "buildpack"), Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);
                        bool      success = bp.Detect(this.Container);
                        if (success)
                        {
                            this.Buildpack = bp;
                            break;
                        }
                        else
                        {
                            Directory.Delete(Path.Combine(this.Workspace.TempDir, "buildpack"), true);
                        }
                    }
                }

                if (this.Buildpack == null)
                {
                    if (Directory.Exists(buildpacksDir))
                    {
                        List <string> systemBuildpacks = Directory.EnumerateDirectories(buildpacksDir).ToList();

                        foreach (string dir in systemBuildpacks)
                        {
                            DEAUtilities.DirectoryCopy(dir, Path.Combine(this.Workspace.TempDir, "buildpack"), true);
                            Buildpack bp      = new Buildpack(Path.Combine(this.Workspace.TempDir, "buildpack"), Path.Combine(this.Workspace.StagedDir, "app"), this.Workspace.Cache, this.Workspace.StagingLogPath);
                            bool      success = bp.Detect(this.Container);
                            if (success)
                            {
                                this.Buildpack = bp;
                                break;
                            }
                            else
                            {
                                Directory.Delete(Path.Combine(this.Workspace.TempDir, "buildpack"), true);
                            }
                        }
                    }
                }

                if (this.Buildpack == null)
                {
                    throw new InvalidOperationException("Unable to detect a supported application type.");
                }
                Logger.Info("Staging task {0}: Detected buildpack {1}", this.Properties.TaskId, this.Buildpack.Name);
            }

            this.Properties.DetectedBuildpack = this.Buildpack.Name;
        }