コード例 #1
0
            public async Task CreateWebApp()
            {
                var     appProfile = GetAppProfile();
                IWebApp webApp     = null;


                await Spinner.StartAsync("", async spinner =>
                {
                    spinner.Text = $"Starting deployment for {appProfile.profile.PublishName}";

                    if (appProfile.isNew)
                    {
                        spinner.Text = $"Creating web app {appProfile.profile.PublishName}";

                        // create the webapp
                        try
                        {
                            if (appProfile.profile.PricingTier == PricingTier.SharedD1)
                            {
                                webApp = await GetSdkClient()
                                         .WebApps.Define(appProfile.profile.PublishName)
                                         .WithRegion(appProfile.profile.Region)
                                         .WithNewResourceGroup(appProfile.profile.ResourceGroup)
                                         .WithNewSharedAppServicePlan()
                                         .CreateAsync();
                            }
                            else
                            {
                                webApp = await GetSdkClient()
                                         .WebApps.Define(appProfile.profile.PublishName)
                                         .WithRegion(appProfile.profile.Region)
                                         .WithNewResourceGroup(appProfile.profile.ResourceGroup)
                                         .WithNewWindowsPlan(appProfile.profile.PricingTier)
                                         .CreateAsync();
                            }
                        }
                        catch (LogingException loginEx)
                        {
                            spinner.Fail(loginEx.Message);
                            return;
                        }
                        catch (Exception ex)
                        {
                            spinner.Fail($"Error creating web app {appProfile.profile.PublishName} - " + ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        spinner.Text = $"{appProfile.profile.PublishName} already published, updating files.";

                        webApp = GetSdkClient()
                                 .WebApps.GetByResourceGroup(appProfile.profile.ResourceGroup, appProfile.profile.PublishName);
                    }

                    // get the zipdeploy url
                    var webUri = new Uri(string.Format("https://{0}.scm.azurewebsites.net/api/zipdeploy", appProfile.profile.PublishName));


                    spinner.Text = "Retrieving publishing profile.";
                    // get the publishing profile and create the auth token
                    var publishProfile = webApp.GetPublishingProfile();
                    var ftpUser        = publishProfile.FtpUsername.Split('\\')[1];
                    var val            = Convert.ToBase64String(Encoding.Default.GetBytes($"{ftpUser}:{publishProfile.FtpPassword}"));
                    string authToken   = $"Basic {val}";

                    try
                    {
                        spinner.Text = "Running dotnet publish.";
                        // run dotnet publish on application
                        try
                        {
                            var results = ShellHelper.Cmd($"dotnet publish {AppPath} -c Release -o {AppPath}/publish");
                            if (results.Contains(": error"))
                            {
                                throw new DotNetPublishException("Error building application", new Exception(results));
                            }
                        }
                        catch (DotNetPublishException dnex)
                        {
                            spinner.Fail(dnex.Message);
                            return;
                        }

                        spinner.Text = "Preparing files for upload.";
                        //zip publish folder
                        var zipFile = ZipContents(appProfile.profile);

                        spinner.Text  = "Uploading application.";
                        var published = await UploadFiles(webUri, zipFile, authToken);
                        if (published)
                        {
                            spinner.Text = $"App {appProfile.profile.PublishName} published.";

                            appProfile.profile.LastPublish = DateTime.Now;
                            SaveAppProfile(appProfile.profile);
                        }
                        else
                        {
                            throw new Exception("Could not deploy files, please try again.");
                        }
                    }
                    catch (Exception ex)
                    {
                        spinner.Fail($"Error creating web app {appProfile.profile.PublishName} - " + ex.Message);
                        throw ex; // throwing so caller can handle
                    }
                    spinner.Succeed($"Browse to https://{appProfile.profile.PublishName}.azurewebsites.net");
                });
            }
コード例 #2
0
 public static void BrowseSite(string resourceGroup, string appName)
 {
     ShellHelper.Bash($"az webapp browse -n {appName} -g {resourceGroup}");
 }
コード例 #3
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);
        }
コード例 #4
0
        public static bool IsLoggedIn()
        {
            var result = ShellHelper.Bash("az account list -o table");

            return(result.Contains("az login"));
        }
コード例 #5
0
        public static bool Login()
        {
            var result = ShellHelper.Bash("az login");

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

            File.WriteAllText(fileName, result);
        }