2024-03-18 14:41:58 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2024-03-18 14:41:58 +00:00
|
|
|
"github.com/databricks/cli/libs/filer"
|
|
|
|
"github.com/databricks/cli/libs/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type statePush struct {
|
|
|
|
filerFactory FilerFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *statePush) Name() string {
|
|
|
|
return "deploy:state-push"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (s *statePush) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2024-03-18 14:41:58 +00:00
|
|
|
f, err := s.filerFactory(b)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
statePath, err := getPathToStateFile(ctx, b)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local, err := os.Open(statePath)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|
|
|
|
defer local.Close()
|
|
|
|
|
|
|
|
log.Infof(ctx, "Writing local deployment state file to remote state directory")
|
|
|
|
err = f.Write(ctx, DeploymentStateFileName, local, filer.CreateParentDirectories, filer.OverwriteIfExists)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StatePush returns a mutator that pushes the deployment state file to Databricks workspace.
|
|
|
|
func StatePush() bundle.Mutator {
|
|
|
|
return &statePush{StateFiler}
|
|
|
|
}
|