Skip to content
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

feat: add prune flag #1022

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ changelog:
sort: asc
filters:
exclude:
- "^test:"
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
Expand Down
1 change: 1 addition & 0 deletions messages/deploy/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
EdgeApplicationDeploySync = "Synchronizes the local azion.json file with remote resources"
EdgeApplicationDeployLocal = "Runs the entire build and deploy process locally"
EdgeApplicationDeployDryrun = "Simulates the deploy process without carrying out any actual action"
EdgeApplicationDeployPrune = "If passed, resources no longer found in the manifest.json file will not be deleted"
EnvFlag = "Relative path to where your custom .env file is stored"
OriginsSuccessful = "Created Origin for Edge Application\n"
OriginsUpdateSuccessful = "Updated Origin for Edge Application %v with ID %v \n"
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
ProjectConf string
Sync bool
DryRun bool
Prune bool
Local bool
Env string
Logs = contracts.Logs{}
Expand Down Expand Up @@ -122,6 +123,7 @@ func NewCobraCmd(deploy *DeployCmd) *cobra.Command {
deployCmd.Flags().BoolVar(&Sync, "sync", false, msg.EdgeApplicationDeploySync)
deployCmd.Flags().BoolVar(&Local, "local", false, msg.EdgeApplicationDeployLocal)
deployCmd.Flags().BoolVar(&DryRun, "dry-run", false, msg.EdgeApplicationDeployDryrun)
deployCmd.Flags().BoolVar(&Prune, "prune", false, msg.EdgeApplicationDeployPrune)
deployCmd.Flags().StringVar(&Env, "env", ".edge/.env", msg.EnvFlag)
return deployCmd
}
Expand Down Expand Up @@ -150,7 +152,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error {

if Local {
deployLocal := deploy.NewDeployCmd(f)
return deployLocal.ExternalRun(f, ProjectConf, Env, Sync, Auto, SkipBuild)
return deployLocal.ExternalRun(f, ProjectConf, Env, Sync, Auto, SkipBuild, Prune)
}

msgs := []string{}
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/deploy_remote/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
SkipBuild bool
ProjectConf string
Sync bool
Prune bool
Env string
)

Expand Down Expand Up @@ -97,11 +98,12 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
return NewCobraCmd(NewDeployCmd(f))
}

func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string, env string, shouldSync, auto, skipBuild bool) error {
func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string, env string, shouldSync, auto, skipBuild, prune bool) error {
ProjectConf = configPath
Sync = shouldSync
Env = env
Auto = auto
Prune = prune
SkipBuild = skipBuild
return cmd.Run(f)
}
Expand Down Expand Up @@ -229,7 +231,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error {
}
}

err = interpreter.CreateResources(conf, manifestStructure, f, ProjectConf, &msgs)
err = interpreter.CreateResources(conf, manifestStructure, f, ProjectConf, Prune, &msgs)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (man *ManifestInterpreter) CreateResources(
manifest *contracts.Manifest,
f *cmdutil.Factory,
projectConf string,
prune bool,
msgs *[]string) error {

logger.FInfoFlags(f.IOStreams.Out, msg.CreatingManifest, f.Format, f.Out)
Expand Down Expand Up @@ -335,9 +336,11 @@ func (man *ManifestInterpreter) CreateResources(
}
}

err = deleteResources(ctx, f, conf, msgs)
if err != nil {
return err
if !prune {
err = deleteResources(ctx, f, conf, msgs)
if err != nil {
return err
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestDeployCmd(t *testing.T) {
pathManifest := "fixtures/manifest.json"
manifest, err := interpreter.ReadManifest(pathManifest, f, &msgs)
require.NoError(t, err)
err = interpreter.CreateResources(options, manifest, f, "azion", &msgs)
err = interpreter.CreateResources(options, manifest, f, "azion", true, &msgs)
require.NoError(t, err)
})

Expand Down
Loading