From 1b318f93fb07f566ad543ab53ee89d2259231e50 Mon Sep 17 00:00:00 2001 From: Souvik Kar Mahapatra Date: Tue, 21 Jan 2025 23:50:16 +0530 Subject: [PATCH] fix: use ~/.meshery directory for temporary files instead of working directory Signed-off-by: Souvik Kar Mahapatra --- utils/kubernetes/kompose/convert.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/utils/kubernetes/kompose/convert.go b/utils/kubernetes/kompose/convert.go index f85c4ca2..86e73664 100644 --- a/utils/kubernetes/kompose/convert.go +++ b/utils/kubernetes/kompose/convert.go @@ -2,6 +2,7 @@ package kompose import ( "os" + "path/filepath" "strconv" "github.com/kubernetes/kompose/client" @@ -30,11 +31,21 @@ func IsManifestADockerCompose(manifest []byte, schemaURL string) error { // converts a given docker-compose file into kubernetes manifests // expects a validated docker-compose file func Convert(dockerCompose DockerComposeFile) (string, error) { - err := utils.CreateFile(dockerCompose, "temp.data", "./") + // Get user's home directory + homeDir, err := os.UserHomeDir() if err != nil { return "", ErrCvrtKompose(err) } + // Construct path to .meshery directory + mesheryDir := filepath.Join(homeDir, ".meshery") + tempFilePath := filepath.Join(mesheryDir, "temp.data") + resultFilePath := filepath.Join(mesheryDir, "result.yaml") + + if err := utils.CreateFile(dockerCompose, "temp.data", mesheryDir); err != nil { + return "", ErrCvrtKompose(err) + } + defer func() { os.Remove("temp.data") os.Remove("result.yaml") @@ -52,8 +63,8 @@ func Convert(dockerCompose DockerComposeFile) (string, error) { } ConvertOpt := client.ConvertOptions{ - InputFiles: []string{"temp.data"}, - OutFile: "result.yaml", + InputFiles: []string{tempFilePath}, + OutFile: resultFilePath, GenerateNetworkPolicies: true, }