diff --git a/cli/azd/pkg/azsdk/zip_deploy_client.go b/cli/azd/pkg/azsdk/zip_deploy_client.go index 6a96e191954..9d8790c3bd5 100644 --- a/cli/azd/pkg/azsdk/zip_deploy_client.go +++ b/cli/azd/pkg/azsdk/zip_deploy_client.go @@ -13,7 +13,6 @@ import ( armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" "github.com/azure/azure-dev/cli/azd/pkg/httputil" ) @@ -28,7 +27,6 @@ const ( type ZipDeployClient struct { hostName string pipeline runtime.Pipeline - cred azcore.TokenCredential } type DeployResponse struct { @@ -81,7 +79,6 @@ func NewZipDeployClient( return &ZipDeployClient{ hostName: hostName, pipeline: pipeline, - cred: credential, }, nil } @@ -116,77 +113,8 @@ func (c *ZipDeployClient) BeginDeploy( return runtime.NewPoller(response, c.pipeline, pollerOptions) } -// Deploys the specified application zip to the azure app service using deployment status api and waits for completion -func (c *ZipDeployClient) BeginDeployTrackStatus( - ctx context.Context, - zipFile io.Reader, - subscriptionId, - resourceGroup, - appName string, -) (*runtime.Poller[armappservice.WebAppsClientGetProductionSiteDeploymentStatusResponse], error) { - request, err := c.createDeployRequest(ctx, zipFile) - if err != nil { - return nil, err - } - - response, err := c.pipeline.Do(request) - if err != nil { - return nil, err - } - - defer response.Body.Close() - - if !runtime.HasStatusCode(response, http.StatusAccepted) { - return nil, runtime.NewResponseError(response) - } - - client, err := armappservice.NewWebAppsClient(subscriptionId, c.cred, nil) - if err != nil { - return nil, fmt.Errorf("creating web app client: %w", err) - } - - deploymentStatusId := response.Header.Get("Scm-Deployment-Id") - if deploymentStatusId == "" { - return nil, fmt.Errorf("empty deployment status id") - } - - // nolint:lll - // Example definition: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/web/resource-manager/Microsoft.Web/stable/2022-03-01/examples/GetSiteDeploymentStatus.json - poller, err := client.BeginGetProductionSiteDeploymentStatus(ctx, resourceGroup, appName, deploymentStatusId, nil) - if err != nil { - return nil, fmt.Errorf("getting deployment status: %w", err) - } - - return poller, nil -} - -func (c *ZipDeployClient) DeployTrackStatus( - ctx context.Context, - zipFile io.Reader, - subscriptionId string, - resourceGroup string, - appName string) (armappservice.WebAppsClientGetProductionSiteDeploymentStatusResponse, error) { - var response armappservice.WebAppsClientGetProductionSiteDeploymentStatusResponse - - poller, err := c.BeginDeployTrackStatus(ctx, zipFile, subscriptionId, resourceGroup, appName) - if err != nil { - return response, err - } - - response, err = poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{ - Frequency: deployStatusInterval, - }) - if err != nil { - return response, err - } - - return response, nil -} - // Deploys the specified application zip to the azure app service and waits for completion -func (c *ZipDeployClient) Deploy( - ctx context.Context, - zipFile io.Reader) (*DeployResponse, error) { +func (c *ZipDeployClient) Deploy(ctx context.Context, zipFile io.Reader) (*DeployResponse, error) { poller, err := c.BeginDeploy(ctx, zipFile) if err != nil { return nil, err diff --git a/cli/azd/pkg/project/service_target_appservice.go b/cli/azd/pkg/project/service_target_appservice.go index 2d624e65f70..2af715e18d8 100644 --- a/cli/azd/pkg/project/service_target_appservice.go +++ b/cli/azd/pkg/project/service_target_appservice.go @@ -27,6 +27,7 @@ func NewAppServiceTarget( env *environment.Environment, azCli azcli.AzCli, ) ServiceTarget { + return &appServiceTarget{ env: env, cli: azCli, @@ -79,7 +80,7 @@ func (st *appServiceTarget) Deploy( ) *async.TaskWithProgress[*ServiceDeployResult, ServiceProgress] { return async.RunTaskWithProgress( func(task *async.TaskContextWithProgress[*ServiceDeployResult, ServiceProgress]) { - if err := st.validateTargetResource(targetResource); err != nil { + if err := st.validateTargetResource(ctx, serviceConfig, targetResource); err != nil { task.SetError(fmt.Errorf("validating target resource: %w", err)) return } @@ -155,6 +156,8 @@ func (st *appServiceTarget) Endpoints( } func (st *appServiceTarget) validateTargetResource( + ctx context.Context, + serviceConfig *ServiceConfig, targetResource *environment.TargetResource, ) error { if !strings.EqualFold(targetResource.ResourceType(), string(infra.AzureResourceTypeWebSite)) { diff --git a/cli/azd/pkg/project/service_target_appservice_test.go b/cli/azd/pkg/project/service_target_appservice_test.go index 1dcb4fdfe4b..f7bcc88ab81 100644 --- a/cli/azd/pkg/project/service_target_appservice_test.go +++ b/cli/azd/pkg/project/service_target_appservice_test.go @@ -4,11 +4,13 @@ package project import ( + "context" "strings" "testing" "github.com/azure/azure-dev/cli/azd/pkg/environment" "github.com/azure/azure-dev/cli/azd/pkg/infra" + "github.com/azure/azure-dev/cli/azd/test/mocks" "github.com/stretchr/testify/require" ) @@ -42,9 +44,11 @@ func TestNewAppServiceTargetTypeValidation(t *testing.T) { for test, data := range tests { t.Run(test, func(t *testing.T) { + mockContext := mocks.NewMockContext(context.Background()) serviceTarget := &appServiceTarget{} + serviceConfig := &ServiceConfig{} - err := serviceTarget.validateTargetResource(data.targetResource) + err := serviceTarget.validateTargetResource(*mockContext.Context, serviceConfig, data.targetResource) if data.expectError { require.Error(t, err) } else { diff --git a/cli/azd/pkg/tools/azcli/azcli_functions_test.go b/cli/azd/pkg/tools/azcli/azcli_functions_test.go index 401155d45c1..9cdadbf2974 100644 --- a/cli/azd/pkg/tools/azcli/azcli_functions_test.go +++ b/cli/azd/pkg/tools/azcli/azcli_functions_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice" "github.com/azure/azure-dev/cli/azd/pkg/azsdk" "github.com/azure/azure-dev/cli/azd/pkg/convert" "github.com/azure/azure-dev/cli/azd/test/mocks" diff --git a/cli/azd/pkg/tools/azcli/azcli_staticwebapp_test.go b/cli/azd/pkg/tools/azcli/azcli_staticwebapp_test.go index ea73f33e865..d5d46ffa522 100644 --- a/cli/azd/pkg/tools/azcli/azcli_staticwebapp_test.go +++ b/cli/azd/pkg/tools/azcli/azcli_staticwebapp_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice" "github.com/azure/azure-dev/cli/azd/pkg/convert" "github.com/azure/azure-dev/cli/azd/test/mocks" "github.com/stretchr/testify/require" diff --git a/cli/azd/pkg/tools/azcli/function_app.go b/cli/azd/pkg/tools/azcli/function_app.go index f0074d1a6bb..ea2068ef635 100644 --- a/cli/azd/pkg/tools/azcli/function_app.go +++ b/cli/azd/pkg/tools/azcli/function_app.go @@ -34,12 +34,7 @@ func (cli *azCli) DeployFunctionAppUsingZipFile( appName string, deployZipFile io.Reader, ) (*string, error) { - app, err := cli.appService(ctx, subscriptionId, resourceGroup, appName) - if err != nil { - return nil, err - } - - hostName, err := appServiceRepositoryHost(app, appName) + hostName, err := cli.appServiceRepositoryHost(ctx, subscriptionId, resourceGroup, appName) if err != nil { return nil, err } diff --git a/cli/azd/pkg/tools/azcli/static_webapp.go b/cli/azd/pkg/tools/azcli/static_webapp.go index e51d4bb91d3..d10db473599 100644 --- a/cli/azd/pkg/tools/azcli/static_webapp.go +++ b/cli/azd/pkg/tools/azcli/static_webapp.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice" ) type AzCliStaticWebAppProperties struct { diff --git a/cli/azd/pkg/tools/azcli/webapp.go b/cli/azd/pkg/tools/azcli/webapp.go index 3f7dbcaa43b..edc2df79388 100644 --- a/cli/azd/pkg/tools/azcli/webapp.go +++ b/cli/azd/pkg/tools/azcli/webapp.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice" "github.com/azure/azure-dev/cli/azd/pkg/azsdk" "github.com/azure/azure-dev/cli/azd/pkg/convert" ) @@ -49,20 +49,19 @@ func (cli *azCli) appService( return &webApp, nil } -func isLinuxWebApp(response *armappservice.WebAppsClientGetResponse) bool { - if response.Properties != nil && response.Properties.SiteConfig != nil && - response.Properties.SiteConfig.LinuxFxVersion != nil { - return true - } - return false -} - -func appServiceRepositoryHost( - response *armappservice.WebAppsClientGetResponse, +func (cli *azCli) appServiceRepositoryHost( + ctx context.Context, + subscriptionId string, + resourceGroup string, appName string, ) (string, error) { + app, err := cli.appService(ctx, subscriptionId, resourceGroup, appName) + if err != nil { + return "", err + } + hostName := "" - for _, item := range response.Properties.HostNameSSLStates { + for _, item := range app.Properties.HostNameSSLStates { if *item.HostType == armappservice.HostTypeRepository { hostName = *item.Name break @@ -76,56 +75,6 @@ func appServiceRepositoryHost( return hostName, nil } -func checkWebAppDeploymentStatus( - res armappservice.WebAppsClientGetProductionSiteDeploymentStatusResponse, -) (string, error) { - properties := res.CsmDeploymentStatus.Properties - inProgressNumber := int(*properties.NumberOfInstancesInProgress) - successNumber := int(*properties.NumberOfInstancesSuccessful) - failNumber := int(*properties.NumberOfInstancesFailed) - failLogs := properties.FailedInstancesLogs - errorString := "" - logErrorFunction := func(properties *armappservice.CsmDeploymentStatusProperties, message string) { - for _, err := range properties.Errors { - if err.Message != nil { - errorString += fmt.Sprintf("Error: %s\n", *err.Message) - } - } - - for _, log := range failLogs { - errorString += fmt.Sprintf("Please check the %slogs for more info: %s\n", message, *log) - } - } - - switch *properties.Status { - case armappservice.DeploymentBuildStatusRuntimeSuccessful: - return "", nil - case armappservice.DeploymentBuildStatusRuntimeFailed: - totalNumber := inProgressNumber + successNumber + failNumber - - if successNumber > 0 { - errorString += fmt.Sprintf("Site started with errors: %d/%d instances failed to start successfully\n", - failNumber, totalNumber) - } else if totalNumber > 0 { - errorString += fmt.Sprintf("Deployment failed because the runtime process failed. In progress instances: %d, "+ - "Successful instances: %d, Failed Instances: %d\n", - inProgressNumber, successNumber, failNumber) - } - - logErrorFunction(properties, "runtime ") - return "", fmt.Errorf(errorString) - case armappservice.DeploymentBuildStatusBuildFailed: - errorString += "Deployment failed because the build process failed\n" - logErrorFunction(properties, "build ") - return "", fmt.Errorf(errorString) - // Default case for the rest statuses, they shouldn't appear as a final response - default: - errorString += fmt.Sprintf("Deployment failed with status: %s\n", *properties.Status) - logErrorFunction(properties, "") - return "", fmt.Errorf(errorString) - } -} - func (cli *azCli) DeployAppServiceZip( ctx context.Context, subscriptionId string, @@ -133,12 +82,7 @@ func (cli *azCli) DeployAppServiceZip( appName string, deployZipFile io.Reader, ) (*string, error) { - app, err := cli.appService(ctx, subscriptionId, resourceGroup, appName) - if err != nil { - return nil, err - } - - hostName, err := appServiceRepositoryHost(app, appName) + hostName, err := cli.appServiceRepositoryHost(ctx, subscriptionId, resourceGroup, appName) if err != nil { return nil, err } @@ -148,21 +92,6 @@ func (cli *azCli) DeployAppServiceZip( return nil, err } - // Deployment Status API only support linux web app for now - if isLinuxWebApp(app) { - response, err := client.DeployTrackStatus(ctx, deployZipFile, subscriptionId, resourceGroup, appName) - if err != nil { - return nil, err - } - - res, err := checkWebAppDeploymentStatus(response) - if err != nil { - return nil, err - } - - return &res, nil - } - response, err := client.Deploy(ctx, deployZipFile) if err != nil { return nil, err diff --git a/go.mod b/go.mod index 19e710be25f..b4349c95b83 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration v1.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3 v3.0.0-beta.1 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appplatform/armappplatform/v2 v2.0.0-beta.1 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice v1.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization v1.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.1.1 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices v1.4.1 @@ -71,7 +72,6 @@ require ( require ( github.com/Azure/azure-pipeline-go v0.2.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2 v2.3.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 730b1e28250..1f18b69d969 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontai github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3 v3.0.0-beta.1/go.mod h1:Ro3jxA16UFXEpIhlUdrX12kSrOceSrV8rMcmnc0FYI8= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appplatform/armappplatform/v2 v2.0.0-beta.1 h1:/0cm1GshkYOYpA9t6W3dU1uGNwBiaTNeGMX4HMD9LBU= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appplatform/armappplatform/v2 v2.0.0-beta.1/go.mod h1:cKYj1VwtPpdhRZDp3eiOIYgx4Q4LiQZvA21I1IiQgpI= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2 v2.3.0 h1:JI8PcWOImyvIUEZ0Bbmfe05FOlWkMi2KhjG+cAKaUms= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2 v2.3.0/go.mod h1:nJLFPGJkyKfDDyJiPuHIXsCi/gpJkm07EvRgiX7SGlI= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice v1.0.0 h1:kRX8I0dWAcpW6Vq0m90CgV+qw4O1vXodgwrhoPr1RWs= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice v1.0.0/go.mod h1:avvc5/7qR4taCvAhOM7KFXuEHhAU0Wek9YX7sh9H3EM= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization v1.0.0 h1:qtRcg5Y7jNJ4jEzPq4GpWLfTspHdNe2ZK6LjwGcjgmU= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization v1.0.0/go.mod h1:lPneRe3TwsoDRKY4O6YDLXHhEWrD+TIRa8XrV/3/fqw= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.1.1 h1:6A4M8smF+y8nM/DYsLNQz9n7n2ZGaEVqfz8ZWQirQkI=