Skip to content

Commit

Permalink
Revert "add deployment status tracking for linux web apps (#3763)" (#…
Browse files Browse the repository at this point in the history
…3915)

This reverts commit d9bd37a.
  • Loading branch information
vhvb1989 authored May 15, 2024
1 parent 35db19c commit 13a7dd5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 170 deletions.
74 changes: 1 addition & 73 deletions cli/azd/pkg/azsdk/zip_deploy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -28,7 +27,6 @@ const (
type ZipDeployClient struct {
hostName string
pipeline runtime.Pipeline
cred azcore.TokenCredential
}

type DeployResponse struct {
Expand Down Expand Up @@ -81,7 +79,6 @@ func NewZipDeployClient(
return &ZipDeployClient{
hostName: hostName,
pipeline: pipeline,
cred: credential,
}, nil
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cli/azd/pkg/project/service_target_appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewAppServiceTarget(
env *environment.Environment,
azCli azcli.AzCli,
) ServiceTarget {

return &appServiceTarget{
env: env,
cli: azCli,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 5 additions & 1 deletion cli/azd/pkg/project/service_target_appservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/tools/azcli/azcli_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/tools/azcli/azcli_staticwebapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 1 addition & 6 deletions cli/azd/pkg/tools/azcli/function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/tools/azcli/static_webapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
95 changes: 12 additions & 83 deletions cli/azd/pkg/tools/azcli/webapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -76,69 +75,14 @@ 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,
resourceGroup string,
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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 13a7dd5

Please sign in to comment.