From 98d8a2c990db7f6ad9fc67053b3544df91b36d32 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Tue, 2 Sep 2025 15:13:01 +0530 Subject: [PATCH] [Fix] - app activation issue --- backend/go-app/docker.go | 22 ++++++++++++---------- backend/go-app/main.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/backend/go-app/docker.go b/backend/go-app/docker.go index b7ee7e6d..122f5847 100755 --- a/backend/go-app/docker.go +++ b/backend/go-app/docker.go @@ -57,14 +57,11 @@ func getParsedTar(tw *tar.Writer, baseDir, extra string) error { switch mode := fi.Mode(); { case mode.IsDir(): // do directory recursion - //log.Printf("DIR: %s", file) - - // Append "src" as extra here - filenamesplit := strings.Split(file, "/") + // Cross-platform path handling for tar entries + filenamesplit := strings.Split(filepath.ToSlash(file), "/") filename := fmt.Sprintf("%s%s/", extra, filenamesplit[len(filenamesplit)-1]) tmpExtra := fmt.Sprintf(filename) - //log.Printf("TmpExtra: %s", tmpExtra) err = getParsedTar(tw, file, tmpExtra) if err != nil { log.Printf("Directory parse issue: %s", err) @@ -86,9 +83,8 @@ func getParsedTar(tw *tar.Writer, baseDir, extra string) error { return err } - filenamesplit := strings.Split(file, "/") + filenamesplit := strings.Split(filepath.ToSlash(file), "/") filename := fmt.Sprintf("%s%s", extra, filenamesplit[len(filenamesplit)-1]) - //log.Printf("Filename: %s", filename) tarHeader := &tar.Header{ Name: filename, Size: int64(len(readFile)), @@ -486,16 +482,22 @@ func buildImage(tags []string, dockerfileLocation string) error { } log.Printf("[INFO] Docker Tags: %s", tags) - dockerfileSplit := strings.Split(dockerfileLocation, "/") + log.Printf("[DEBUG] Dockerfile location: %s", dockerfileLocation) + + // Convert to forward slashes for consistent handling across OS + normalizedPath := filepath.ToSlash(dockerfileLocation) + dockerfileSplit := strings.Split(normalizedPath, "/") // Create a buffer buf := new(bytes.Buffer) tw := tar.NewWriter(buf) defer tw.Close() + + // Use the directory part of the dockerfile path baseDir := strings.Join(dockerfileSplit[0:len(dockerfileSplit)-1], "/") - // Builds the entire folder into buf - err = getParsedTar(tw, baseDir, "") + // Builds the entire folder into buf using OS-specific path + err = getParsedTar(tw, filepath.FromSlash(baseDir), "") if err != nil { log.Printf("[ERROR] Tar issue during app build: %s", err) } diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 720ca901..79622f95 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -3326,6 +3326,35 @@ func buildSwaggerApp(resp http.ResponseWriter, body []byte, user shuffle.User, s log.Printf("[INFO] Successfully stitched ZIPFILE for %s", identifier) + // Copy baseline Dockerfile to build directory + dockerfileSource := "../app_gen/python-lib/baseline/Dockerfile" + dockerfileDestination := fmt.Sprintf("%s/Dockerfile", basePath) + + // Read and copy the baseline Dockerfile + dockerfileContent, err := ioutil.ReadFile(dockerfileSource) + if err != nil { + log.Printf("[ERROR] Failed to read baseline Dockerfile: %s", err) + resp.WriteHeader(500) + resp.Write([]byte(`{"success": false, "reason": "Failed to read baseline Dockerfile"}`)) + return + } + + err = ioutil.WriteFile(dockerfileDestination, dockerfileContent, 0644) + if err != nil { + log.Printf("[ERROR] Failed to copy Dockerfile to build directory: %s", err) + resp.WriteHeader(500) + resp.Write([]byte(`{"success": false, "reason": "Failed to copy Dockerfile"}`)) + return + } + + // Verify the Dockerfile was created + if _, err := os.Stat(dockerfileDestination); os.IsNotExist(err) { + log.Printf("[ERROR] Dockerfile does not exist at destination: %s", dockerfileDestination) + resp.WriteHeader(500) + resp.Write([]byte(`{"success": false, "reason": "Dockerfile was not created properly"}`)) + return + } + // 4. Build the image locally. // FIXME: Should be moved to a local docker registry dockerLocation := fmt.Sprintf("%s/Dockerfile", basePath)