fixed backend code

This commit is contained in:
dhaval055
2023-10-09 17:57:34 +00:00
parent c7fc95831f
commit 6fbc916902
3 changed files with 57 additions and 61 deletions
+1 -3
View File
@@ -8,8 +8,6 @@ ADD ./go-app/main.go /app
ADD ./go-app/walkoff.go /app
ADD ./go-app/docker.go /app
ADD ./go-app/shuffle-shared /app/shuffle-shared
ADD ./go-app/go.mod /app
# Required files for code generation
@@ -43,4 +41,4 @@ COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certifica
WORKDIR /app
EXPOSE 5001
CMD ["./webapp"]
CMD ["./webapp"]
+54 -56
View File
@@ -463,72 +463,70 @@ func buildImage(tags []string, dockerfileFolder string) error {
}
} else {
//docker part here
ctx := context.Background()
client, err := client.NewEnvClient()
if err != nil {
log.Printf("Unable to create docker client: %s", err)
return err
}
// ctx := context.Background()
// client, err := client.NewEnvClient()
// if err != nil {
// log.Printf("Unable to create docker client: %s", err)
// return err
// }
log.Printf("[INFO] Docker Tags: %s", tags)
dockerfileSplit := strings.Split(dockerfileFolder, "/")
// log.Printf("[INFO] Docker Tags: %s", tags)
// dockerfileSplit := strings.Split(dockerfileFolder, "/")
// Create a buffer
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
defer tw.Close()
baseDir := strings.Join(dockerfileSplit[0:len(dockerfileSplit)-1], "/")
// // Create a buffer
// buf := new(bytes.Buffer)
// tw := tar.NewWriter(buf)
// defer tw.Close()
// baseDir := strings.Join(dockerfileSplit[0:len(dockerfileSplit)-1], "/")
// Builds the entire folder into buf
err = getParsedTar(tw, baseDir, "")
if err != nil {
log.Printf("Tar issue: %s", err)
}
// // Builds the entire folder into buf
// err = getParsedTar(tw, baseDir, "")
// if err != nil {
// log.Printf("Tar issue: %s", err)
// }
dockerFileTarReader := bytes.NewReader(buf.Bytes())
buildOptions := types.ImageBuildOptions{
Remove: true,
Tags: tags,
BuildArgs: map[string]*string{},
}
//NetworkMode: "host",
// dockerFileTarReader := bytes.NewReader(buf.Bytes())
// buildOptions := types.ImageBuildOptions{
// Remove: true,
// Tags: tags,
// BuildArgs: map[string]*string{},
// }
// //NetworkMode: "host",
httpProxy := os.Getenv("HTTP_PROXY")
if len(httpProxy) > 0 {
buildOptions.BuildArgs["HTTP_PROXY"] = &httpProxy
}
httpsProxy := os.Getenv("HTTPS_PROXY")
if len(httpProxy) > 0 {
buildOptions.BuildArgs["https_proxy"] = &httpsProxy
}
// httpProxy := os.Getenv("HTTP_PROXY")
// if len(httpProxy) > 0 {
// buildOptions.BuildArgs["HTTP_PROXY"] = &httpProxy
// }
// httpsProxy := os.Getenv("HTTPS_PROXY")
// if len(httpProxy) > 0 {
// buildOptions.BuildArgs["https_proxy"] = &httpsProxy
// }
// Build the actual image
imageBuildResponse, err := client.ImageBuild(
ctx,
dockerFileTarReader,
buildOptions,
)
// // Build the actual image
// imageBuildResponse, err := client.ImageBuild(
// ctx,
// dockerFileTarReader,
// buildOptions,
// )
if err != nil {
return err
}
// if err != nil {
// return err
// }
// // Read the STDOUT from the build process
// defer imageBuildResponse.Body.Close()
// 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, ",")))
// }
// }
// Read the STDOUT from the build process
defer imageBuildResponse.Body.Close()
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 -2
View File
@@ -1,6 +1,6 @@
module shuffle-shared
replace github.com/shuffle/shuffle-shared => /app/shuffle-shared
// replace github.com/shuffle/shuffle-shared => /app/shuffle-shared
go 1.19
@@ -19,7 +19,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/h2non/filetype v1.1.3
github.com/satori/go.uuid v1.2.0
github.com/shuffle/shuffle-shared v0.4.19
github.com/shuffle/shuffle-shared v0.4.50
golang.org/x/crypto v0.9.0
google.golang.org/api v0.125.0
google.golang.org/appengine v1.6.7