mirror of https://github.com/databricks/cli.git
Define deploy command as sequence of build phases (#129)
This commit is contained in:
parent
8640696b4b
commit
c255bd686a
|
@ -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
|
package bundle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -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"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -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(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -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"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue