2022-11-30 13:15:22 +00:00
|
|
|
package config
|
|
|
|
|
2023-07-25 11:35:08 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-09-04 09:55:01 +00:00
|
|
|
"github.com/databricks/cli/bundle/config/paths"
|
2023-12-21 15:45:23 +00:00
|
|
|
"github.com/databricks/cli/libs/exec"
|
2023-07-25 11:35:08 +00:00
|
|
|
)
|
|
|
|
|
2023-09-04 09:55:01 +00:00
|
|
|
type Artifacts map[string]*Artifact
|
|
|
|
|
|
|
|
func (artifacts Artifacts) SetConfigFilePath(path string) {
|
|
|
|
for _, artifact := range artifacts {
|
|
|
|
artifact.ConfigFilePath = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 11:35:08 +00:00
|
|
|
type ArtifactType string
|
|
|
|
|
|
|
|
const ArtifactPythonWheel ArtifactType = `whl`
|
|
|
|
|
|
|
|
type ArtifactFile struct {
|
2024-02-05 15:29:45 +00:00
|
|
|
Source string `json:"source"`
|
|
|
|
RemotePath string `json:"remote_path" bundle:"readonly"`
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
2022-11-30 13:15:22 +00:00
|
|
|
|
|
|
|
// Artifact defines a single local code artifact that can be
|
|
|
|
// built/uploaded/referenced in the context of this bundle.
|
|
|
|
type Artifact struct {
|
2023-07-25 11:35:08 +00:00
|
|
|
Type ArtifactType `json:"type"`
|
2022-11-30 13:15:22 +00:00
|
|
|
|
2023-07-25 11:35:08 +00:00
|
|
|
// The local path to the directory with a root of artifact,
|
|
|
|
// for example, where setup.py is for Python projects
|
2023-10-03 13:59:28 +00:00
|
|
|
Path string `json:"path,omitempty"`
|
2022-11-30 13:15:22 +00:00
|
|
|
|
2023-07-25 11:35:08 +00:00
|
|
|
// The relative or absolute path to the built artifact files
|
|
|
|
// (Python wheel, Java jar and etc) itself
|
2023-10-03 13:59:28 +00:00
|
|
|
Files []ArtifactFile `json:"files,omitempty"`
|
|
|
|
BuildCommand string `json:"build,omitempty"`
|
2023-09-04 09:55:01 +00:00
|
|
|
|
2024-02-01 14:10:04 +00:00
|
|
|
Executable exec.ExecutableType `json:"executable,omitempty"`
|
|
|
|
|
2023-09-04 09:55:01 +00:00
|
|
|
paths.Paths
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Build(ctx context.Context) ([]byte, error) {
|
|
|
|
if a.BuildCommand == "" {
|
|
|
|
return nil, fmt.Errorf("no build property defined")
|
|
|
|
}
|
|
|
|
|
2024-02-01 14:10:04 +00:00
|
|
|
var e *exec.Executor
|
|
|
|
var err error
|
|
|
|
if a.Executable != "" {
|
|
|
|
e, err = exec.NewCommandExecutorWithExecutable(a.Path, a.Executable)
|
|
|
|
} else {
|
|
|
|
e, err = exec.NewCommandExecutor(a.Path)
|
|
|
|
a.Executable = e.ShellType()
|
|
|
|
}
|
2023-12-21 15:45:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-07-26 12:58:52 +00:00
|
|
|
}
|
2023-12-21 15:45:23 +00:00
|
|
|
return e.Exec(ctx, a.BuildCommand)
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|