Make all workspace paths string fields (#327)

## Changes

These are unlikely to ever be DBFS paths so we can remove this level of indirection to simplify.

**Note:** this is a breaking change. Downstream usage of these fields must be updated.

## Tests

Existing tests pass.
This commit is contained in:
Pieter Noordhuis 2023-04-12 16:54:36 +02:00 committed by GitHub
parent 31ccebd62a
commit b388f4a0dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 51 additions and 78 deletions

View File

@ -64,7 +64,7 @@ func (m *build) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, er
} }
// Check that an artifact path is defined. // Check that an artifact path is defined.
remotePath := b.Config.Workspace.ArtifactPath.Workspace remotePath := b.Config.Workspace.ArtifactsPath
if remotePath == "" { if remotePath == "" {
return nil, fmt.Errorf("remote artifact path not configured") return nil, fmt.Errorf("remote artifact path not configured")
} }

View File

@ -20,21 +20,21 @@ func (m *defineDefaultWorkspacePaths) Name() string {
} }
func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) { func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
root := b.Config.Workspace.Root root := b.Config.Workspace.RootPath
if root == "" { if root == "" {
return nil, fmt.Errorf("unable to define default workspace paths: workspace root not defined") return nil, fmt.Errorf("unable to define default workspace paths: workspace root not defined")
} }
if !b.Config.Workspace.FilePath.IsSet() { if b.Config.Workspace.FilesPath == "" {
b.Config.Workspace.FilePath.Workspace = path.Join(root, "files") b.Config.Workspace.FilesPath = path.Join(root, "files")
} }
if !b.Config.Workspace.ArtifactPath.IsSet() { if b.Config.Workspace.ArtifactsPath == "" {
b.Config.Workspace.ArtifactPath.Workspace = path.Join(root, "artifacts") b.Config.Workspace.ArtifactsPath = path.Join(root, "artifacts")
} }
if !b.Config.Workspace.StatePath.IsSet() { if b.Config.Workspace.StatePath == "" {
b.Config.Workspace.StatePath.Workspace = path.Join(root, "state") b.Config.Workspace.StatePath = path.Join(root, "state")
} }
return nil, nil return nil, nil

View File

@ -15,37 +15,31 @@ func TestDefineDefaultWorkspacePaths(t *testing.T) {
bundle := &bundle.Bundle{ bundle := &bundle.Bundle{
Config: config.Root{ Config: config.Root{
Workspace: config.Workspace{ Workspace: config.Workspace{
Root: "/", RootPath: "/",
}, },
}, },
} }
_, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle) _, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "/files", bundle.Config.Workspace.FilePath.Workspace) assert.Equal(t, "/files", bundle.Config.Workspace.FilesPath)
assert.Equal(t, "/artifacts", bundle.Config.Workspace.ArtifactPath.Workspace) assert.Equal(t, "/artifacts", bundle.Config.Workspace.ArtifactsPath)
assert.Equal(t, "/state", bundle.Config.Workspace.StatePath.Workspace) assert.Equal(t, "/state", bundle.Config.Workspace.StatePath)
} }
func TestDefineDefaultWorkspacePathsAlreadySet(t *testing.T) { func TestDefineDefaultWorkspacePathsAlreadySet(t *testing.T) {
bundle := &bundle.Bundle{ bundle := &bundle.Bundle{
Config: config.Root{ Config: config.Root{
Workspace: config.Workspace{ Workspace: config.Workspace{
Root: "/", RootPath: "/",
FilePath: config.PathLike{ FilesPath: "/foo/bar",
Workspace: "/foo/bar", ArtifactsPath: "/foo/bar",
}, StatePath: "/foo/bar",
ArtifactPath: config.PathLike{
Workspace: "/foo/bar",
},
StatePath: config.PathLike{
Workspace: "/foo/bar",
},
}, },
}, },
} }
_, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle) _, err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), bundle)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "/foo/bar", bundle.Config.Workspace.FilePath.Workspace) assert.Equal(t, "/foo/bar", bundle.Config.Workspace.FilesPath)
assert.Equal(t, "/foo/bar", bundle.Config.Workspace.ArtifactPath.Workspace) assert.Equal(t, "/foo/bar", bundle.Config.Workspace.ArtifactsPath)
assert.Equal(t, "/foo/bar", bundle.Config.Workspace.StatePath.Workspace) assert.Equal(t, "/foo/bar", bundle.Config.Workspace.StatePath)
} }

View File

@ -19,7 +19,7 @@ func (m *defineDefaultWorkspaceRoot) Name() string {
} }
func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) { func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
if b.Config.Workspace.Root != "" { if b.Config.Workspace.RootPath != "" {
return nil, nil return nil, nil
} }
@ -31,7 +31,7 @@ func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle
return nil, fmt.Errorf("unable to define default workspace root: bundle environment not selected") return nil, fmt.Errorf("unable to define default workspace root: bundle environment not selected")
} }
b.Config.Workspace.Root = fmt.Sprintf( b.Config.Workspace.RootPath = fmt.Sprintf(
"~/.bundle/%s/%s", "~/.bundle/%s/%s",
b.Config.Bundle.Name, b.Config.Bundle.Name,
b.Config.Bundle.Environment, b.Config.Bundle.Environment,

View File

@ -22,5 +22,5 @@ func TestDefaultWorkspaceRoot(t *testing.T) {
} }
_, err := mutator.DefineDefaultWorkspaceRoot().Apply(context.Background(), bundle) _, err := mutator.DefineDefaultWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "~/.bundle/name/environment", bundle.Config.Workspace.Root) assert.Equal(t, "~/.bundle/name/environment", bundle.Config.Workspace.RootPath)
} }

View File

@ -21,7 +21,7 @@ func (m *expandWorkspaceRoot) Name() string {
} }
func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) { func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
root := b.Config.Workspace.Root root := b.Config.Workspace.RootPath
if root == "" { if root == "" {
return nil, fmt.Errorf("unable to expand workspace root: workspace root not defined") return nil, fmt.Errorf("unable to expand workspace root: workspace root not defined")
} }
@ -33,7 +33,7 @@ func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) ([]bu
if strings.HasPrefix(root, "~/") { if strings.HasPrefix(root, "~/") {
home := fmt.Sprintf("/Users/%s", currentUser.UserName) home := fmt.Sprintf("/Users/%s", currentUser.UserName)
b.Config.Workspace.Root = path.Join(home, root[2:]) b.Config.Workspace.RootPath = path.Join(home, root[2:])
} }
return nil, nil return nil, nil

View File

@ -19,13 +19,13 @@ func TestExpandWorkspaceRoot(t *testing.T) {
CurrentUser: &scim.User{ CurrentUser: &scim.User{
UserName: "jane@doe.com", UserName: "jane@doe.com",
}, },
Root: "~/foo", RootPath: "~/foo",
}, },
}, },
} }
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle) _, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "/Users/jane@doe.com/foo", bundle.Config.Workspace.Root) assert.Equal(t, "/Users/jane@doe.com/foo", bundle.Config.Workspace.RootPath)
} }
func TestExpandWorkspaceRootDoesNothing(t *testing.T) { func TestExpandWorkspaceRootDoesNothing(t *testing.T) {
@ -35,13 +35,13 @@ func TestExpandWorkspaceRootDoesNothing(t *testing.T) {
CurrentUser: &scim.User{ CurrentUser: &scim.User{
UserName: "jane@doe.com", UserName: "jane@doe.com",
}, },
Root: "/Users/charly@doe.com/foo", RootPath: "/Users/charly@doe.com/foo",
}, },
}, },
} }
_, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle) _, err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), bundle)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "/Users/charly@doe.com/foo", bundle.Config.Workspace.Root) assert.Equal(t, "/Users/charly@doe.com/foo", bundle.Config.Workspace.RootPath)
} }
func TestExpandWorkspaceRootWithoutRoot(t *testing.T) { func TestExpandWorkspaceRootWithoutRoot(t *testing.T) {
@ -62,7 +62,7 @@ func TestExpandWorkspaceRootWithoutCurrentUser(t *testing.T) {
bundle := &bundle.Bundle{ bundle := &bundle.Bundle{
Config: config.Root{ Config: config.Root{
Workspace: config.Workspace{ Workspace: config.Workspace{
Root: "~/foo", RootPath: "~/foo",
}, },
}, },
} }

View File

@ -64,7 +64,7 @@ func (m *translatePaths) rewritePath(
} }
// Prefix remote path with its remote root path. // Prefix remote path with its remote root path.
remotePath = path.Join(b.Config.Workspace.FilePath.Workspace, filepath.ToSlash(remotePath)) remotePath = path.Join(b.Config.Workspace.FilesPath, filepath.ToSlash(remotePath))
// Convert local path into workspace path via specified function. // Convert local path into workspace path via specified function.
interp, err := fn(*p, localPath, filepath.ToSlash(remotePath)) interp, err := fn(*p, localPath, filepath.ToSlash(remotePath))

View File

@ -41,9 +41,7 @@ func TestTranslatePaths(t *testing.T) {
Config: config.Root{ Config: config.Root{
Path: dir, Path: dir,
Workspace: config.Workspace{ Workspace: config.Workspace{
FilePath: config.PathLike{ FilesPath: "/bundle",
Workspace: "/bundle",
},
}, },
Resources: config.Resources{ Resources: config.Resources{
Jobs: map[string]*resources.Job{ Jobs: map[string]*resources.Job{
@ -177,9 +175,7 @@ func TestTranslatePathsInSubdirectories(t *testing.T) {
Config: config.Root{ Config: config.Root{
Path: dir, Path: dir,
Workspace: config.Workspace{ Workspace: config.Workspace{
FilePath: config.PathLike{ FilesPath: "/bundle",
Workspace: "/bundle",
},
}, },
Resources: config.Resources{ Resources: config.Resources{
Jobs: map[string]*resources.Job{ Jobs: map[string]*resources.Job{
@ -242,9 +238,7 @@ func TestTranslatePathsOutsideBundleRoot(t *testing.T) {
Config: config.Root{ Config: config.Root{
Path: dir, Path: dir,
Workspace: config.Workspace{ Workspace: config.Workspace{
FilePath: config.PathLike{ FilesPath: "/bundle",
Workspace: "/bundle",
},
}, },
Resources: config.Resources{ Resources: config.Resources{
Jobs: map[string]*resources.Job{ Jobs: map[string]*resources.Job{

View File

@ -10,19 +10,6 @@ import (
"github.com/databricks/databricks-sdk-go/service/scim" "github.com/databricks/databricks-sdk-go/service/scim"
) )
type PathLike struct {
// Workspace contains a WSFS path.
Workspace string `json:"workspace,omitempty"`
// DBFS contains a DBFS path.
DBFS string `json:"dbfs,omitempty"`
}
// IsSet returns whether either path is non-nil.
func (p PathLike) IsSet() bool {
return p.Workspace != "" || p.DBFS != ""
}
// Workspace defines configurables at the workspace level. // Workspace defines configurables at the workspace level.
type Workspace struct { type Workspace struct {
// Unified authentication attributes. // Unified authentication attributes.
@ -52,22 +39,22 @@ type Workspace struct {
// This is set after configuration initialization. // This is set after configuration initialization.
CurrentUser *scim.User `json:"current_user,omitempty" bundle:"readonly"` CurrentUser *scim.User `json:"current_user,omitempty" bundle:"readonly"`
// Remote base path for deployment state, for artifacts, as synchronization target. // Remote workspace base path for deployment state, for artifacts, as synchronization target.
// This defaults to "~/.bundle/${bundle.name}/${bundle.environment}" where "~" expands to // This defaults to "~/.bundle/${bundle.name}/${bundle.environment}" where "~" expands to
// the current user's home directory in the workspace (e.g. `/Users/jane@doe.com`). // the current user's home directory in the workspace (e.g. `/Users/jane@doe.com`).
Root string `json:"root,omitempty"` RootPath string `json:"root_path,omitempty"`
// Remote path to synchronize local files to. // Remote workspace path to synchronize local files to.
// This defaults to "${workspace.root}/files". // This defaults to "${workspace.root}/files".
FilePath PathLike `json:"file_path,omitempty"` FilesPath string `json:"file_path,omitempty"`
// Remote path for build artifacts. // Remote workspace path for build artifacts.
// This defaults to "${workspace.root}/artifacts". // This defaults to "${workspace.root}/artifacts".
ArtifactPath PathLike `json:"artifact_path,omitempty"` ArtifactsPath string `json:"artifact_path,omitempty"`
// Remote path for deployment state. // Remote workspace path for deployment state.
// This defaults to "${workspace.root}/state". // This defaults to "${workspace.root}/state".
StatePath PathLike `json:"state_path,omitempty"` StatePath string `json:"state_path,omitempty"`
} }
func (w *Workspace) Client() (*databricks.WorkspaceClient, error) { func (w *Workspace) Client() (*databricks.WorkspaceClient, error) {

View File

@ -30,9 +30,9 @@ func (m *delete) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
} }
red := color.New(color.FgRed).SprintFunc() red := color.New(color.FgRed).SprintFunc()
fmt.Fprintf(os.Stderr, "\nRemote directory %s will be deleted\n", b.Config.Workspace.Root) fmt.Fprintf(os.Stderr, "\nRemote directory %s will be deleted\n", b.Config.Workspace.RootPath)
if !b.AutoApprove { if !b.AutoApprove {
proceed, err := logger.Ask(fmt.Sprintf("%s and all files in it will be %s Proceed?: ", b.Config.Workspace.Root, red("deleted permanently!"))) proceed, err := logger.Ask(fmt.Sprintf("%s and all files in it will be %s Proceed?: ", b.Config.Workspace.RootPath, red("deleted permanently!")))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,7 +42,7 @@ func (m *delete) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
} }
err := b.WorkspaceClient().Workspace.Delete(ctx, workspace.Delete{ err := b.WorkspaceClient().Workspace.Delete(ctx, workspace.Delete{
Path: b.Config.Workspace.Root, Path: b.Config.Workspace.RootPath,
Recursive: true, Recursive: true,
}) })
if err != nil { if err != nil {

View File

@ -16,7 +16,7 @@ func getSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) {
opts := sync.SyncOptions{ opts := sync.SyncOptions{
LocalPath: b.Config.Path, LocalPath: b.Config.Path,
RemotePath: b.Config.Workspace.FilePath.Workspace, RemotePath: b.Config.Workspace.FilesPath,
Full: false, Full: false,
SnapshotBasePath: cacheDir, SnapshotBasePath: cacheDir,

View File

@ -20,7 +20,7 @@ func (m *acquire) Name() string {
func (m *acquire) init(b *bundle.Bundle) error { func (m *acquire) init(b *bundle.Bundle) error {
user := b.Config.Workspace.CurrentUser.UserName user := b.Config.Workspace.CurrentUser.UserName
dir := b.Config.Workspace.StatePath.Workspace dir := b.Config.Workspace.StatePath
l, err := locker.CreateLocker(user, dir, b.WorkspaceClient()) l, err := locker.CreateLocker(user, dir, b.WorkspaceClient())
if err != nil { if err != nil {
return err return err

View File

@ -19,7 +19,7 @@ func (l *statePull) Name() string {
} }
func (l *statePull) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) { func (l *statePull) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
f, err := filer.NewWorkspaceFilesClient(b.WorkspaceClient(), b.Config.Workspace.StatePath.Workspace) f, err := filer.NewWorkspaceFilesClient(b.WorkspaceClient(), b.Config.Workspace.StatePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,7 +17,7 @@ func (l *statePush) Name() string {
} }
func (l *statePush) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) { func (l *statePush) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
f, err := filer.NewWorkspaceFilesClient(b.WorkspaceClient(), b.Config.Workspace.StatePath.Workspace) f, err := filer.NewWorkspaceFilesClient(b.WorkspaceClient(), b.Config.Workspace.StatePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,7 +20,7 @@ func syncOptionsFromBundle(cmd *cobra.Command, b *bundle.Bundle) (*sync.SyncOpti
opts := sync.SyncOptions{ opts := sync.SyncOptions{
LocalPath: b.Config.Path, LocalPath: b.Config.Path,
RemotePath: b.Config.Workspace.FilePath.Workspace, RemotePath: b.Config.Workspace.FilesPath,
Full: full, Full: full,
PollInterval: interval, PollInterval: interval,

View File

@ -29,7 +29,7 @@ func syncOptionsFromBundle(cmd *cobra.Command, args []string, b *bundle.Bundle)
opts := sync.SyncOptions{ opts := sync.SyncOptions{
LocalPath: b.Config.Path, LocalPath: b.Config.Path,
RemotePath: b.Config.Workspace.FilePath.Workspace, RemotePath: b.Config.Workspace.FilesPath,
Full: full, Full: full,
PollInterval: interval, PollInterval: interval,

View File

@ -22,9 +22,7 @@ func TestSyncOptionsFromBundle(t *testing.T) {
}, },
Workspace: config.Workspace{ Workspace: config.Workspace{
FilePath: config.PathLike{ FilesPath: "/Users/jane@doe.com/path",
Workspace: "/Users/jane@doe.com/path",
},
}, },
}, },
} }