From 87f995f9b3650c9178fdf9e58c53cc608d2d0b84 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Mon, 27 Nov 2023 12:30:48 +0000 Subject: [PATCH 1/3] lets see what this does --- .../kurtosis_instruction/tasks/run_python.go | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go index e4df70e945..f046267f53 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go @@ -3,7 +3,6 @@ package tasks import ( "context" "fmt" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/shared_utils" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/exec_result" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service_directory" @@ -23,8 +22,6 @@ import ( "github.com/kurtosis-tech/stacktrace" "github.com/xtgo/uuid" "go.starlark.net/starlark" - "io" - "os" "path" "strings" ) @@ -160,17 +157,6 @@ func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_arg } builtin.run = pythonScript.GoString() - compressedScript, compressedScriptMd5, scriptCompressionInterpretationErr := getCompressedPythonScriptForUpload(builtin.run) - if err != nil { - return nil, scriptCompressionInterpretationErr - } - defer compressedScript.Close() - uniqueFilesArtifactName := fmt.Sprintf(scriptArtifactFormat, builtin.name) - _, err = builtin.serviceNetwork.UploadFilesArtifact(compressedScript, compressedScriptMd5, uniqueFilesArtifactName) - if err != nil { - return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while storing the python script to disk") - } - if arguments.IsSet(PythonArgumentsArgName) { argsValue, err := builtin_argument.ExtractArgumentValue[*starlark.List](arguments, PythonArgumentsArgName) if err != nil { @@ -217,20 +203,11 @@ func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_arg if interpretationErr != nil { return nil, interpretationErr } - filesArtifactMountDirPaths[pythonWorkspace] = uniqueFilesArtifactName filesArtifactExpansion, interpretationErr = service_config.ConvertFilesArtifactsMounts(filesArtifactMountDirPaths, builtin.serviceNetwork) if interpretationErr != nil { return nil, interpretationErr } } - } else { - filesArtifactMountDirPaths := map[string]string{} - filesArtifactMountDirPaths[pythonWorkspace] = uniqueFilesArtifactName - var interpretationErr *startosis_errors.InterpretationError - filesArtifactExpansion, interpretationErr = service_config.ConvertFilesArtifactsMounts(filesArtifactMountDirPaths, builtin.serviceNetwork) - if interpretationErr != nil { - return nil, interpretationErr - } } // build a service config from image and files artifacts expansion. @@ -377,24 +354,7 @@ func getPythonCommandToRun(builtin *RunPythonCapabilities) (string, error) { pythonScriptAbsolutePath := path.Join(pythonWorkspace, pythonScriptFileName) if len(argumentsAsString) > 0 { - return fmt.Sprintf("python %s %s", pythonScriptAbsolutePath, argumentsAsString), nil + return fmt.Sprintf("python -c '%s' %s", builtin.run, argumentsAsString), nil } return fmt.Sprintf("python %s", pythonScriptAbsolutePath), nil } - -func getCompressedPythonScriptForUpload(pythonScript string) (io.ReadCloser, []byte, *startosis_errors.InterpretationError) { - temporaryPythonScriptDir, err := os.MkdirTemp(defaultTmpDir, temporaryPythonDirectoryPrefix) - defer os.Remove(temporaryPythonScriptDir) - if err != nil { - return nil, nil, startosis_errors.NewInterpretationError("an error occurred while creating a temporary folder to write the python script too") - } - pythonScriptFilePath := path.Join(temporaryPythonScriptDir, pythonScriptFileName) - if err = os.WriteFile(pythonScriptFilePath, []byte(pythonScript), pythonScriptReadPermission); err != nil { - return nil, nil, startosis_errors.NewInterpretationError("an error occurred while writing python script to disk") - } - compressed, _, contentMd5, err := shared_utils.CompressPath(pythonScriptFilePath, enforceMaxSizeLimit) - if err != nil { - return nil, nil, startosis_errors.NewInterpretationError("an error occurred while compressing the python script") - } - return compressed, contentMd5, nil -} From e0e4e342f0ee8659b07d5d627244a5223216a3ee Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Mon, 27 Nov 2023 12:42:44 +0000 Subject: [PATCH 2/3] fix bug --- .../startosis_engine/kurtosis_instruction/tasks/run_python.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go index f046267f53..c0818478b1 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go @@ -22,7 +22,6 @@ import ( "github.com/kurtosis-tech/stacktrace" "github.com/xtgo/uuid" "go.starlark.net/starlark" - "path" "strings" ) @@ -352,9 +351,8 @@ func getPythonCommandToRun(builtin *RunPythonCapabilities) (string, error) { } argumentsAsString := strings.Join(maybePythonArgumentsWithRuntimeValueReplaced, spaceDelimiter) - pythonScriptAbsolutePath := path.Join(pythonWorkspace, pythonScriptFileName) if len(argumentsAsString) > 0 { return fmt.Sprintf("python -c '%s' %s", builtin.run, argumentsAsString), nil } - return fmt.Sprintf("python %s", pythonScriptAbsolutePath), nil + return fmt.Sprintf("python -c '%s'", builtin.run), nil } From 384607c68f79ad361a0e785dba45542efe02bc6b Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Mon, 27 Nov 2023 12:47:06 +0000 Subject: [PATCH 3/3] cleanup unused constants --- .../kurtosis_instruction/tasks/run_python.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go index c0818478b1..0f16dccd5f 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go @@ -37,17 +37,7 @@ const ( pipInstallCmd = "pip install" - pythonScriptFileName = "main.py" - pythonWorkspace = "/tmp/python" - - defaultTmpDir = "" - pythonScriptReadPermission = 0644 - enforceMaxSizeLimit = true - temporaryPythonDirectoryPrefix = "run-python-*" - successfulPipRunExitCode = 0 - - scriptArtifactFormat = "%v-python-script" ) func NewRunPythonService(serviceNetwork service_network.ServiceNetwork, runtimeValueStore *runtime_value_store.RuntimeValueStore) *kurtosis_plan_instruction.KurtosisPlanInstruction {