BUG: Docker build issue for old version workaround
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -16,8 +16,8 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
build: ./backend
|
||||
image: ghcr.io/frikky/shuffle-backend:0.8.42
|
||||
#build: ./backend
|
||||
image: ghcr.io/frikky/shuffle-backend:0.8.43
|
||||
container_name: shuffle-backend
|
||||
hostname: ${BACKEND_HOSTNAME}
|
||||
# Here for debugging:
|
||||
@@ -53,8 +53,8 @@ services:
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- SHUFFLE_APP_SDK_VERSION=0.8.0
|
||||
- SHUFFLE_WORKER_VERSION=0.8.0
|
||||
- SHUFFLE_APP_SDK_VERSION=0.8.3
|
||||
- SHUFFLE_WORKER_VERSION=0.8.3
|
||||
- ORG_ID=${ORG_ID}
|
||||
- ENVIRONMENT_NAME=${ENVIRONMENT_NAME}
|
||||
- BASE_URL=http://${OUTER_HOSTNAME}:${BACKEND_PORT}
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
var environment = os.Getenv("ENVIRONMENT_NAME")
|
||||
var baseUrl = os.Getenv("BASE_URL")
|
||||
var baseimagename = "frikky/shuffle"
|
||||
var registryName = "registry.hub.docker.com"
|
||||
var fallbackName = "shuffle-orborus"
|
||||
var sleepTime = 2
|
||||
|
||||
var containerId string
|
||||
@@ -34,6 +36,11 @@ func getThisContainerId() string {
|
||||
out, err := exec.Command("bash", "-c", cmd).Output()
|
||||
if err == nil {
|
||||
id = strings.TrimSpace(string(out))
|
||||
|
||||
log.Printf("Checking if %s is in %s", ".scope", string(out))
|
||||
if strings.Contains(string(out), ".scope") {
|
||||
id = fallbackName
|
||||
}
|
||||
}
|
||||
|
||||
return id
|
||||
@@ -42,7 +49,7 @@ func getThisContainerId() string {
|
||||
func init() {
|
||||
containerId = getThisContainerId()
|
||||
if len(containerId) == 0 {
|
||||
log.Printf("[ERROR] No container ID found.")
|
||||
log.Printf("[ERROR] No container ID found. Not running containerized?")
|
||||
} else {
|
||||
log.Printf("[INFO] Found container ID: %s", containerId)
|
||||
}
|
||||
@@ -854,11 +861,17 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Container error: %s", err)
|
||||
log.Printf("Container CREATE error: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{})
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to start container in environment %s: %s", environment, err)
|
||||
//shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{})
|
||||
log.Printf("[INFO] Container %s is created", cont.ID)
|
||||
return nil
|
||||
}
|
||||
@@ -1357,14 +1370,35 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
|
||||
log.Printf("Skipping FULL_EXECUTION because size is larger than %d", maxSize)
|
||||
}
|
||||
|
||||
// Try original -> Go to lowercase
|
||||
err = deployApp(dockercli, image, identifier, env)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed deploying %s from image %s: %s", identifier, image, err)
|
||||
// Trying to replace with lowercase to deploy again. This seems to work with Dockerhub well.
|
||||
// FIXME: Should try to remotely download directly if this persists.
|
||||
image = fmt.Sprintf("%s:%s_%s", baseimagename, strings.ToLower(action.AppName), action.AppVersion)
|
||||
if strings.Contains(image, " ") {
|
||||
image = strings.ReplaceAll(image, " ", "-")
|
||||
}
|
||||
|
||||
err = deployApp(dockercli, image, identifier, env)
|
||||
if err != nil {
|
||||
image = fmt.Sprintf("%s/%s:%s_%s", registryName, baseimagename, strings.ToLower(action.AppName), action.AppVersion)
|
||||
if strings.Contains(image, " ") {
|
||||
image = strings.ReplaceAll(image, " ", "-")
|
||||
}
|
||||
|
||||
err = deployApp(dockercli, image, identifier, env)
|
||||
if err != nil {
|
||||
|
||||
log.Printf("[ERROR] Failed deploying image THRICE. Aborting if the image doesn't exist")
|
||||
if strings.Contains(err.Error(), "No such image") {
|
||||
//log.Printf("[WARNING] Failed deploying %s from image %s: %s", identifier, image, err)
|
||||
log.Printf("[ERROR] Image doesn't exist. Shutting down")
|
||||
shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Adding visited (3): %s", action.Label)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user