Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bacalhau --local #437

Merged
merged 30 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4cb0c18
bacalhau --local
js-ts Aug 2, 2022
711d48c
adding test for --local
js-ts Aug 3, 2022
7df27a4
//nolint:unused,deadcode
js-ts Aug 3, 2022
7e61074
removing line
js-ts Aug 3, 2022
b010732
add require.Noeror
js-ts Aug 3, 2022
eff3486
chainging permissions
Aug 3, 2022
970a194
adding comments, and default for isLocal
js-ts Aug 3, 2022
6657dc4
Merge branch 'main' into bacalhau_local
js-ts Aug 4, 2022
a65907f
Make Input Volumes Work
js-ts Aug 5, 2022
325a8a7
Merge branch 'main' into bacalhau_local
js-ts Aug 6, 2022
0e8305b
resolving merge errors
js-ts Aug 6, 2022
f1d2996
removing nolint spaces
js-ts Aug 6, 2022
d37a106
lint issues
js-ts Aug 6, 2022
5302bdb
removing comment
js-ts Aug 6, 2022
6712e76
add test for --local input
js-ts Aug 8, 2022
b1815c6
try fix lint error
js-ts Aug 8, 2022
7623cf8
pull .circleci\config.yaml from main
js-ts Aug 8, 2022
fd380cd
Update config.yml
enricorotundo Aug 9, 2022
fc23661
add a local devstack mode that is the same but with a publically conn…
binocarlos Aug 10, 2022
94a89bc
remove local executor - local is more about having a devstack locally…
binocarlos Aug 10, 2022
8472c0e
pass the job into local devstack
binocarlos Aug 10, 2022
9adb6e7
Fix expected vs acutal comparison in --local test
Aug 11, 2022
76887f6
Fix subtle bug
Aug 11, 2022
0b8637f
Fix test cases for --local flag
Aug 11, 2022
9d56ec0
Fix conflict with main branch
Aug 11, 2022
5a248cd
Fix CI errors
Aug 11, 2022
f305770
Merge branch 'main' of https://github.com/filecoin-project/bacalhau i…
Aug 12, 2022
33d5bc2
Pull to fix tests, Remove the Local interface
js-ts Aug 12, 2022
5de5dda
Add GPU support
js-ts Aug 12, 2022
c199751
Add test for local output
js-ts Aug 12, 2022
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
2 changes: 0 additions & 2 deletions cmd/bacalhau/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestApplySuite(t *testing.T) {
suite.Run(t, new(ApplySuite))
}


//before all the suite
func (suite *ApplySuite) SetupAllSuite() {

Expand Down Expand Up @@ -112,4 +111,3 @@ func (suite *ApplySuite) TestApplyYAML_GenericSubmit() {
}
}
}

88 changes: 54 additions & 34 deletions cmd/bacalhau/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/filecoin-project/bacalhau/pkg/executor"
"github.com/filecoin-project/bacalhau/pkg/ipfs"
pjob "github.com/filecoin-project/bacalhau/pkg/job"

"github.com/filecoin-project/bacalhau/pkg/local"
"github.com/filecoin-project/bacalhau/pkg/system"
"github.com/filecoin-project/bacalhau/pkg/verifier"
"github.com/rs/zerolog/log"
Expand All @@ -36,6 +36,7 @@ var jobCPU string
var jobMemory string
var jobGPU string
var skipSyntaxChecking bool
var isLocal bool
var waitForJobToFinishAndPrintOutput bool
var jobLabels []string

Expand Down Expand Up @@ -353,6 +354,11 @@ func init() { // nolint:gochecknoinits // Using init in cobra command is idomati
`Wait For Job To Finish And Print Output`,
)

dockerRunCmd.PersistentFlags().BoolVar(
&isLocal, "local", false,
`Run the job locally. Docker is required`,
)

// ipfs get wait time
dockerRunCmd.PersistentFlags().IntVarP(
&jobIpfsGetTimeOut, "gettimeout", "g", 10, //nolint: gomnd
Expand Down Expand Up @@ -454,47 +460,61 @@ var dockerRunCmd = &cobra.Command{
}
}

job, err := getAPIClient().Submit(ctx, spec, deal, nil)
if err != nil {
return err
}

states, err := getAPIClient().GetExecutionStates(ctx, job.ID)
if err != nil {
return err
}

cmd.Printf("%s\n", job.ID)
currentNodeID, _ := pjob.GetCurrentJobState(states)
nodeIds := []string{currentNodeID}

// TODO: #424 Should we refactor all this waiting out? I worry about putting this all here \
// feels like we're overloading the surface of the CLI command a lot.
if waitForJobToFinishAndPrintOutput {
err = WaitForJob(ctx, job.ID, job,
WaitForJobThrowErrors(job, []executor.JobStateType{
executor.JobStateCancelled,
executor.JobStateError,
}),
WaitForJobAllHaveState(nodeIds, executor.JobStateComplete),
)
if isLocal {
client, err := local.NewDockerClient()
if err != nil {
cmd.Printf("%t\n", local.IsInstalled(client))
return err
}
std, err := local.RunJobLocally(ctx, spec)
cmd.Printf("%v", std)

cidl := Get(job.ID, jobIpfsGetTimeOut, jobLocalOutput)

// TODO: #425 Can you explain what the below is doing? Please comment.
var cidv string
for cid := range cidl {
cidv = filepath.Join(jobLocalOutput, cid)
if err != nil {
return err
}
body, err := os.ReadFile(cidv + "/stdout")
} else {
job, err := getAPIClient().Submit(ctx, spec, deal, nil)
if err != nil {
return err
}
fmt.Println()
fmt.Println(string(body))

states, err := getAPIClient().GetExecutionStates(ctx, job.ID)
if err != nil {
return err
}

cmd.Printf("%s\n", job.ID)
currentNodeID, _ := pjob.GetCurrentJobState(states)
nodeIds := []string{currentNodeID}

// TODO: #424 Should we refactor all this waiting out? I worry about putting this all here \
// feels like we're overloading the surface of the CLI command a lot.
if waitForJobToFinishAndPrintOutput {
err = WaitForJob(ctx, job.ID, job,
WaitForJobThrowErrors(job, []executor.JobStateType{
executor.JobStateCancelled,
executor.JobStateError,
}),
WaitForJobAllHaveState(nodeIds, executor.JobStateComplete),
)
if err != nil {
return err
}

cidl := Get(job.ID, jobIpfsGetTimeOut, jobLocalOutput)

// TODO: #425 Can you explain what the below is doing? Please comment.
var cidv string
for cid := range cidl {
cidv = filepath.Join(jobLocalOutput, cid)
}
body, err := os.ReadFile(cidv + "/stdout")
if err != nil {
return err
}
fmt.Println()
fmt.Println(string(body))
}
}

return nil
Expand Down
15 changes: 15 additions & 0 deletions cmd/bacalhau/docker_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ func (suite *DockerRunSuite) TestRun_GenericSubmitWait() {
}
}

func (suite *DockerRunSuite) TestRun_GenericSubmitLocal() {
args := []string{"docker", "run", "ubuntu", "echo", "hello", "--local"}
expectedStdout := "hello"
done := capture()
_, _, err := ExecuteTestCobraCommand(suite.T(), suite.rootCmd, args...)
out, _ := done()

require.NoError(suite.T(), err)
trimmedStdout := strings.TrimSpace(string(out))
fmt.Println(trimmedStdout)

require.Equal(suite.T(), trimmedStdout, expectedStdout, "Expected %s as output, but got %s", expectedStdout, trimmedStdout)

}

func (suite *DockerRunSuite) TestRun_SubmitInputs() {
tests := []struct {
numberOfJobs int
Expand Down
29 changes: 29 additions & 0 deletions cmd/bacalhau/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bacalhau
import (
"bytes"
"fmt"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -102,6 +103,34 @@ func ReverseList(s []string) []string {
return s
}

//nolint:unused,deadcode
func capture() func() (string, error) {
r, w, err := os.Pipe()
if err != nil {
panic(err)
}

done := make(chan error, 1)

save := os.Stdout
os.Stdout = w

var buf strings.Builder

go func() {
_, err := io.Copy(&buf, r)
r.Close()
done <- err
}()

return func() (string, error) {
os.Stdout = save
w.Close()
err := <-done
return buf.String(), err
}
}

// func RandInt(i int) int {
// n, err := rand.Int(rand.Reader, big.NewInt(int64(i)))
// if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/miekg/dns v1.1.48 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
Expand All @@ -231,7 +231,7 @@ require (
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openzipkin/zipkin-go v0.4.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
Expand Down Expand Up @@ -289,6 +289,7 @@ require (
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,9 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
Expand Down Expand Up @@ -1375,8 +1376,9 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0=
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down Expand Up @@ -2040,8 +2042,9 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
Loading