Skip to content

Fix: Remove package cleanup to prevent deletion of user-provided packages #5445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 12, 2025
12 changes: 11 additions & 1 deletion cli/azd/internal/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"strings"
"time"

"github.com/azure/azure-dev/cli/azd/cmd/actions"
Expand Down Expand Up @@ -254,7 +257,7 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
PackagePath: da.flags.fromPackage,
}
} else {
// --from-package not set, package the application
// --from-package not set, automatically package the application
packageResult, err = async.RunWithProgress(
func(packageProgress project.ServiceProgress) {
progressMessage := fmt.Sprintf("Deploying service %s (%s)", svc.Name, packageProgress.Message)
Expand Down Expand Up @@ -282,6 +285,13 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
},
)

// clean up for packages automatically created in temp dir
if da.flags.fromPackage == "" && strings.HasPrefix(packageResult.PackagePath, os.TempDir()) {
if err := os.RemoveAll(packageResult.PackagePath); err != nil {
log.Printf("failed to remove temporary package: %s : %s", packageResult.PackagePath, err)
}
}

da.console.StopSpinner(ctx, stepMessage, input.GetStepResultFormat(err))
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion cli/azd/pkg/project/service_target_appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (st *appServiceTarget) Deploy(
return nil, fmt.Errorf("failed reading deployment zip file: %w", err)
}

defer os.Remove(packageOutput.PackagePath)
defer zipFile.Close()

progress.SetProgress(NewServiceProgress("Uploading deployment package"))
Expand Down
1 change: 0 additions & 1 deletion cli/azd/pkg/project/service_target_functionapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (f *functionAppTarget) Deploy(
return nil, fmt.Errorf("failed reading deployment zip file: %w", err)
}

defer os.Remove(packageOutput.PackagePath)
defer zipFile.Close()

progress.SetProgress(NewServiceProgress("Uploading deployment package"))
Expand Down
Loading