Skip to content

Commit

Permalink
Merge pull request #271 from depot/exec
Browse files Browse the repository at this point in the history
Add engine detection to `exec`
  • Loading branch information
jacobwgillespie authored Apr 16, 2024
2 parents 35ed411 + 903b591 commit b17b4aa
Show file tree
Hide file tree
Showing 5 changed files with 809 additions and 499 deletions.
8 changes: 8 additions & 0 deletions pkg/cmd/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func NewCmdExec(dockerCli command.Cli) *cobra.Command {
ProjectId: &projectID,
Options: []*cliv1.BuildOptions{{Command: cliv1.Command_COMMAND_EXEC}},
}

if len(args) > 0 && args[0] == "dagger" {
daggerVersion, _ := helpers.ResolveDaggerVersion()
if daggerVersion != "" {
req = helpers.NewDaggerRequest(projectID, daggerVersion)
}
}

build, err := helpers.BeginBuild(ctx, req, token)
if err != nil {
return fmt.Errorf("unable to begin build: %w", err)
Expand Down
14 changes: 14 additions & 0 deletions pkg/helpers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ func NewBakeRequest(project string, opts map[string]buildx.Options, features Usi
Options: targets,
}
}

func NewDaggerRequest(projectID, daggerVersion string) *cliv1.CreateBuildRequest {
return &cliv1.CreateBuildRequest{
ProjectId: &projectID,
Options: []*cliv1.BuildOptions{{Command: cliv1.Command_COMMAND_DAGGER}},
RequiredEngine: &cliv1.CreateBuildRequest_RequiredEngine{
Engine: &cliv1.CreateBuildRequest_RequiredEngine_Dagger{
Dagger: &cliv1.CreateBuildRequest_RequiredEngine_DaggerEngine{
Version: daggerVersion,
},
},
},
}
}
25 changes: 25 additions & 0 deletions pkg/helpers/dagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package helpers

import (
"fmt"
"os/exec"
"strings"
)

func ResolveDaggerVersion() (string, error) {
daggerPath, err := exec.LookPath("dagger")
if err != nil {
return "", err
}

output, err := exec.Command(daggerPath, "version").Output()
if err != nil {
return "", err
}

parsed := strings.Split(string(output), " ")
if len(parsed) < 2 {
return "", fmt.Errorf("unable able to parse dagger version")
}
return parsed[1], nil
}
Loading

0 comments on commit b17b4aa

Please sign in to comment.