diff --git a/bundle/bundle.go b/bundle/bundle.go index 86e0872a..71ebe268 100644 --- a/bundle/bundle.go +++ b/bundle/bundle.go @@ -1,3 +1,9 @@ +// Package bundle is the top level package for Databricks Application Bundles. +// +// A bundle is represented by the [Bundle] type. It consists of configuration +// and runtime state, such as a client to a Databricks workspace. +// Every mutation to a bundle's configuration or state is represented as a [Mutator]. +// This interface makes every mutation observable and lets us reason about sequencing. package bundle import ( diff --git a/bundle/phases/build.go b/bundle/phases/build.go new file mode 100644 index 00000000..ec0f1e89 --- /dev/null +++ b/bundle/phases/build.go @@ -0,0 +1,20 @@ +package phases + +import ( + "github.com/databricks/bricks/bundle" + "github.com/databricks/bricks/bundle/artifacts" + "github.com/databricks/bricks/bundle/config/interpolation" +) + +// The build phase builds artifacts. +func Build() bundle.Mutator { + return newPhase( + "build", + []bundle.Mutator{ + artifacts.BuildAll(), + interpolation.Interpolate( + interpolation.IncludeLookupsInPath("artifacts"), + ), + }, + ) +} diff --git a/bundle/phases/deploy.go b/bundle/phases/deploy.go new file mode 100644 index 00000000..8a8e2820 --- /dev/null +++ b/bundle/phases/deploy.go @@ -0,0 +1,20 @@ +package phases + +import ( + "github.com/databricks/bricks/bundle" + "github.com/databricks/bricks/bundle/artifacts" + "github.com/databricks/bricks/bundle/deploy/terraform" +) + +// The deploy phase deploys artifacts and resources. +func Deploy() bundle.Mutator { + return newPhase( + "deploy", + []bundle.Mutator{ + artifacts.UploadAll(), + terraform.Interpolate(), + terraform.Write(), + terraform.Apply(), + }, + ) +} diff --git a/bundle/phases/initialize.go b/bundle/phases/initialize.go new file mode 100644 index 00000000..22a24116 --- /dev/null +++ b/bundle/phases/initialize.go @@ -0,0 +1,24 @@ +package phases + +import ( + "github.com/databricks/bricks/bundle" + "github.com/databricks/bricks/bundle/config/interpolation" + "github.com/databricks/bricks/bundle/config/mutator" +) + +// The initialize phase fills in defaults and connects to the workspace. +// Interpolation of fields referring to the "bundle" and "workspace" keys +// happens upon completion of this phase. +func Initialize() bundle.Mutator { + return newPhase( + "initialize", + []bundle.Mutator{ + mutator.PopulateCurrentUser(), + mutator.DefaultArtifactPath(), + interpolation.Interpolate( + interpolation.IncludeLookupsInPath("bundle"), + interpolation.IncludeLookupsInPath("workspace"), + ), + }, + ) +} diff --git a/bundle/phases/phase.go b/bundle/phases/phase.go new file mode 100644 index 00000000..0016f41c --- /dev/null +++ b/bundle/phases/phase.go @@ -0,0 +1,30 @@ +// Package phases defines build phases as logical groups of [bundle.Mutator] instances. +package phases + +import ( + "context" + + "github.com/databricks/bricks/bundle" +) + +// This phase type groups mutators that belong to a lifecycle phase. +// It expands into the specific mutators when applied. +type phase struct { + name string + mutators []bundle.Mutator +} + +func newPhase(name string, mutators []bundle.Mutator) bundle.Mutator { + return &phase{ + name: name, + mutators: mutators, + } +} + +func (p *phase) Name() string { + return p.name +} + +func (p *phase) Apply(context.Context, *bundle.Bundle) ([]bundle.Mutator, error) { + return p.mutators, nil +} diff --git a/cmd/bundle/deploy.go b/cmd/bundle/deploy.go new file mode 100644 index 00000000..4bd726fc --- /dev/null +++ b/cmd/bundle/deploy.go @@ -0,0 +1,26 @@ +package bundle + +import ( + "github.com/databricks/bricks/bundle" + "github.com/databricks/bricks/bundle/phases" + "github.com/spf13/cobra" +) + +var deployCmd = &cobra.Command{ + Use: "deploy", + Short: "Deploy bundle", + + PreRunE: ConfigureBundle, + RunE: func(cmd *cobra.Command, args []string) error { + b := bundle.Get(cmd.Context()) + return bundle.Apply(cmd.Context(), b, []bundle.Mutator{ + phases.Initialize(), + phases.Build(), + phases.Deploy(), + }) + }, +} + +func init() { + AddCommand(deployCmd) +}