Skip to content

Commit

Permalink
fix: Fix starlark scripts for CLI commands (#824)
Browse files Browse the repository at this point in the history
Closes #823
Closes #817

Changelog picked up from commits here:

fix: Fix starlark command for CLI rendertemplate
fix: Fix starlark command for CLI storeservice

Co-authored-by: Victor Colombo <victor.colombo@kurtosistech.com>
  • Loading branch information
victorcolombo and victorcolombo committed Jan 9, 2023
1 parent 3196e6c commit f8542dd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ parameters:
startosis-test-script-file-relative-path:
type: string
default: "internal_testsuites/starlark/ci_tests/startosis_simple_script.star"
rendertemplate-cli-test-template-relative-path:
type: string
default: "internal_testsuites/resources/render_template_cli_test/template.txt"
rendertemplate-cli-test-data-json-relative-path:
type: string
default: "internal_testsuites/resources/render_template_cli_test/data.json"



Expand Down Expand Up @@ -705,6 +711,10 @@ jobs:
- run: "${KURTOSIS_BINPATH} service add test-enclave test1 httpd --ports http=80"
- run: "${KURTOSIS_BINPATH} service add test-enclave test2 httpd --ports http=80"

# File commands
- run: "${KURTOSIS_BINPATH} files rendertemplate test-enclave << pipeline.parameters.rendertemplate-cli-test-template-relative-path >> << pipeline.parameters.rendertemplate-cli-test-data-json-relative-path >> ./rendered"
- run: "${KURTOSIS_BINPATH} files storeservice test-enclave test1 /usr/local/apache2/conf/httpd.conf"

# Module inside an enclave
- run: "${KURTOSIS_BINPATH} enclave ls"
- run: "${KURTOSIS_BINPATH} enclave inspect test-enclave"
Expand Down
4 changes: 2 additions & 2 deletions cli/cli/commands/files/rendertemplate/rendertemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
engineClientCtxKey = "engine-client"

starlarkTemplate = `
def run(args):
render_templates(config = {
def run(plan, args):
plan.render_templates(config = {
args.file_name: struct(
template = args.template,
data = args.template_data,
Expand Down
35 changes: 31 additions & 4 deletions cli/cli/commands/files/storeservice/storeservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const (
engineClientCtxKey = "engine-client"

starlarkTemplate = `
def run(args):
store_service_files(
def run(plan, args):
plan.store_service_files(
service_id = args.service_id,
src = args.src
)
Expand Down Expand Up @@ -114,12 +114,39 @@ func run(

func storeServiceFileStarlarkCommand(ctx context.Context, enclaveCtx *enclaves.EnclaveContext, serviceId services.ServiceID, filePath string, enclaveId enclaves.EnclaveID) (*enclaves.StarlarkRunResult, error) {
runResult, err := enclaveCtx.RunStarlarkScriptBlocking(ctx, starlarkTemplate, fmt.Sprintf(`{"service_id": "%s", "src": "%s"}`, serviceId, filePath), false)
if len(runResult.ValidationErrors) > 0 || runResult.ExecutionError != nil || len(runResult.ValidationErrors) > 0 {
if err != nil {
return nil, stacktrace.Propagate(
err,
"An unexpected error occurred running command for copying content from filepath '%v' in user service with ID '%v' to enclave '%v'. This is a bug in Kurtosis, please report.",
filePath,
serviceId,
enclaveId)
}
if runResult.InterpretationError != nil {
return nil, stacktrace.NewError(
"An error occurred interpreting command for copying content from filepath '%v' in user service with ID '%v' to enclave '%v': %s\nThis is a bug in Kurtosis, please report.",
filePath,
serviceId,
enclaveId,
runResult.InterpretationError.GetErrorMessage(),
)
}
if len(runResult.ValidationErrors) > 0 {
return nil, stacktrace.NewError(
"An error occurred validating command for copying content from filepath '%v' in user service with ID '%v' to enclave '%v': %v",
filePath,
serviceId,
enclaveId,
runResult.ValidationErrors,
)
}
if runResult.ExecutionError != nil {
return nil, stacktrace.NewError(
"An error occurred running Starlark script for copying content from filepath '%v' in user service with ID '%v' to enclave '%v'",
"An error occurred executing command for copying content from filepath '%v' in user service with ID '%v' to enclave '%v': %s",
filePath,
serviceId,
enclaveId,
runResult.ExecutionError.GetErrorMessage(),
)
}
return runResult, err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Name" : "Stranger",
"Answer": 6,
"Numbers": [1, 2, 3],
"UnixTimeStamp": 1257894000,
"LargeFloat": 1231231243.43,
"Alive": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{.Name}}. The sum of {{.Numbers}} is {{.Answer}}. My favorite moment in history {{.UnixTimeStamp}}. My favorite number {{.LargeFloat}}. Am I Alive? {{.Alive}}

0 comments on commit f8542dd

Please sign in to comment.