Skip to content

Commit

Permalink
fix: use ~/.meshery directory for temporary files instead of working …
Browse files Browse the repository at this point in the history
…directory

Signed-off-by: Souvik Kar Mahapatra <[email protected]>
  • Loading branch information
souvikinator committed Jan 21, 2025
1 parent 10a1b2d commit 1b318f9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions utils/kubernetes/kompose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kompose

import (
"os"
"path/filepath"
"strconv"

"github.com/kubernetes/kompose/client"
Expand Down Expand Up @@ -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")
Expand All @@ -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,
}

Expand Down

0 comments on commit 1b318f9

Please sign in to comment.