[Fix] - app activation issue
This commit is contained in:
+12
-10
@@ -57,14 +57,11 @@ func getParsedTar(tw *tar.Writer, baseDir, extra string) error {
|
|||||||
switch mode := fi.Mode(); {
|
switch mode := fi.Mode(); {
|
||||||
case mode.IsDir():
|
case mode.IsDir():
|
||||||
// do directory recursion
|
// do directory recursion
|
||||||
//log.Printf("DIR: %s", file)
|
// Cross-platform path handling for tar entries
|
||||||
|
filenamesplit := strings.Split(filepath.ToSlash(file), "/")
|
||||||
// Append "src" as extra here
|
|
||||||
filenamesplit := strings.Split(file, "/")
|
|
||||||
filename := fmt.Sprintf("%s%s/", extra, filenamesplit[len(filenamesplit)-1])
|
filename := fmt.Sprintf("%s%s/", extra, filenamesplit[len(filenamesplit)-1])
|
||||||
|
|
||||||
tmpExtra := fmt.Sprintf(filename)
|
tmpExtra := fmt.Sprintf(filename)
|
||||||
//log.Printf("TmpExtra: %s", tmpExtra)
|
|
||||||
err = getParsedTar(tw, file, tmpExtra)
|
err = getParsedTar(tw, file, tmpExtra)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Directory parse issue: %s", err)
|
log.Printf("Directory parse issue: %s", err)
|
||||||
@@ -86,9 +83,8 @@ func getParsedTar(tw *tar.Writer, baseDir, extra string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
filenamesplit := strings.Split(file, "/")
|
filenamesplit := strings.Split(filepath.ToSlash(file), "/")
|
||||||
filename := fmt.Sprintf("%s%s", extra, filenamesplit[len(filenamesplit)-1])
|
filename := fmt.Sprintf("%s%s", extra, filenamesplit[len(filenamesplit)-1])
|
||||||
//log.Printf("Filename: %s", filename)
|
|
||||||
tarHeader := &tar.Header{
|
tarHeader := &tar.Header{
|
||||||
Name: filename,
|
Name: filename,
|
||||||
Size: int64(len(readFile)),
|
Size: int64(len(readFile)),
|
||||||
@@ -486,16 +482,22 @@ func buildImage(tags []string, dockerfileLocation string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[INFO] Docker Tags: %s", tags)
|
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
|
// Create a buffer
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
tw := tar.NewWriter(buf)
|
tw := tar.NewWriter(buf)
|
||||||
defer tw.Close()
|
defer tw.Close()
|
||||||
|
|
||||||
|
// Use the directory part of the dockerfile path
|
||||||
baseDir := strings.Join(dockerfileSplit[0:len(dockerfileSplit)-1], "/")
|
baseDir := strings.Join(dockerfileSplit[0:len(dockerfileSplit)-1], "/")
|
||||||
|
|
||||||
// Builds the entire folder into buf
|
// Builds the entire folder into buf using OS-specific path
|
||||||
err = getParsedTar(tw, baseDir, "")
|
err = getParsedTar(tw, filepath.FromSlash(baseDir), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERROR] Tar issue during app build: %s", err)
|
log.Printf("[ERROR] Tar issue during app build: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3326,6 +3326,35 @@ func buildSwaggerApp(resp http.ResponseWriter, body []byte, user shuffle.User, s
|
|||||||
|
|
||||||
log.Printf("[INFO] Successfully stitched ZIPFILE for %s", identifier)
|
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.
|
// 4. Build the image locally.
|
||||||
// FIXME: Should be moved to a local docker registry
|
// FIXME: Should be moved to a local docker registry
|
||||||
dockerLocation := fmt.Sprintf("%s/Dockerfile", basePath)
|
dockerLocation := fmt.Sprintf("%s/Dockerfile", basePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user