Skip to content

Commit

Permalink
Better printing during inabox failure mode (#1101)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley authored Jan 14, 2025
1 parent 0f14d1c commit 0872d51
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions inabox/bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ function start_graph {
popd
./wait-for http://0.0.0.0:8000 -- echo "GraphQL up"

if [ $? -ne 0 ]; then
echo "Failed to start graph node"
exit 1
fi

echo "Graph node started ....."
}

Expand Down
10 changes: 5 additions & 5 deletions inabox/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (env *Config) RegisterBlobVersionAndRelays(ethClient common.EthClient) map[
// TODO: Supply the test path to the runner utility
func (env *Config) StartBinaries() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"start-detached"}, []string{})
err := execCmd("./bin.sh", []string{"start-detached"}, []string{}, true)

if err != nil {
log.Panicf("Failed to start binaries. Err: %s", err)
Expand All @@ -339,23 +339,23 @@ func (env *Config) StartBinaries() {
// TODO: Supply the test path to the runner utility
func (env *Config) StopBinaries() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"stop"}, []string{})
err := execCmd("./bin.sh", []string{"stop"}, []string{}, true)
if err != nil {
log.Panicf("Failed to stop binaries. Err: %s", err)
}
}

func (env *Config) StartAnvil() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"start-anvil"}, []string{})
err := execCmd("./bin.sh", []string{"start-anvil"}, []string{}, false) // printing output causes hang
if err != nil {
log.Panicf("Failed to start anvil. Err: %s", err)
}
}

func (env *Config) StopAnvil() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"stop-anvil"}, []string{})
err := execCmd("./bin.sh", []string{"stop-anvil"}, []string{}, true)
if err != nil {
log.Panicf("Failed to stop anvil. Err: %s", err)
}
Expand All @@ -381,7 +381,7 @@ func (env *Config) RunNodePluginBinary(operation string, operator OperatorVars)
"NODE_NUM_CONFIRMATIONS=0",
}

err := execCmd("./node-plugin.sh", []string{}, envVars)
err := execCmd("./node-plugin.sh", []string{}, envVars, true)

if err != nil {
log.Panicf("Failed to run node plugin. Err: %s", err)
Expand Down
6 changes: 5 additions & 1 deletion inabox/deploy/localstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func DeployResources(
changeDirectory(filepath.Join(rootPath, "inabox"))
if err := pool.Retry(func() error {
fmt.Println("Creating S3 bucket")
return execCmd("./create-s3-bucket.sh", []string{}, []string{fmt.Sprintf("AWS_URL=http://0.0.0.0:%s", localStackPort)})
return execCmd(
"./create-s3-bucket.sh",
[]string{},
[]string{fmt.Sprintf("AWS_URL=http://0.0.0.0:%s", localStackPort)},
true)
}); err != nil {
fmt.Println("Could not connect to docker:", err)
return err
Expand Down
4 changes: 2 additions & 2 deletions inabox/deploy/subgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ func (env *Config) updateSubgraph(updater subgraphUpdater, path string, startBlo

func (env *Config) StartGraphNode() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"start-graph"}, []string{})
err := execCmd("./bin.sh", []string{"start-graph"}, []string{}, true)
if err != nil {
log.Panicf("Failed to start graph node. Err: %s", err)
}
}

func (env *Config) StopGraphNode() {
changeDirectory(filepath.Join(env.rootPath, "inabox"))
err := execCmd("./bin.sh", []string{"stop-graph"}, []string{})
err := execCmd("./bin.sh", []string{"stop-graph"}, []string{}, true)
if err != nil {
log.Panicf("Failed to stop graph node. Err: %s", err)
}
Expand Down
11 changes: 6 additions & 5 deletions inabox/deploy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func CreateNewTestDirectory(templateName, rootPath string) (string, error) {
templatePath := filepath.Join(rootPath, fmt.Sprintf("inabox/templates/%s", templateName))
err = execCmd(
"cp",
[]string{templatePath, fmt.Sprintf("%s/config.yaml", testPath)}, []string{})
[]string{templatePath, fmt.Sprintf("%s/config.yaml", testPath)}, []string{}, true)
if err != nil {
return "", fmt.Errorf("failed to copy template to test directory: %s", err.Error())
}
Expand All @@ -297,17 +297,18 @@ func GetLatestTestDirectory(rootPath string) (string, error) {
return testname, nil
}

func execCmd(name string, args []string, envVars []string) error {
func execCmd(name string, args []string, envVars []string, print bool) error {
cmd := exec.Command(name, args...)
if len(envVars) > 0 {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, envVars...)
}
var out bytes.Buffer
var stderr bytes.Buffer
// TODO: When these are uncommented, the deployer sometimes fails to start anvil
// cmd.Stdout = &out
// cmd.Stderr = &stderr
if print {
cmd.Stdout = &out
cmd.Stderr = &stderr
}

err := cmd.Run()
if err != nil {
Expand Down

0 comments on commit 0872d51

Please sign in to comment.