示例#1
0
            public async Task CreateWebApp(string regionName = "southcentralus")
            {
                var appName = Guid.NewGuid().ToString();
                var nm      = string.Format($"aspnetcoreapp{appName}");

                Console.WriteLine($"Creating web app {nm}");

                try
                {
                    var webApp = await GetSdkClient()
                                 .WebApps
                                 .Define(nm)
                                 .WithRegion(
                        Region.Create(regionName)
                        )
                                 .WithNewResourceGroup(nm)
                                 .WithNewWindowsPlan(pricingTier: PricingTier.BasicB1)
                                 .CreateAsync();

                    Console.WriteLine($"Created web app {nm}");

                    GroupName  = nm;
                    AppName    = nm;
                    RegionName = regionName;

                    // run dotnet publish on application
                    ShellHelper.Bash($"dotnet publish {AppPath} -c Release -o {AppPath}/publish");
                    //zip publish folder
                    var zipFile = ZipContents();
                    // Push to WebApp
                    CLI.UploadFiles(zipFile, GroupName, AppName);
                    // browse to site
                    CLI.BrowseSite(GroupName, AppName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error creating web app {nm} - " + ex.Message);
                    throw ex; // throwing so caller can handle
                }
            }
示例#2
0
    public static int Install()
    {
      var installed = false;

      if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
      {
        var tempFile = Path.ChangeExtension(Path.GetTempFileName(), "msi");
        var msiName = "https://azurecliprod.blob.core.windows.net/msi/azure-cli-latest.msi";

        Spinner.Start($"Download Azure CLI from {msiName}", async () =>
                {
                  Task t = WebUtils.DownloadAsync(msiName, tempFile);
                  t.Wait();
                  await t;
                });

        Spinner.Start($"Running Azure CLI installer at {tempFile}", spinner =>
        {
          var p = Process.Start("msiexec.exe", $"/package \"{tempFile}\"");
          p.WaitForExit();
          installed = true;
        });
      }

      if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
      {
        Spinner.Start("Running Azure CLI installer via homebrew", spinner =>
        {
        // this will almost never fail, ruby is on macOS by default.
        spinner.Info("Checking for dependency of ruby");
          if (!DependencyChecker.Ruby())
          {
            spinner.Fail("ruby required to install azure cli");
            return;
          }
          spinner.Succeed();
        });

        Spinner.Start("Checking for dependency of homebrew", spinner =>
        {
        // we can install homebrew auto
        // ShellHelper("/usr/bin/ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"");
        if (!DependencyChecker.Homebrew())
          {
            spinner.Fail("homebrew required to install azure cli");
            return;
          }
          spinner.Succeed();
        });

        Spinner.Start("Installing azure cli using homebrew", spinner =>
        {
          ShellHelper.Bash("brew update && brew install azure-cli");
          installed = true;
        });
      }

      if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
      {
        // todo
      }

      if (installed)
      {
        Console.WriteLine("Close and reopen this command prompt and run \"az login\" to setup the Azure Command Line");
      }

      return 0;
    }
示例#3
0
 public static void BrowseSite(string resourceGroup, string appName)
 {
     ShellHelper.Bash($"az webapp browse -n {appName} -g {resourceGroup}");
 }
示例#4
0
        public static void UploadFiles(string zipFile, string resourceGroup, string appName)
        {
            var result = ShellHelper.Bash($"az webapp deployment source config-zip -g {resourceGroup} -n {appName} --src {zipFile}");

            Console.WriteLine(result);
        }
示例#5
0
        public static bool IsLoggedIn()
        {
            var result = ShellHelper.Bash("az account list -o table");

            return(result.Contains("az login"));
        }
示例#6
0
        public static bool Login()
        {
            var result = ShellHelper.Bash("az login");

            return(result.Contains("You have logged in."));
        }
示例#7
0
        public static void CreateServicePrincipalFile()
        {
            var result = ShellHelper.Bash("az ad sp create-for-rbac --sdk-auth");

            File.WriteAllText(fileName, result);
        }