示例#1
0
 public TestRepository(string repositoryName, bool obliterateOnDispose)
 {
     _physicalPath = Git.GetRepositoryPath(repositoryName);
     _environment = new TestEnvironment { RepositoryPath = _physicalPath };
     _repository = new GitExeRepository(_environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
     _obliterateOnDispose = obliterateOnDispose;
 }
示例#2
0
        public IRepository EnsureRepository(RepositoryType repositoryType)
        {
            IRepository repository;
            if (repositoryType == RepositoryType.Mercurial)
            {
                if (IsGitRepository)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, RepositoryType.Git, _environment.RepositoryPath));
                }
                FileSystemHelpers.EnsureDirectory(_environment.RepositoryPath);
                repository = new HgRepository(_environment.RepositoryPath, _environment.SiteRootPath, _settings, _traceFactory);
            }
            else 
            {
                if (IsHgRepository)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, RepositoryType.Mercurial, _environment.RepositoryPath));
                }
                repository = new GitExeRepository(_environment, _settings, _traceFactory);
            }

            if (!repository.Exists)
            {
                repository.Initialize();
            }
            return repository;
        }
示例#3
0
 public LibGit2SharpRepository(IEnvironment environment, IDeploymentSettingsManager settings, ITraceFactory tracerFactory)
 {
     _tracerFactory = tracerFactory;
     _settings = settings;
     RepositoryPath = environment.RepositoryPath;
     _legacyGitExeRepository = new GitExeRepository(environment, settings, tracerFactory);
 }
示例#4
0
 public GitExeServer(string path, IProfilerFactory profilerFactory)
 {
     _gitExe = new GitExecutable(path);
     _gitExe.SetTraceLevel(2);
     _profilerFactory = profilerFactory;
     _repository = new GitExeRepository(path, profilerFactory);
     _repository.SetTraceLevel(2);
 }
示例#5
0
 public GitDeploymentRepository(string path, ITraceFactory traceFactory)
 {
     _gitExe = new GitExecutable(path);
     _gitExe.SetTraceLevel(2);
     _traceFactory = traceFactory;
     _repository = new GitExeRepository(path, traceFactory);
     _repository.SetTraceLevel(2);
 }
示例#6
0
 public void GitRepoDoesntExistBeforeInitialize()
 {
     using (TestRepository testRepository = GetRepository())
     {
         var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
         Assert.False(gitRepo.Exists, "git repository shouldn't exist yet");
     }
 }
示例#7
0
 public GitExeServer(string path, IOperationLock initLock, ITraceFactory traceFactory)
 {
     _gitExe = new GitExecutable(path);
     _gitExe.SetTraceLevel(2);
     _traceFactory = traceFactory;
     _repository = new GitExeRepository(path, traceFactory);
     _repository.SetTraceLevel(2);
     _initLock = initLock;
 }
示例#8
0
 public void GitRepoExistsAfterInitialize()
 {
     using (TestRepository testRepository = GetRepository())
     {
         var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
         gitRepo.Initialize();
         Assert.True(gitRepo.Exists, "git repository should exist");
     }
 }
示例#9
0
        public void FetchWithoutConflictOnGitEmptyRepo()
        {
            using (TestRepository testRepository = GetRepository())
            {
                // Arrange
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);

                // Act
                gitRepo.Initialize();
                Assert.Throws<BranchNotFoundException>(() => gitRepo.FetchWithoutConflict("https://github.com/KuduApps/EmptyGitRepo.git", "master"));
            }
        }
示例#10
0
        public GitExeServer(string path, IOperationLock initLock, IDeploymentEnvironment deploymentEnvironment, ITraceFactory traceFactory)
        {
            _gitExe = new GitExecutable(path);
            _traceFactory = traceFactory;
            _repository = new GitExeRepository(path, traceFactory);
            _initLock = initLock;

            // Setup the deployment environment variable to be used by the post receive hook
            _gitExe.EnvironmentVariables[KnownEnviornment.EXEPATH] = deploymentEnvironment.ExePath;
            _gitExe.EnvironmentVariables[KnownEnviornment.APPPATH] = deploymentEnvironment.ApplicationPath;
            _gitExe.EnvironmentVariables[KnownEnviornment.MSBUILD] = deploymentEnvironment.MSBuildExtensionsPath;
            _gitExe.EnvironmentVariables[KnownEnviornment.DEPLOYER] = "";
        }
示例#11
0
        public GitExeServer(string path, IOperationLock initLock, IDeploymentCommandGenerator deploymentCommandGenerator, ITraceFactory traceFactory)
        {
            _gitExe = new GitExecutable(path);
            _gitExe.SetTraceLevel(2);
            _traceFactory = traceFactory;
            _repository = new GitExeRepository(path, traceFactory);
            _repository.SetTraceLevel(2);
            _initLock = initLock;
            _deploymentCommandGenerator = deploymentCommandGenerator;

            // Setup the deployment environment variable to be used by the post receive hook
            _gitExe.EnvironmentVariables[_deploymentCommandGenerator.DeploymentEnvironmentVariable] = _deploymentCommandGenerator.GetDeploymentExePath();
        }
示例#12
0
        public void GitRepoDoesntExistIfCorrupted()
        {
            using (TestRepository testRepository = GetRepository())
            {
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);

                gitRepo.Initialize();
                Assert.True(gitRepo.Exists, "git repository should exist");

                string gitHeadPath = Path.Combine(testRepository.PhysicalPath, ".git", "HEAD");
                File.Delete(gitHeadPath);
                Assert.False(gitRepo.Exists, "git repository shouldn't exist");
            }
        }
示例#13
0
        public void FetchWithoutConflictOnEmptyRepoReturnsFalse()
        {
            using (TestRepository testRepository = GetRepository())
            {
                // Arrange
                var gitRepo = new GitExeRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance);

                // Act
                gitRepo.Initialize();
                var ex = Assert.Throws<InvalidOperationException>(() => gitRepo.FetchWithoutConflict("https://github.com/KuduApps/EmptyGitRepo.git", "master"));

                // Assert
                Assert.Equal("Could not fetch remote branch 'master'. Verify that the branch exists in the repository.", ex.Message);
            }
        }
示例#14
0
        public void GitRepoDoesntExistIfGitRepoOnlyOnParentDirectory()
        {
            using (TestRepository testRepository = GetRepository())
            {
                // Create a repository
                var gitRepo = new GitExeRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                gitRepo.Initialize();

                // Checkout for existence in subdirectory
                var testedPath = Path.Combine(testRepository.PhysicalPath, "subdirectory");
                Directory.CreateDirectory(testedPath);
                gitRepo = new GitExeRepository(testedPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                Assert.False(gitRepo.Exists, "git repository shouldn't exist yet");
            }
        }
示例#15
0
        public void GitGetChangeSetReturnsNullIfIdDoesNotExist()
        {
            // Arrange
            using (TestRepository testRepository = GetRepository())
            {
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                gitRepo.Initialize();

                // Act
                var changeset = gitRepo.GetChangeSet("does-not-exist");

                // Assert
                Assert.Null(changeset);
            }
        }
示例#16
0
        public void GitInitializeCreatesPostCommitHook()
        {
            using (TestRepository testRepository = GetRepository())
            {
                // Arrange
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                string postCommitHookPath = Path.Combine(testRepository.PhysicalPath, ".git", "hooks", "post-receive");
                string expected = "#!/bin/sh\r\nread i\r\necho $i > pushinfo\r\n\"$KUDU_EXE\" \"$KUDU_APPPATH\" \"$KUDU_MSBUILD\" \"$KUDU_DEPLOYER\"\n";

                // Act
                gitRepo.Initialize();

                // Assert
                Assert.Equal(expected, File.ReadAllText(postCommitHookPath));
            }
        }
示例#17
0
        public GitExeServer(string path, string homePath, IOperationLock initLock, string logFileEnv, IDeploymentEnvironment deploymentEnvironment, ITraceFactory traceFactory)
        {
            _gitExe = new GitExecutable(path);
            _gitExe.SetHomePath(homePath);
            _traceFactory = traceFactory;
            _repository = new GitExeRepository(path, homePath, traceFactory);
            _initLock = initLock;

            // Transfer logFileEnv => git.exe => kudu.exe, this represent per-request tracefile
            _gitExe.EnvironmentVariables[Constants.TraceFileEnvKey] = logFileEnv;

            // Setup the deployment environment variable to be used by the post receive hook
            _gitExe.EnvironmentVariables[KnownEnvironment.EXEPATH] = deploymentEnvironment.ExePath;
            _gitExe.EnvironmentVariables[KnownEnvironment.APPPATH] = deploymentEnvironment.ApplicationPath;
            _gitExe.EnvironmentVariables[KnownEnvironment.MSBUILD] = deploymentEnvironment.MSBuildExtensionsPath;
            _gitExe.EnvironmentVariables[KnownEnvironment.DEPLOYER] = "";
        }
示例#18
0
        public void GitExecuteWithRetryTest(string message, int expect)
        {
            // Mock
            var settings = new Mock<IDeploymentSettingsManager>();
            var trace = new Mock<ITraceFactory>();

            var repository = new GitExeRepository(Mock.Of<IEnvironment>(), settings.Object, trace.Object);
            Exception exception = null;
            var actual = 0;

            // Setup
            trace.Setup(t => t.GetTracer())
                 .Returns(() => NullTracer.Instance);

            // Test
            try
            {
                repository.ExecuteGenericGitCommandWithRetryAndCatchingWellKnownGitErrors(() =>
                {
                    ++actual;
                    if (message == null)
                    {
                        return true;
                    }

                    throw new Exception(message);
                });
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // Assert
            Assert.Equal(expect, actual);
            Assert.Equal(message, (exception == null) ? null : exception.Message);
        }
示例#19
0
        public GitExeServer(string path, string homePath, IOperationLock initLock, string logFileEnv, IDeploymentEnvironment deploymentEnvironment, IDeploymentSettingsManager settings, ITraceFactory traceFactory)
        {
            // Honor settings if longer
            var gitTimeout = settings.GetCommandIdleTimeout();
            if (gitTimeout < _gitMinTimeout)
            {
                gitTimeout = _gitMinTimeout;
            }

            _gitExe = new GitExecutable(path, gitTimeout);
            _gitExe.SetHomePath(homePath);
            _traceFactory = traceFactory;
            _repository = new GitExeRepository(path, homePath, settings, traceFactory);
            _initLock = initLock;

            // Transfer logFileEnv => git.exe => kudu.exe, this represent per-request tracefile
            _gitExe.EnvironmentVariables[Constants.TraceFileEnvKey] = logFileEnv;

            // Setup the deployment environment variable to be used by the post receive hook
            _gitExe.EnvironmentVariables[KnownEnvironment.EXEPATH] = deploymentEnvironment.ExePath;
            _gitExe.EnvironmentVariables[KnownEnvironment.APPPATH] = deploymentEnvironment.ApplicationPath;
            _gitExe.EnvironmentVariables[KnownEnvironment.MSBUILD] = deploymentEnvironment.MSBuildExtensionsPath;
            _gitExe.EnvironmentVariables[KnownEnvironment.DEPLOYER] = "";
        }
 public GitDeploymentRepository(string path, string homePath, ITraceFactory traceFactory)
 {
     _path = path;
     _traceFactory = traceFactory;
     _repository = new GitExeRepository(path, homePath, traceFactory);
 }
示例#21
0
 public TestRepository(string repositoryName, bool obliterateOnDispose)
 {
     _physicalPath = Git.GetRepositoryPath(repositoryName);
     _repository = new GitExeRepository(_physicalPath);
     _obliterateOnDispose = obliterateOnDispose;
 }
示例#22
0
        public void GitClearLockRemovesHeadAndIndexLocks()
        {
            using (var testRepo = GetRepository())
            {
                // Arrange
                Git.Init(testRepo.PhysicalPath);
                string fileToWrite = Path.Combine(testRepo.PhysicalPath, "some file.txt");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "index.lock"), "");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "HEAD.lock"), "");
                File.WriteAllText(fileToWrite, "Hello world");
                var env = new TestEnvironment
                {
                    RepositoryPath = testRepo.PhysicalPath
                };
                var gitRepo = new GitExeRepository(env, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);


                // Assert - 1
                var ex = Assert.Throws<CommandLineException>(() => Git.Add(testRepo.PhysicalPath, fileToWrite));
                Assert.Contains(".git/index.lock': File exists.", ex.Message);
                
                // Act - 2
                gitRepo.ClearLock();
                Git.Add(testRepo.PhysicalPath, fileToWrite);
            }

        }
示例#23
0
        public void GitRepoParsesCommitDetails(string id, ChangeSet expectedChangeset)
        {
            using (var testRepository = Git.Clone("Mvc3Application_NoSolution"))
            {
                // Arrange
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);

                // Act
                var changeset = gitRepo.GetChangeSet(id);

                // Assert
                Assert.Equal(expectedChangeset.Id, changeset.Id);
                Assert.Equal(expectedChangeset.AuthorName, changeset.AuthorName);
                Assert.Equal(expectedChangeset.AuthorEmail, changeset.AuthorEmail);
                Assert.Equal(expectedChangeset.Message, changeset.Message.Trim());
                Assert.Equal(expectedChangeset.Timestamp, changeset.Timestamp);
            }
        }
示例#24
0
 public TestRepository(string repositoryName)
 {
     _physicalPath = Git.GetRepositoryPath(repositoryName);
     _repository = new GitExeRepository(_physicalPath);
 }
示例#25
0
 public IRepository GetCustomRepository()
 {
     ITracer tracer = _traceFactory.GetTracer();
     if (IsCustomGitRepository)
     {
         tracer.Trace("Assuming custom git repository at {0}", _environment.RepositoryPath);
         var ret = new GitExeRepository(_environment, _settings, _traceFactory);
         ret.SkipPostReceiveHookCheck = true;
         return ret;
     }
     return null;
 }
示例#26
0
        public IRepository EnsureRepository(RepositoryType repositoryType)
        {
            // Validate if conflicting with existing repository
            RepositoryType existingType;
            if (TryGetExistingRepositoryType(out existingType) && existingType != repositoryType)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MismatchRepository, repositoryType, existingType, _environment.RepositoryPath));
            }

            IRepository repository;
            if (repositoryType == RepositoryType.None)
            {
                repository = new NullRepository(_environment, _traceFactory, _httpContext);
            }
            else if (repositoryType == RepositoryType.Mercurial)
            {
                FileSystemHelpers.EnsureDirectory(_environment.RepositoryPath);
                repository = new HgRepository(_environment.RepositoryPath, _environment.RootPath, _settings, _traceFactory);
            }
            else
            {
                repository = new GitExeRepository(_environment, _settings, _traceFactory);
            }

            if (!repository.Exists)
            {
                repository.Initialize();
            }
            return repository;
        }
示例#27
0
        static int Main(string[] args)
        {
            // Turn flag on in app.config to wait for debugger on launch
            if (ConfigurationManager.AppSettings["WaitForDebuggerOnStart"] == "true")
            {
                while (!Debugger.IsAttached)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }

            if (args.Length < 2)
            {
                System.Console.WriteLine("Usage: kudu.exe appRoot wapTargets [deployer]");
                return 1;
            }

            // The post receive hook launches the exe from sh and intereprets newline differently.
            // This fixes very wacky issues with how the output shows up in the conosle on push
            System.Console.Error.NewLine = "\n";
            System.Console.Out.NewLine = "\n";

            System.Environment.SetEnvironmentVariable("GIT_DIR", null, System.EnvironmentVariableTarget.Process);

            string appRoot = args[0];
            string wapTargets = args[1];
            string deployer = args.Length == 2 ? null : args[2];

            IEnvironment env = GetEnvironment(appRoot);
            ISettings settings = new XmlSettings.Settings(GetSettingsPath(env));
            IDeploymentSettingsManager settingsManager = new DeploymentSettingsManager(settings);

            // Adjust repo path
            env.RepositoryPath = Path.Combine(env.SiteRootPath, settingsManager.GetRepositoryPath());

            // Setup the trace
            IFileSystem fileSystem = new FileSystem();
            TraceLevel level = settingsManager.GetTraceLevel();
            ITracer tracer = GetTracer(env, level, fileSystem);
            ITraceFactory traceFactory = new TracerFactory(() => tracer);

            // Calculate the lock path
            string lockPath = Path.Combine(env.SiteRootPath, Constants.LockPath);
            string deploymentLockPath = Path.Combine(lockPath, Constants.DeploymentLockFile);
            string statusLockPath = Path.Combine(lockPath, Constants.StatusLockFile);
            IOperationLock deploymentLock = new LockFile(deploymentLockPath, traceFactory, fileSystem);
            IOperationLock statusLock = new LockFile(statusLockPath, traceFactory, fileSystem);

            IBuildPropertyProvider buildPropertyProvider = new BuildPropertyProvider();
            ISiteBuilderFactory builderFactory = new SiteBuilderFactory(buildPropertyProvider, env);

            IRepository gitRepository = new GitExeRepository(env, settingsManager, traceFactory);

            var logger = new ConsoleLogger();
            IDeploymentManager deploymentManager = new DeploymentManager(builderFactory,
                                                          env, 
                                                          fileSystem, 
                                                          traceFactory, 
                                                          settingsManager,
                                                          new DeploymentStatusManager(env, fileSystem, statusLock),
                                                          deploymentLock,
                                                          GetLogger(env, level, logger));

            var step = tracer.Step("Executing external process", new Dictionary<string, string>
            {
                { "type", "process" },
                { "path", "kudu.exe" },
                { "arguments", appRoot + " " + wapTargets }
            });

            using (step)
            {
                try
                {
                    deploymentManager.Deploy(gitRepository, changeSet: null, deployer: deployer, clean: false);
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine(e.Message);
                    System.Console.Error.WriteLine(Resources.Log_DeploymentError);
                    return 1;
                }
            }

            if (logger.HasErrors)
            {
                System.Console.Error.WriteLine(Resources.Log_DeploymentError);
                return 1;
            }

            return 0;
        }
示例#28
0
 public HybridGitRepository(string path)
 {
     _exeRepository = new GitExeRepository(path);
     _libgitRepository = new LibGitRepository(path);
 }
示例#29
0
 public GitDeploymentRepository(string path, string homePath, ITraceFactory traceFactory)
 {
     _path         = path;
     _traceFactory = traceFactory;
     _repository   = new GitExeRepository(path, homePath, traceFactory);
 }
示例#30
0
 public GitDeploymentRepository(string path, ITraceFactory traceFactory)
 {
     _gitExe       = new GitExecutable(path);
     _traceFactory = traceFactory;
     _repository   = new GitExeRepository(path, traceFactory);
 }
示例#31
0
文件: Program.cs 项目: shibayan/kudu
        private static int PerformDeploy(
            string appRoot,
            string wapTargets,
            string deployer,
            string lockPath,
            IEnvironment env,
            IDeploymentSettingsManager settingsManager,
            TraceLevel level,
            ITracer tracer,
            ITraceFactory traceFactory,
            IOperationLock deploymentLock)
        {
            System.Environment.SetEnvironmentVariable("GIT_DIR", null, System.EnvironmentVariableTarget.Process);

            // Skip SSL Certificate Validate
            OperationClient.SkipSslValidationIfNeeded();

            // Adjust repo path
            env.RepositoryPath = Path.Combine(env.SiteRootPath, settingsManager.GetRepositoryPath());

            string statusLockPath = Path.Combine(lockPath, Constants.StatusLockFile);
            string hooksLockPath = Path.Combine(lockPath, Constants.HooksLockFile);

            IOperationLock statusLock = new LockFile(statusLockPath, traceFactory);
            IOperationLock hooksLock = new LockFile(hooksLockPath, traceFactory);

            IBuildPropertyProvider buildPropertyProvider = new BuildPropertyProvider();
            ISiteBuilderFactory builderFactory = new SiteBuilderFactory(buildPropertyProvider, env);
            var logger = new ConsoleLogger();

            IRepository gitRepository;
            if (settingsManager.UseLibGit2SharpRepository())
            {
                gitRepository = new LibGit2SharpRepository(env, settingsManager, traceFactory);
            }
            else
            {
                gitRepository = new GitExeRepository(env, settingsManager, traceFactory);
            }

            IServerConfiguration serverConfiguration = new ServerConfiguration();
            IAnalytics analytics = new Analytics(settingsManager, serverConfiguration, traceFactory);

            IWebHooksManager hooksManager = new WebHooksManager(tracer, env, hooksLock);
            IDeploymentStatusManager deploymentStatusManager = new DeploymentStatusManager(env, analytics, statusLock);
            IAutoSwapHandler autoSwapHander = new AutoSwapHandler(env, settingsManager, traceFactory);
            var functionManager = new FunctionManager(env, traceFactory);
            IDeploymentManager deploymentManager = new DeploymentManager(builderFactory,
                                                          env,
                                                          traceFactory,
                                                          analytics,
                                                          settingsManager,
                                                          deploymentStatusManager,
                                                          deploymentLock,
                                                          GetLogger(env, level, logger),
                                                          hooksManager,
                                                          functionManager);

            var step = tracer.Step(XmlTracer.ExecutingExternalProcessTrace, new Dictionary<string, string>
            {
                { "type", "process" },
                { "path", "kudu.exe" },
                { "arguments", appRoot + " " + wapTargets }
            });

            using (step)
            {
                try
                {
                    deploymentManager.DeployAsync(gitRepository, changeSet: null, deployer: deployer, clean: false)
                        .Wait();

                    string branch = settingsManager.GetBranch();
                    ChangeSet changeSet = gitRepository.GetChangeSet(branch);
                    IDeploymentStatusFile statusFile = deploymentStatusManager.Open(changeSet.Id);
                    if (statusFile != null && statusFile.Status == DeployStatus.Success)
                    {
                        autoSwapHander.HandleAutoSwap(changeSet.Id, deploymentManager.GetLogger(changeSet.Id), tracer).Wait();
                    }
                }
                catch (Exception e)
                {
                    tracer.TraceError(e);

                    System.Console.Error.WriteLine(e.GetBaseException().Message);
                    System.Console.Error.WriteLine(Resources.Log_DeploymentError);
                    return 1;
                }
            }

            if (logger.HasErrors)
            {
                System.Console.Error.WriteLine(Resources.Log_DeploymentError);
                return 1;
            }

            return 0;
        }
示例#32
0
 public HybridGitRepository(string path)
 {
     _exeRepository    = new GitExeRepository(path);
     _libgitRepository = new LibGitRepository(path);
 }