Ejemplo n.º 1
0
        public AppyPlayAzureConfigurationBuilder WithFunctionApp(string functionAppName, Region functionRegion, string extensionRunTime, string workerRunTime = null)
        {
            var rgName             = _infraParameters.ResourceGroupParameters.ResourceGroupName;
            var storageAccountName = _infraParameters.StorageAccountParameters.AccountName;
            var parameters         = new AppyFunctionAppParameters
            {
                AppName            = functionAppName,
                ResourceGroupName  = rgName,
                StorageAccountName = storageAccountName,
                AppRegion          = functionRegion,
                ExtensionsRunTime  = extensionRunTime,
                WorkerRunTime      = workerRunTime
            };

            _infraParameters.FunctionsApps.Add(parameters);

            return(this);
        }
Ejemplo n.º 2
0
 static bool hasChangedFunctionWorkerRunTime(AppyFunctionAppParameters parameters, IReadOnlyDictionary <string, Microsoft.Azure.Management.AppService.Fluent.IAppSetting> appSettings) =>
 (!appSettings.TryGetValue("FUNCTIONS_WORKER_RUNTIME", out var workerRunTimeSetting) && !string.IsNullOrEmpty(parameters.WorkerRunTime)) ||
Ejemplo n.º 3
0
        public static async Task CreateFunctionAppResources(this IAzure azure, ILogger logger, AppyFunctionAppParameters parameters)
        {
            logger.Info($"Creating Azure Function App with name {parameters.AppName} in group {parameters.ResourceGroupName}");
            var functionApps = await azure.AppServices.FunctionApps.ListByResourceGroupAsync(parameters.ResourceGroupName);

            var storageAccount = await azure.StorageAccounts.GetByResourceGroupAsync(parameters.ResourceGroupName, parameters.StorageAccountName);

            var functionResource = functionApps.SingleOrDefault(functionApp => functionApp.Name == parameters.AppName);

            if (!ReferenceEquals(functionResource, null))
            {
                logger.Info($"Azure Function App with name {parameters.AppName} already exists in group {parameters.ResourceGroupName}");

                logger.Info($"Looking changes in Function App {parameters.AppName} parameters in group {parameters.ResourceGroupName}");
                var updateProcess = functionResource
                                    .Update()
                                    .WithExistingStorageAccount(storageAccount);

                var appSettings = await functionResource.GetAppSettingsAsync();

                var hasChanges = false;

                // update worker runtime (dotnet, node, etc)
                if (hasChangedFunctionWorkerRunTime(parameters, appSettings))
                {
                    updateProcess.WithAppSetting("FUNCTIONS_WORKER_RUNTIME", parameters.WorkerRunTime);
                    hasChanges = true;
                }

                if (!hasChanges)
                {
                    logger.Info($"There are not changes in Function App {parameters.AppName} parameters in group {parameters.ResourceGroupName}");
                    return;
                }

                logger.Info($"Applying changes in Function App {parameters.AppName} parameters in group {parameters.ResourceGroupName}");
                await updateProcess
                .ApplyAsync();

                logger.Info($"Applied changes in Function App {parameters.AppName} parameters in group {parameters.ResourceGroupName}");

                return;
            }

            var createProcess = azure.AppServices.FunctionApps
                                .Define(parameters.AppName)
                                .WithRegion(parameters.AppRegion)
                                .WithExistingResourceGroup(parameters.ResourceGroupName)
                                .WithNewConsumptionPlan()
                                .WithExistingStorageAccount(storageAccount)
                                .WithRuntimeVersion(parameters.ExtensionsRunTime);

            if (!string.IsNullOrEmpty(parameters.WorkerRunTime))
            {
                createProcess = (IWithCreate)createProcess.WithAppSetting("FUNCTIONS_WORKER_RUNTIME", parameters.WorkerRunTime);
            }
            await createProcess
            .CreateAsync();

            logger.Info($"Created Azure Function App with name {parameters.AppName} in group {parameters.ResourceGroupName}");
        }