Example #1
0
 private void EnsureFilePermission()
 {
     if (!OSDetector.IsOnWindows())
     {
         PermissionHelper.Chmod("600", _id_rsa, _environment, _deploymentSettingManager, NullLogger.Instance);
         PermissionHelper.Chmod("644", _id_rsaPub, _environment, _deploymentSettingManager, NullLogger.Instance);
     }
 }
Example #2
0
 private string GetLinuxPostBuildFilepath(DeploymentContext context, FileInfo fi)
 {
     if (string.Equals(".sh", fi.Extension, StringComparison.OrdinalIgnoreCase))
     {
         context.Logger.Log("Add execute permission for post build script " + fi.FullName);
         PermissionHelper.Chmod("ugo+x", fi.FullName, Environment, DeploymentSettings, context.Logger);
         return(string.Format(CultureInfo.InvariantCulture, "\"{0}\"", fi.FullName));
     }
     return(null);
 }
        private void GenerateScript(DeploymentContext context, ILogger buildLogger)
        {
            try
            {
                using (context.Tracer.Step("Generating deployment script"))
                {
                    var scriptGenerator = ExternalCommandFactory.BuildExternalCommandExecutable(RepositoryPath, context.OutputPath, buildLogger);

                    // Set home path to the user profile so cache directories created by azure-cli are created there
                    scriptGenerator.SetHomePath(System.Environment.GetEnvironmentVariable("APPDATA"));

                    var scriptGeneratorCommandArguments = String.Format(ScriptGeneratorCommandArgumentsFormat, RepositoryPath, Environment.DeploymentToolsPath, ScriptGeneratorCommandArguments);
                    var scriptGeneratorCommand          = "\"{0}\" {1}".FormatInvariant(DeploymentScriptGeneratorToolPath, scriptGeneratorCommandArguments);

                    bool cacheUsed = UseCachedDeploymentScript(scriptGeneratorCommandArguments, context);
                    if (!cacheUsed)
                    {
                        buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommandArguments);

                        scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, scriptGeneratorCommand);

                        if (!OSDetector.IsOnWindows())
                        {
                            // Kuduscript output is typically not given execute permission, so add it
                            var deploymentScriptPath = DeploymentManager.GetCachedDeploymentScriptPath(Environment);
                            PermissionHelper.Chmod("ugo+x", deploymentScriptPath, Environment, DeploymentSettings, buildLogger);
                        }

                        CacheDeploymentScript(scriptGeneratorCommandArguments, context);
                    }
                    else
                    {
                        buildLogger.Log(Resources.Log_DeploymentScriptGeneratorUsingCache, scriptGeneratorCommandArguments);
                    }
                }
            }
            catch (Exception ex)
            {
                context.Tracer.TraceError(ex);

                // HACK: Log an empty error to the global logger (post receive hook console output).
                // The reason we don't log the real exception is because the 'live output' running
                // msbuild has already been captured.
                context.GlobalLogger.LogError();

                throw;
            }
        }
Example #4
0
        public override Task Build(DeploymentContext context)
        {
            string commandFullPath = _command;
            var    tcs             = new TaskCompletionSource <object>();

            context.Logger.Log("Running custom deployment command...");

            try
            {
                if (!OSDetector.IsOnWindows())
                {
                    if (commandFullPath.StartsWith(".", StringComparison.OrdinalIgnoreCase))
                    {
                        string finalCommandPath = Path.GetFullPath(Path.Combine(RepositoryPath, commandFullPath));
                        if (File.Exists(finalCommandPath))
                        {
                            commandFullPath = finalCommandPath;
                        }
                    }

                    if (commandFullPath.Contains(RepositoryPath))
                    {
                        context.Logger.Log("Setting execute permissions for " + commandFullPath);
                        PermissionHelper.Chmod("ugo+x", commandFullPath, Environment, DeploymentSettings, context.Logger);
                    }
                    else
                    {
                        context.Logger.Log("Not setting execute permissions for " + commandFullPath);
                    }
                }

                RunCommand(context, _command, ignoreManifest: false);

                tcs.SetResult(null);
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }

            return(tcs.Task);
        }
        public void Initialize()
        {
            var tracer = _tracerFactory.GetTracer();

            using (tracer.Step("GitExeRepository.Initialize"))
            {
                Execute(tracer, "init");

                Execute(tracer, "config core.autocrlf {0}", OSDetector.IsOnWindows() ? "true" : "false");

                // This speeds up git operations like 'git checkout', especially on slow drives like in Azure
                Execute(tracer, "config core.preloadindex true");

                Execute(tracer, @"config user.name ""{0}""", _settings.GetGitUsername());
                Execute(tracer, @"config user.email ""{0}""", _settings.GetGitEmail());

                // This is needed to make lfs work
                Execute(tracer, @"config filter.lfs.clean ""git-lfs clean %f""");
                Execute(tracer, @"config filter.lfs.smudge ""git-lfs smudge %f""");
                Execute(tracer, @"config filter.lfs.required true");

                using (tracer.Step("Configure git server"))
                {
                    // Allow getting pushes even though we're not bare
                    Execute(tracer, "config receive.denyCurrentBranch ignore");
                }

                // to disallow browsing to this folder in case of in-place repo
                using (tracer.Step("Create deny users for .git folder"))
                {
                    string content = "<?xml version=\"1.0\"" + @"?>
<configuration>
  <system.web>
    <authorization>
      <deny users=" + "\"*\"" + @"/>
    </authorization>
  </system.web>
<configuration>";

                    File.WriteAllText(Path.Combine(_gitExe.WorkingDirectory, ".git", "web.config"), content);
                }

                // Server env does not support interactive cred prompt; hence, we intercept any credential provision
                // for git fetch/clone with http/https scheme and return random invalid u/p forcing 'fatal: Authentication failed.'
                using (tracer.Step("Configure git-credential"))
                {
                    FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(GitCredentialHookPath));

                    string content = @"#!/bin/sh
if [ " + "\"$1\" = \"get\"" + @" ]; then
      echo username=dummyUser
      echo password=dummyPassword
fi" + "\n";

                    File.WriteAllText(GitCredentialHookPath, content);

                    Execute(tracer, "config credential.helper \"!'{0}'\"", GitCredentialHookPath);
                }

                using (tracer.Step("Setup post receive hook"))
                {
                    FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(PostReceiveHookPath));

                    //#!/bin/sh
                    //read i
                    //echo $i > pushinfo
                    //KnownEnvironment.KUDUCOMMAND
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("#!/bin/sh");
                    sb.AppendLine("read i");
                    sb.AppendLine("echo $i > pushinfo");
                    sb.AppendLine(KnownEnvironment.KUDUCOMMAND);
                    if (OSDetector.IsOnWindows())
                    {
                        FileSystemHelpers.WriteAllText(PostReceiveHookPath, sb.ToString());
                    }
                    else
                    {
                        FileSystemHelpers.WriteAllText(PostReceiveHookPath, sb.ToString().Replace("\r\n", "\n"));
                        using (tracer.Step("Non-Windows enviroment, granting 755 permission to post-receive hook file"))
                        {
                            PermissionHelper.Chmod("755", PostReceiveHookPath, _environment, _settings, NullLogger.Instance);
                        }
                    }
                }

                // NOTE: don't add any new init steps after creating the post receive hook,
                // as it's also used to mark that Init was fully executed
            }
        }