Improved the image download mechanism for self-built apps onprem
This commit is contained in:
+46
-18
@@ -604,11 +604,27 @@ func getDockerImage(resp http.ResponseWriter, request *http.Request) {
|
||||
// return
|
||||
//}
|
||||
|
||||
body, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "Failed reading body"}`))
|
||||
return
|
||||
var err error
|
||||
body := []byte{}
|
||||
//log.Printf("IMAGE REQUEST BODY: %#v", request.Body)
|
||||
if request.Body == nil || request.Body == http.NoBody {
|
||||
// Check for the image query, otherwise we skip everything
|
||||
imageQuery := request.URL.Query().Get("image")
|
||||
if len(imageQuery) == 0 {
|
||||
resp.WriteHeader(400)
|
||||
resp.Write([]byte(`{"success": false, "reason": "No image query found"}`))
|
||||
return
|
||||
}
|
||||
|
||||
body = []byte(fmt.Sprintf(`{"name": "%s"}`, imageQuery))
|
||||
|
||||
} else {
|
||||
body, err = ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
resp.WriteHeader(400)
|
||||
resp.Write([]byte(`{"success": false, "reason": "Failed reading body"}`))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// This has to be done in a weird way because Datastore doesn't
|
||||
@@ -630,21 +646,24 @@ func getDockerImage(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
images, err := dockercli.ImageList(ctx, image.ListOptions{
|
||||
All: true,
|
||||
})
|
||||
|
||||
img := image.Summary{}
|
||||
tagFound := ""
|
||||
|
||||
img2 := image.Summary{}
|
||||
tagFound := ""
|
||||
tagFound2 := ""
|
||||
|
||||
alternativeNameSplit := strings.Split(version.Name, "/")
|
||||
alternativeName := version.Name
|
||||
if len(alternativeNameSplit) == 3 {
|
||||
alternativeName = strings.Join(alternativeNameSplit[1:3], "/")
|
||||
// Old way of doing it
|
||||
//alternativeNameSplit := strings.Split(version.Name, "/")
|
||||
//alternativeName := version.Name
|
||||
//if len(alternativeNameSplit) == 3 {
|
||||
// alternativeName = strings.Join(alternativeNameSplit[1:3], "/")
|
||||
//}
|
||||
|
||||
appname, baseAppname, appnameSplit2, err := shuffle.GetAppNameSplit(version)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed getting appname split: %s", err)
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "message": "Couldn't get the right docker image name"}`)))
|
||||
return
|
||||
}
|
||||
|
||||
if len(version.Name) == 0 {
|
||||
@@ -655,11 +674,20 @@ func getDockerImage(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Trying to download image: '%s'. Alt name: %#v", version.Name, alternativeName)
|
||||
log.Printf("[INFO] Trying to download image: '%s'. Appname: '%s'. BaseAppname: '%s', Split2: %s", version.Name, appname, baseAppname, appnameSplit2)
|
||||
|
||||
alternativeName := appname
|
||||
ctx := context.Background()
|
||||
images, err := dockercli.ImageList(ctx, image.ListOptions{
|
||||
All: true,
|
||||
})
|
||||
|
||||
for _, image := range images {
|
||||
for _, tag := range image.RepoTags {
|
||||
//log.Printf("[DEBUG] Tag: %s", tag)
|
||||
if strings.Contains(tag, "<none>") {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.ToLower(tag) == strings.ToLower(version.Name) {
|
||||
img = image
|
||||
tagFound = tag
|
||||
|
||||
@@ -20,7 +20,7 @@ require (
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/h2non/filetype v1.1.3
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shuffle/shuffle-shared v0.8.33
|
||||
github.com/shuffle/shuffle-shared v0.8.34
|
||||
golang.org/x/crypto v0.36.0
|
||||
google.golang.org/api v0.176.1
|
||||
google.golang.org/grpc v1.68.1
|
||||
|
||||
@@ -974,7 +974,7 @@ func deleteWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to list child workflows: %s", err)
|
||||
} else {
|
||||
log.Printf("\n\n[DEBUG] Found %d child workflows for workflow %s\n\n", len(childWorkflows), workflow.ID)
|
||||
//log.Printf("\n\n[DEBUG] Found %d child workflows for workflow %s\n\n", len(childWorkflows), workflow.ID)
|
||||
|
||||
// Find cookies and append them to request.Header to replicate current request as closely as possible
|
||||
for _, childWorkflow := range childWorkflows {
|
||||
|
||||
Reference in New Issue
Block a user