Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions cmd/apps/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
appkitRepoURL = "https://github.com/databricks/appkit"
appkitTemplateDir = "template"
appkitDefaultBranch = "main"
defaultProfile = "DEFAULT"
)

// normalizeVersion ensures the version string has a "v" prefix if it looks like a semver.
Expand Down Expand Up @@ -808,20 +809,24 @@ func runCreate(ctx context.Context, opts createOptions) error {
if err := os.Chdir(absOutputDir); err != nil {
return fmt.Errorf("failed to change to project directory: %w", err)
}
if profile == "" {
// If the profile is not set, it means the DEFAULT profile was used to infer the workspace host, we set it so that it's used for the deploy and dev-remote commands
profile = defaultProfile
}
}

if shouldDeploy {
cmdio.LogString(ctx, "")
cmdio.LogString(ctx, "Deploying app...")
if err := runPostCreateDeploy(ctx); err != nil {
if err := runPostCreateDeploy(ctx, profile); err != nil {
cmdio.LogString(ctx, fmt.Sprintf("⚠ Deploy failed: %v", err))
cmdio.LogString(ctx, " You can deploy manually with: databricks apps deploy")
}
}

if runMode != prompt.RunModeNone {
cmdio.LogString(ctx, "")
if err := runPostCreateDev(ctx, runMode, projectInitializer, absOutputDir); err != nil {
if err := runPostCreateDev(ctx, runMode, projectInitializer, absOutputDir, profile); err != nil {
return err
}
}
Expand All @@ -830,20 +835,25 @@ func runCreate(ctx context.Context, opts createOptions) error {
}

// runPostCreateDeploy runs the deploy command in the current directory.
func runPostCreateDeploy(ctx context.Context) error {
func runPostCreateDeploy(ctx context.Context, profile string) error {
executable, err := os.Executable()
if err != nil {
return fmt.Errorf("failed to get executable path: %w", err)
}
cmd := exec.CommandContext(ctx, executable, "apps", "deploy")
args := []string{"apps", "deploy"}
if profile != "" {
// We ensure the same profile is used for the deploy command as the one used for the init command
args = append(args, "--profile", profile)
}
cmd := exec.CommandContext(ctx, executable, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

// runPostCreateDev runs the dev or dev-remote command in the current directory.
func runPostCreateDev(ctx context.Context, mode prompt.RunMode, projectInit initializer.Initializer, workDir string) error {
func runPostCreateDev(ctx context.Context, mode prompt.RunMode, projectInit initializer.Initializer, workDir, profile string) error {
switch mode {
case prompt.RunModeDev:
if projectInit != nil {
Expand All @@ -858,7 +868,12 @@ func runPostCreateDev(ctx context.Context, mode prompt.RunMode, projectInit init
if err != nil {
return fmt.Errorf("failed to get executable path: %w", err)
}
cmd := exec.CommandContext(ctx, executable, "apps", "dev-remote")
args := []string{"apps", "dev-remote"}
if profile != "" {
// We ensure the same profile is used for the dev-remote command as the one used for the init command
args = append(args, "--profile", profile)
}
cmd := exec.CommandContext(ctx, executable, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
Expand Down