BUG: Docker build issue for old version workaround

This commit is contained in:
frikky
2020-12-19 14:21:39 +01:00
parent e38950e285
commit 2248e407f7
5 changed files with 70 additions and 18 deletions
+21 -4
View File
@@ -8,6 +8,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
@@ -235,7 +236,7 @@ func buildImageMemory(fs billy.Filesystem, tags []string, dockerfileFolder strin
buildOptions,
)
log.Printf("Response: %#v", imageBuildResponse.Body)
//log.Printf("Response: %#v", imageBuildResponse.Body)
//log.Printf("IMAGERESPONSE: %#v", imageBuildResponse.Body)
defer imageBuildResponse.Body.Close()
@@ -251,9 +252,12 @@ func buildImageMemory(fs billy.Filesystem, tags []string, dockerfileFolder strin
// This fixes some issues with older versions of Docker which can't build
// on their own ( <17.05 )
pullOptions := types.ImagePullOptions{}
canonicalName := fmt.Sprintf("registry.hub.docker.com")
downloaded := false
for _, image := range tags {
newImage := fmt.Sprintf("%s/%s", canonicalName, image)
// Is this ok? Not sure. Tags shouldn't be controlled here prolly.
image = strings.ToLower(image)
newImage := fmt.Sprintf("%s/%s", registryName, image)
log.Printf("[INFO] Pulling image %s", newImage)
reader, err := client.ImagePull(ctx, newImage, pullOptions)
if err != nil {
@@ -261,10 +265,17 @@ func buildImageMemory(fs billy.Filesystem, tags []string, dockerfileFolder strin
continue
}
// Attempt to retag the image to not contain registry...
//newBuf := buildBuf
downloaded = true
io.Copy(os.Stdout, reader)
log.Printf("[INFO] Successfully downloaded and built %s", newImage)
}
if !downloaded {
return errors.New(fmt.Sprintf("Failed to build / download images %s", strings.Join(tags, ",")))
}
//baseDockerName
}
}
@@ -331,9 +342,15 @@ func buildImage(tags []string, dockerfileFolder string) error {
// Read the STDOUT from the build process
defer imageBuildResponse.Body.Close()
_, err = io.Copy(os.Stdout, imageBuildResponse.Body)
buildBuf := new(strings.Builder)
_, err = io.Copy(buildBuf, imageBuildResponse.Body)
if err != nil {
return err
} else {
if strings.Contains(buildBuf.String(), "errorDetail") {
log.Printf("[ERROR] Docker build:\n%s\nERROR ABOVE: Trying to pull tags from: %s", buildBuf.String(), strings.Join(tags, "\n"))
return errors.New(fmt.Sprintf("Failed building %s. Check backend logs for details. Most likely means you have an old version of Docker.", strings.Join(tags, ",")))
}
}
return nil
+2 -1
View File
@@ -72,6 +72,7 @@ var gceProject = "shuffle"
var bucketName = "shuffler.appspot.com"
var baseAppPath = "/home/frikky/git/shaffuru/tmp/apps"
var baseDockerName = "frikky/shuffle"
var registryName = "registry.hub.docker.com"
//var syncUrl = "http://192.168.102.54:5002"
var syncUrl = "https://shuffler.io"
@@ -6484,7 +6485,7 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
dockerLocation := fmt.Sprintf("%s/Dockerfile", basePath)
log.Printf("Dockerfile: %s", dockerLocation)
versionName := fmt.Sprintf("%s_%s", strings.ReplaceAll(api.Name, " ", "-"), api.AppVersion)
versionName := fmt.Sprintf("%s_%s", strings.ToLower(strings.ReplaceAll(api.Name, " ", "-")), api.AppVersion)
dockerTags := []string{
fmt.Sprintf("%s:%s", baseDockerName, identifier),
fmt.Sprintf("%s:%s", baseDockerName, versionName),
+2 -2
View File
@@ -5599,7 +5599,7 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
newName = strings.ReplaceAll(newName, " ", "-")
tags := []string{
fmt.Sprintf("%s:%s_%s", baseDockerName, newName, workflowapp.AppVersion),
fmt.Sprintf("%s:%s_%s", baseDockerName, strings.ToLower(newName), workflowapp.AppVersion),
}
if len(allapps) == 0 {
@@ -5673,7 +5673,7 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
}
if len(appendParams) > 0 {
log.Printf("Appending %d params to the START of %s", len(appendParams), action.Name)
log.Printf("[AUTH] Appending %d params to the START of %s", len(appendParams), action.Name)
workflowapp.Actions[index].Parameters = append(appendParams, workflowapp.Actions[index].Parameters...)
}