Repository navigation
Add bundle auto-deploy get and list
#7941
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-pr3-create
Choose a base branch
from
dabs-ad-d4-pr4-get-list
base: dabs-ad-d4-pr3-create
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.
+627
−5
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,85 @@ | ||
|
|
||
| === A target without a trigger | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy get | ||
| Error: target dev has no auto-deploy trigger that you can view. To create one, run: databricks bundle auto-deploy create -t dev | ||
|
|
||
| === The target's trigger | ||
|
|
||
| >>> [CLI] bundle auto-deploy get | ||
| Trigger ID: [UUID][0] | ||
| Repository: https://github.com/acme/repo | ||
| Bundle: databricks.yml | ||
| Target: dev | ||
| Branch: main | ||
| Deploy as: you or a user | ||
|
|
||
| >>> [CLI] bundle auto-deploy get -t prod | ||
| Trigger ID: [UUID][1] | ||
| Repository: https://github.com/acme/repo | ||
| Bundle: databricks.yml | ||
| Target: prod | ||
| Branch: main | ||
| Deploy as: [UUID][2] | ||
|
|
||
| >>> [CLI] bundle auto-deploy get -t prod -o json | ||
| { | ||
| "name": "webhook-triggers/[UUID][1]", | ||
| "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", | ||
| "deploy_as": { | ||
| "service_principal_client_id": "[UUID][2]" | ||
| } | ||
| }, | ||
| "trigger_id": "[UUID][1]" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"dev\"" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"", | ||
| "page_token": "1" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"", | ||
| "page_token": "1" | ||
| } | ||
| } | ||
|
|
||
| === Another caller does not see the trigger | ||
|
|
||
| >>> musterr as-test-sp [CLI] bundle auto-deploy get | ||
| 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,18 @@ | ||
| git-repo-init | ||
| git remote add origin https://github.com/acme/repo | ||
|
|
||
| title "A target without a trigger" | ||
| trace musterr $CLI bundle auto-deploy get | ||
|
|
||
| $CLI bundle auto-deploy create >> LOG.setup 2>&1 | ||
| $CLI bundle auto-deploy create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 >> LOG.setup 2>&1 | ||
| rm "$OUT_REQUESTS" | ||
|
|
||
| title "The target's trigger" | ||
| trace $CLI bundle auto-deploy get | ||
| trace $CLI bundle auto-deploy get -t prod | ||
| trace $CLI bundle auto-deploy get -t prod -o json | ||
| print_requests.py --get //git-webhooks | ||
|
|
||
| title "Another caller does not see the trigger" | ||
| trace musterr as-test-sp $CLI bundle auto-deploy get |
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,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,115 @@ | ||
|
|
||
| === A bundle without triggers | ||
|
|
||
| >>> [CLI] bundle auto-deploy list | ||
| Target Branch Deploy as Trigger ID | ||
|
|
||
| === Another bundle in the same repository, whose trigger is not this bundle's | ||
|
|
||
| >>> withdir other [CLI] bundle auto-deploy create | ||
| Pushes to branch main now deploy target dev as you. | ||
| Trigger ID: [UUID][0] | ||
| { | ||
| "method": "PUT", | ||
| "path": "/api/2.0/git-webhooks", | ||
| "body": { | ||
| "repo_url": "https://github.com/acme/repo", | ||
| "git_provider": "GITHUB", | ||
| "trigger_config": { | ||
| "push_event": { | ||
| "branch": "main" | ||
| }, | ||
| "dabs_deploy": { | ||
| "bundle_yml_repo_path": "other/databricks.yml", | ||
| "deployment_mode": "dev" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| === The triggers of this bundle's targets | ||
|
|
||
| >>> [CLI] bundle auto-deploy list | ||
| Target Branch Deploy as Trigger ID | ||
| dev main you or a user [UUID][1] | ||
| prod main you or a user [UUID][2] | ||
|
|
||
| >>> [CLI] bundle auto-deploy list -o json | ||
| [ | ||
| { | ||
| "name": "webhook-triggers/[UUID][1]", | ||
| "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" | ||
| }, | ||
| "trigger_id": "[UUID][1]" | ||
| } | ||
| }, | ||
| { | ||
| "name": "webhook-triggers/[UUID][2]", | ||
| "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" | ||
| }, | ||
| "trigger_id": "[UUID][2]" | ||
| } | ||
| } | ||
| ] | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"", | ||
| "page_token": "1" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"", | ||
| "page_token": "2" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"", | ||
| "page_token": "1" | ||
| } | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers", | ||
| "q": { | ||
| "filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"", | ||
| "page_token": "2" | ||
| } | ||
| } |
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,18 @@ | ||
| git-repo-init | ||
| git remote add origin https://github.com/acme/repo | ||
|
|
||
| title "A bundle without triggers" | ||
| trace $CLI bundle auto-deploy list | ||
|
|
||
| $CLI bundle auto-deploy create >> LOG.setup 2>&1 | ||
| $CLI bundle auto-deploy create -t prod >> LOG.setup 2>&1 | ||
| rm "$OUT_REQUESTS" | ||
|
|
||
| title "Another bundle in the same repository, whose trigger is not this bundle's" | ||
| trace withdir other $CLI bundle auto-deploy create | ||
| print_requests.py //git-webhooks | ||
|
|
||
| title "The triggers of this bundle's targets" | ||
| trace $CLI bundle auto-deploy list | ||
| trace $CLI bundle auto-deploy list -o json | ||
| print_requests.py --get //git-webhooks |
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,45 @@ | ||
| package autodeploy | ||
|
|
||
| import ( | ||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // The service shows deploy_as only for a service principal other than the caller, so an unset | ||
| // value is the caller or a user, which an admin's update can make someone other than the creator. | ||
| const deployAsTemplate = `{{with .TriggerConfig.DabsDeploy.DeployAs}}{{.ServicePrincipalClientID}}{{else}}you or a user{{end}}` | ||
|
|
||
| const getTemplate = `Trigger ID: {{.TriggerConfig.TriggerID}} | ||
| Repository: {{.RepoURL}} | ||
| Bundle: {{.TriggerConfig.DabsDeploy.BundleYmlRepoPath}} | ||
| Target: {{.TriggerConfig.DabsDeploy.DeploymentMode}} | ||
| Branch: {{.TriggerConfig.PushEvent.Branch}} | ||
| Deploy as: ` + deployAsTemplate + ` | ||
| ` | ||
|
|
||
| func newGetCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "get", | ||
| Short: "Show the auto-deploy trigger of this bundle target", | ||
| Args: root.NoArgs, | ||
| Annotations: map[string]string{ | ||
| "template": getTemplate, | ||
| }, | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
| return cmdio.Render(ctx, found) | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package autodeploy | ||
|
|
||
| import ( | ||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/databricks/cli/libs/gitwebhooks" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List the auto-deploy triggers of this bundle's targets", | ||
| Long: `List the auto-deploy triggers of this bundle's targets. | ||
|
|
||
| The triggers are those for the origin URL and workspace of the selected target | ||
| (-t). A target with another workspace or origin has its triggers there.`, | ||
| Args: root.NoArgs, | ||
| Annotations: map[string]string{ | ||
| "headerTemplate": `{{header "Target"}} {{header "Branch"}} {{header "Deploy as"}} {{header "Trigger ID"}}`, | ||
| "template": cmdio.Heredoc(` | ||
| {{range .}}{{.TriggerConfig.DabsDeploy.DeploymentMode | green}} {{.TriggerConfig.PushEvent.Branch}} ` + deployAsTemplate + ` {{.TriggerConfig.TriggerID}} | ||
| {{end}}`), | ||
| }, | ||
| } | ||
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| t, api, err := loadTrigger(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ctx := cmd.Context() | ||
| return cmdio.RenderIterator(ctx, api.ListWebhookTriggers(ctx, gitwebhooks.ListWebhookTriggersRequest{Filter: t.bundleFilter()})) | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
Oops, something went wrong.
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]
listsays it covers "this bundle's targets", butloadTriggerrunsProcessBundle, which selects one target first. In a bundle with two targets and nodefault: true,bundle auto-deploy listfails with "please specify target" even though the filter never uses the target. Whenprodsets its ownworkspace.host, runninglistfromdevonly queries dev's workspace and leaves out prod's trigger without saying so. The same happens when a target overridesbundle.git.origin_url, becauserepo_urlcomes from the selected target (trigger.goresolveTrigger). Shouldlistwork without a selected target, or go through each target's workspace and origin? Failing that, can the help text say it lists the triggers in the selected target's workspace and repository?