private bool IsZipDeployment(out bool isScmRunFromPackage) { // Check app settings for run from package. bool runFromPkgConfigured = Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteZipDeployment)) || Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteAltZipDeployment)) || Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteRunFromPackage)); if (!_environment.IsLinuxConsumption()) { isScmRunFromPackage = false; // This check is strong enough for SKUs other than Linux Consumption. return(runFromPkgConfigured); } // The following logic only applies to Linux Consumption, since currently SCM_RUN_FROM_PACKAGE is always set even if we are not using it. if (runFromPkgConfigured) { isScmRunFromPackage = false; return(true); } // If SCM_RUN_FROM_PACKAGE is set to a valid value and the blob exists, it's a zip deployment. var url = _environment.GetEnvironmentVariable(ScmRunFromPackage); if (string.IsNullOrEmpty(url)) { LinuxContainerEventGenerator.LogEvent(message: $"{nameof(ScmRunFromPackage)} is empty.", source: nameof(ScriptApplicationHostOptionsSetup)); isScmRunFromPackage = false; return(false); } if (Utility.TryCleanUrl(url, out string cleanedUrl)) { LinuxContainerEventGenerator.LogEvent(message: $"{nameof(ScmRunFromPackage)} = {cleanedUrl}", source: nameof(ScriptApplicationHostOptionsSetup)); } var isValidZipSetting = Utility.IsValidZipSetting(url); LinuxContainerEventGenerator.LogEvent(message: $"{nameof(ScmRunFromPackage)} isValidZipSetting = {isValidZipSetting}", source: nameof(ScriptApplicationHostOptionsSetup)); if (!isValidZipSetting) { isScmRunFromPackage = false; // Return early so we don't call storage if it isn't absolutely necessary. return(false); } var blobExists = BlobExists(url); LinuxContainerEventGenerator.LogEvent(message: $"{nameof(ScmRunFromPackage)} blobExists = {blobExists}", source: nameof(ScriptApplicationHostOptionsSetup)); bool scmRunFromPkgConfigured = isValidZipSetting && blobExists; isScmRunFromPackage = scmRunFromPkgConfigured; return(scmRunFromPkgConfigured); }
public virtual bool BlobExists(string url) { if (string.IsNullOrEmpty(url)) { return(false); } try { BlobClient blobClient = new BlobClient(new Uri(url)); int attempt = 0; while (true) { try { return(blobClient.Exists()); } catch (Exception ex) when(!ex.IsFatal()) { LinuxContainerEventGenerator.LogEvent(message: $"Exception when checking if {nameof(ScmRunFromPackage)} blob exists", e: ex, logLevel: LogLevel.Error, source: nameof(ScriptApplicationHostOptionsSetup)); if (++attempt > 2) { return(false); } Thread.Sleep(TimeSpan.FromSeconds(0.3)); } } } catch (Exception ex) { LinuxContainerEventGenerator.LogEvent(message: $"Failed to check status of {nameof(ScmRunFromPackage)}", e: ex, logLevel: LogLevel.Error, source: nameof(ScriptApplicationHostOptionsSetup)); return(false); } }