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..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 @@ -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,9 +22,6 @@ import ( "github.com/kurtosis-tech/stacktrace" "github.com/xtgo/uuid" "go.starlark.net/starlark" - "io" - "os" - "path" "strings" ) @@ -41,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 { @@ -160,17 +146,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 +192,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. @@ -375,26 +341,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 %s %s", pythonScriptAbsolutePath, 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 fmt.Sprintf("python -c '%s' %s", builtin.run, argumentsAsString), nil } - return compressed, contentMd5, nil + return fmt.Sprintf("python -c '%s'", builtin.run), nil }