/// <summary> /// Deploy lightweight reverse proxy to App Service. /// </summary> /// <param name="resourceGroup"></param> /// <param name="webSite"></param> /// <param name="tags"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <SiteSourceControlInner> DeployProxyAsync( IResourceGroup resourceGroup, SiteInner webSite, IDictionary <string, string> tags = null, CancellationToken cancellationToken = default ) { try { tags ??= new Dictionary <string, string>(); Log.Information($"Deploying proxy service to AppService: {webSite.Name} ..."); var siteSourceControlDefinition = new SiteSourceControlInner() { Location = resourceGroup.RegionName, Tags = tags, RepoUrl = PROXY_REPO_URL, Branch = PROXY_BRANCH, IsManualIntegration = true }; siteSourceControlDefinition.Validate(); var siteSourceControl = await _webSiteManagementClient .WebApps .CreateOrUpdateSourceControlAsync( resourceGroup.Name, webSite.Name, siteSourceControlDefinition, cancellationToken ); Log.Information($"Deployed proxy service to AppService: {webSite.Name}"); return(siteSourceControl); } catch (Exception ex) { Log.Error(ex, $"Failed deploy proxy service to AppService: {webSite.Name}"); throw; } }
public async Task <SiteInner> CreateSiteAsync( IResourceGroup resourceGroup, AppServicePlanInner appServicePlan, string azureWebsiteName, string remoteEndpoint, X509Certificate2 webAppX509Certificate, IDictionary <string, string> tags = null, CancellationToken cancellationToken = default ) { try { tags = tags ?? new Dictionary <string, string>(); Log.Information($"Creating Azure AppService: {azureWebsiteName} ..."); var webSiteParameters = new SiteInner { Location = resourceGroup.RegionName, Tags = tags, Enabled = true, HttpsOnly = true, // Will redirect HTTP traffic to HTTPS. ClientAffinityEnabled = false, ServerFarmId = appServicePlan.Id, SiteConfig = new SiteConfig { AppSettings = new List <NameValuePair> { new NameValuePair { Name = PROXY_ENV_REMOTE_ENDPOINT, // NOTE: This should be PublicIP address exposed by Ingress. Value = remoteEndpoint }, new NameValuePair { Name = PROXY_ENV_REMOTE_ENDPOINT_SSL_THUMBPRINT, // NOTE: this certificate should be added to Ingress as default certificate. Value = webAppX509Certificate.Thumbprint } }, // Coming from Microsoft.Web/sites/config resource NumberOfWorkers = 1, RequestTracingEnabled = true, HttpLoggingEnabled = true, DetailedErrorLoggingEnabled = true, AlwaysOn = true, MinTlsVersion = SupportedTlsVersions.OneFullStopTwo } }; webSiteParameters.Validate(); var webSite = await _webSiteManagementClient .WebApps .CreateOrUpdateAsync( resourceGroup.Name, azureWebsiteName, webSiteParameters, cancellationToken ); var siteSourceControlRequest = new SiteSourceControlInner() { Location = resourceGroup.RegionName, Tags = tags, RepoUrl = PROXY_REPO_URL, Branch = PROXY_BRANCH, IsManualIntegration = true }; siteSourceControlRequest.Validate(); var siteSourceControl = await _webSiteManagementClient .WebApps .CreateOrUpdateSourceControlAsync( resourceGroup.Name, azureWebsiteName, siteSourceControlRequest, cancellationToken ); webSite = await _webSiteManagementClient .WebApps .GetAsync( resourceGroup.Name, azureWebsiteName, cancellationToken ); Log.Information($"Created Azure AppService: {azureWebsiteName}"); return(webSite); } catch (Exception ex) { Log.Error(ex, $"Failed to create Azure AppService: {azureWebsiteName}"); throw; } }