Repository navigation
Add bundle auto-deploy delete
#7942
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
Open
atreyadbrx
wants to merge
1
commit into
dabs-ad-d4-pr4-get-list
Choose a base branch
from
dabs-ad-d4-pr5-delete
base: dabs-ad-d4-pr4-get-list
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+262
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| bundle: | ||
| name: auto-deploy | ||
|
|
||
| targets: | ||
| dev: | ||
| default: true | ||
| prod: | ||
| git: | ||
| branch: main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Cloud = false | ||
| EnvMatrix.DMS = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
|
|
||
| === Without a terminal, delete needs --auto-approve | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy delete | ||
| Error: this deletes the auto-deploy trigger of target dev. To proceed, use --auto-approve | ||
|
|
||
| === Deleting the target's trigger leaves the other target's | ||
|
|
||
| >>> [CLI] bundle auto-deploy delete --auto-approve | ||
| Deleted the auto-deploy trigger of target dev. | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/git-webhooks/trigger", | ||
| "body": { | ||
| "repo_url": "https://github.com/acme/repo", | ||
| "git_provider": "GITHUB", | ||
| "trigger_config": { | ||
| "push_event": { | ||
| "branch": "main" | ||
| }, | ||
| "dabs_deploy": { | ||
| "bundle_yml_repo_path": "databricks.yml", | ||
| "deployment_mode": "dev" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| >>> [CLI] bundle auto-deploy list | ||
| Target Branch Deploy as Trigger ID | ||
| prod main its creator [UUID] | ||
|
|
||
| === A retried delete sends its body again | ||
|
|
||
| >>> [CLI] bundle auto-deploy delete -t prod --auto-approve | ||
| Deleted the auto-deploy trigger of target prod. | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/git-webhooks/trigger", | ||
| "body": { | ||
| "repo_url": "https://github.com/acme/repo", | ||
| "git_provider": "GITHUB", | ||
| "trigger_config": { | ||
| "push_event": { | ||
| "branch": "main" | ||
| }, | ||
| "dabs_deploy": { | ||
| "bundle_yml_repo_path": "databricks.yml", | ||
| "deployment_mode": "prod" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| { | ||
| "method": "DELETE", | ||
| "path": "/api/2.0/git-webhooks/trigger", | ||
| "body": { | ||
| "repo_url": "https://github.com/acme/repo", | ||
| "git_provider": "GITHUB", | ||
| "trigger_config": { | ||
| "push_event": { | ||
| "branch": "main" | ||
| }, | ||
| "dabs_deploy": { | ||
| "bundle_yml_repo_path": "databricks.yml", | ||
| "deployment_mode": "prod" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| >>> [CLI] bundle auto-deploy list | ||
| Target Branch Deploy as Trigger ID | ||
|
|
||
| === A target without a trigger | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy delete --auto-approve | ||
| Error: target dev has no auto-deploy trigger that you can view. To create one, run: databricks bundle auto-deploy create -t dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| git-repo-init | ||
| git remote add origin https://github.com/acme/repo | ||
|
|
||
| $CLI bundle auto-deploy create >> LOG.setup 2>&1 | ||
| $CLI bundle auto-deploy create -t prod >> LOG.setup 2>&1 | ||
| rm "$OUT_REQUESTS" | ||
|
|
||
| title "Without a terminal, delete needs --auto-approve" | ||
| trace musterr $CLI bundle auto-deploy delete | ||
|
|
||
| title "Deleting the target's trigger leaves the other target's" | ||
| trace $CLI bundle auto-deploy delete --auto-approve | ||
| print_requests.py //git-webhooks | ||
| trace $CLI bundle auto-deploy list | ||
|
|
||
| title "A retried delete sends its body again" | ||
| fault.py --body-contains deployment_mode "DELETE /api/2.0/git-webhooks/trigger" 503 0 1 TEMPORARILY_UNAVAILABLE | ||
| trace $CLI bundle auto-deploy delete -t prod --auto-approve | ||
| print_requests.py //git-webhooks | ||
| trace $CLI bundle auto-deploy list | ||
|
|
||
| title "A target without a trigger" | ||
| trace musterr $CLI bundle auto-deploy delete --auto-approve | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package autodeploy | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/databricks/cli/libs/gitwebhooks" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newDeleteCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "delete", | ||
| Short: "Stop auto-deploying this bundle target", | ||
| Long: `Stop auto-deploying this bundle target. | ||
|
|
||
| Deletes the target's auto-deploy trigger and the job that runs its deploys. | ||
| The service keeps the trigger's past attempts, but the attempts command can no | ||
| longer show them.`, | ||
| Args: root.NoArgs, | ||
| } | ||
|
|
||
| var autoApprove bool | ||
| cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip the confirmation prompt") | ||
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| t, api, err := loadTrigger(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ctx := cmd.Context() | ||
| found, err := findTrigger(ctx, api, t) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !autoApprove { | ||
| if !cmdio.IsPromptSupported(ctx) { | ||
| return fmt.Errorf("this deletes the auto-deploy trigger of target %s. To proceed, use --auto-approve", t.target) | ||
| } | ||
| ok, err := cmdio.AskYesOrNo(ctx, fmt.Sprintf("Delete the auto-deploy trigger of target %s?", t.target)) | ||
| if err != nil || !ok { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| err = api.DeleteWebhookTrigger(ctx, gitwebhooks.DeleteWebhookTrigger{ | ||
| RepoURL: found.RepoURL, | ||
| GitProvider: found.GitProvider, | ||
| TriggerConfig: &gitwebhooks.DeploymentTriggerConfig{ | ||
| PushEvent: found.TriggerConfig.PushEvent, | ||
| DabsDeploy: &gitwebhooks.DabsDeployTarget{ | ||
| BundleYmlRepoPath: t.bundlePath, | ||
| DeploymentMode: t.target, | ||
| }, | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| cmdio.LogString(ctx, fmt.Sprintf("Deleted the auto-deploy trigger of target %s.", t.target)) | ||
| return nil | ||
| } | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nice to have] After the retried
delete -t prod, the test only prints the requests. It never shows that prod's trigger is gone. If the retry returned a 2xx without the fake deleting anything, this golden would still be produced. The last section runs against dev, which an earlier section already deleted. Can we addtrace $CLI bundle auto-deploy listhere, or point the "target without a trigger" section at-t prod, so the output shows the state after the retry?