Load runtimes from remote before parse runtime config

This commit is contained in:
Flanker-MSFT 2023-12-22 14:54:07 +08:00
Родитель 9b99b87d58
Коммит 8f57138e9f
2 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -14,8 +14,10 @@ import com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig;
import com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig;
import com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig;
import com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity;
import com.microsoft.azure.toolkit.lib.appservice.function.AzureFunctions;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionsServiceSubscription;
import com.microsoft.azure.toolkit.lib.appservice.function.core.AzureFunctionsAnnotationConstants;
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
import com.microsoft.azure.toolkit.lib.appservice.model.*;
@ -125,6 +127,9 @@ public class DeployHandler {
if (config == null) {
return null;
}
final FunctionsServiceSubscription serviceSubscription = (FunctionsServiceSubscription) Azure.az(AzureFunctions.class)
.forSubscription(ctx.getOrCreateAzureAppServiceClient().getSubscriptionId());
serviceSubscription.loadRuntimes();
final OperatingSystem os = Optional.ofNullable(config.os()).map(OperatingSystem::fromString)
.orElseGet(() -> Optional.ofNullable(getFunctionApp()).map(FunctionApp::getAppServicePlan).map(AppServicePlan::getOperatingSystem).orElse(OperatingSystem.WINDOWS));
final String javaVersion = getJavaVersion();

Просмотреть файл

@ -23,6 +23,7 @@ import com.microsoft.azure.toolkit.lib.appservice.utils.Utils;
import com.microsoft.azure.toolkit.lib.appservice.webapp.AzureWebApp;
import com.microsoft.azure.toolkit.lib.appservice.webapp.WebApp;
import com.microsoft.azure.toolkit.lib.appservice.webapp.WebAppBase;
import com.microsoft.azure.toolkit.lib.appservice.webapp.WebAppServiceSubscription;
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
@ -41,7 +42,7 @@ import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.TaskAction;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import java.io.File;
import java.util.Collections;
import java.util.List;
@ -74,6 +75,7 @@ public class DeployTask extends DefaultTask {
normalizeConfigValue(config);
validate(config);
config.subscriptionId(GradleAuthHelper.login(azureWebappExtension.getAuth(), config.subscriptionId()));
azureWebappExtension.setSubscription(config.subscriptionId());
validateOnline(config);
final WebAppBase<?, ?, ?> target = createOrUpdateWebapp(config);
deployArtifact(target, config);
@ -153,19 +155,23 @@ public class DeployTask extends DefaultTask {
.deploymentSlotConfigurationSource(config.deploymentSlotConfigurationSource())
.pricingTier(Optional.ofNullable(config.pricingTier()).map(PricingTier::fromString).orElse(null))
.region(Optional.ofNullable(config.region()).map(Region::fromName).orElse(null))
.runtime(convert(config.runtime()))
.runtime(getRuntimeConfig(config))
.servicePlanName(config.servicePlanName())
.appSettings(config.appSettings());
}
private RuntimeConfig convert(@Nullable GradleRuntimeConfig config) {
private RuntimeConfig getRuntimeConfig(@Nonnull GradleWebAppConfig webAppConfig) {
final GradleRuntimeConfig config = webAppConfig.runtime();
if (Objects.isNull(config)) {
return null;
}
final WebAppServiceSubscription serviceSubscription = (WebAppServiceSubscription) Azure.az(AzureWebApp.class).forSubscription(webAppConfig.subscriptionId());
final OperatingSystem os = Optional.ofNullable(config.os()).map(OperatingSystem::fromString)
.orElseGet(() -> Optional.ofNullable(getWebApp()).map(WebApp::getAppServicePlan).map(AppServicePlan::getOperatingSystem).orElse(OperatingSystem.LINUX));
.orElseGet(() -> Optional.ofNullable(serviceSubscription.webApps().get(webAppConfig.appName(), webAppConfig.resourceGroup()))
.map(WebApp::getAppServicePlan).map(AppServicePlan::getOperatingSystem).orElse(OperatingSystem.LINUX));
final String javaVersion = config.javaVersion();
final String webContainer = config.webContainer();
serviceSubscription.loadRuntimes();
final Runtime runtime = os == OperatingSystem.DOCKER ? FunctionAppRuntime.DOCKER : os == OperatingSystem.WINDOWS ?
WebAppWindowsRuntime.fromContainerAndJavaVersionUserText(webContainer, javaVersion) :
WebAppLinuxRuntime.fromContainerAndJavaVersionUserText(webContainer, javaVersion);
@ -178,11 +184,6 @@ public class DeployTask extends DefaultTask {
.startUpCommand(config.startUpCommand());
}
private WebApp getWebApp() {
return Azure.az(AzureWebApp.class).webApps(azureWebappExtension.getSubscription())
.get(azureWebappExtension.getAppName(), azureWebappExtension.getResourceGroup());
}
private GradleWebAppConfig parseConfiguration() {
final AzureWebappPluginExtension ctx = this.azureWebappExtension;
GradleWebAppConfig config = new GradleWebAppConfig();