Skip to content

Commit

Permalink
fix exec cmd list
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Feb 29, 2024
1 parent 56d9331 commit 323ac97
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
25 changes: 17 additions & 8 deletions core/server/api_container/server/startosis_engine/plan.yml
@@ -1,13 +1,22 @@
packageId: github.com/kurtosis-tech/plan-yaml-prac
services:
- uuid: 1
name: database
name: db
image:
name: postgres:latest
- uuid: 2
name: tedi
image:
name: ubuntu:latest
name: postgres:alpine
envVars:
- key: DB_URL
value: '{{ kurtosis.1.ip_address }}'
- key: POSTGRES_PASSWORD
value: tedi
- key: POSTGRES_DB
value: tedi
- key: POSTGRES_USER
value: tedi
tasks:
- uuid: 2
taskType: exec
command:
- echo
- Hello, world
serviceName: db
acceptableCodes:
- 156
Expand Up @@ -82,7 +82,7 @@ type Task struct {
Uuid int `yaml:"uuid,omitempty"` // done
Name string `yaml:"name,omitempty"` // done
TaskType TaskType `yaml:"taskType,omitempty"` // done
RunCmd string `yaml:"command,omitempty"` // done
RunCmd []string `yaml:"command,omitempty"` // done
Image string `yaml:"image,omitempty"` // done
Files []*FileMount `yaml:"files,omitempty"` // done
Store []*FilesArtifact `yaml:"store,omitempty"` // done
Expand Down
Expand Up @@ -421,7 +421,7 @@ func (pyg *PlanYamlGeneratorImpl) updatePlanYamlFromRunSh(runShInstruction *inst
if err != nil {
return startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", tasks.RunArgName)
}
task.RunCmd = runCommand.GoString()
task.RunCmd = []string{runCommand.GoString()}

var image string
if arguments.IsSet(tasks.ImageNameArgName) {
Expand Down Expand Up @@ -550,7 +550,7 @@ func (pyg *PlanYamlGeneratorImpl) updatePlanYamlFromRunPython(runPythonInstructi
if err != nil {
return startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", tasks.RunArgName)
}
task.RunCmd = runCommand.GoString()
task.RunCmd = []string{runCommand.GoString()}

var image string
if arguments.IsSet(tasks.ImageNameArgName) {
Expand Down Expand Up @@ -747,7 +747,20 @@ func (pyg *PlanYamlGeneratorImpl) updatePlanYamlFromExec(execInstruction *instru
if interpretationErr != nil {
return interpretationErr
}
task.RunCmd = commandStarlarkList.String()
// Convert Starlark list to Go slice
var cmdList []string
iter := commandStarlarkList.Iterate()
defer iter.Done()
var x starlark.Value
for iter.Next(&x) {
if i, ok := x.(starlark.String); ok {
cmdList = append(cmdList, i.GoString())
} else {
// Handle the case if the element is not an integer
fmt.Println("Non-string element found in Starlark list")
}
}
task.RunCmd = cmdList

acceptableCodes := []int64{0}
if arguments.IsSet(exec.AcceptableCodesArgName) {
Expand Down
Expand Up @@ -137,23 +137,24 @@ CMD ["node", "app.js"]
relativePathToMainFile := "main.star"

serializedScript := `def run(plan, args):
database = plan.add_service(
name="database",
config=ServiceConfig(
image="postgres:latest",
)
)
plan.add_service(
name="tedi",
name="db",
config=ServiceConfig(
image="ubuntu:latest",
env_vars={
"DB_URL": database.ip_address
},
image="postgres:alpine",
env_vars = {
"POSTGRES_DB": "tedi",
"POSTGRES_USER": "tedi",
"POSTGRES_PASSWORD": "tedi",
}
)
)
result = plan.exec(
service_name = "db",
recipe = ExecRecipe(command = ["echo", "Hello, world"]),
acceptable_codes=[156],
)
plan.print(result)
`
serializedJsonParams := "{}"
_, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), packageId, mainFunctionName, noPackageReplaceOptions, relativePathToMainFile, serializedScript, serializedJsonParams, defaultNonBlockingMode, emptyEnclaveComponents, emptyInstructionsPlanMask)
Expand Down

0 comments on commit 323ac97

Please sign in to comment.