#373: Added basic fix to the Worker

This commit is contained in:
frikky
2021-05-18 10:52:10 +02:00
parent 0696febd52
commit 4c6c6ba9c5
4 changed files with 27 additions and 24 deletions
+1
View File
@@ -1,5 +1,6 @@
<integration>
<name>custom-shuffle</name>
<level>9</level>
<hook_url>http://<IP>:<PORT>/api/v1/hooks/webhook_<HOOK_ID></hook_url>
<alert_format>json</alert_format>
</integration>
+3 -1
View File
@@ -12,7 +12,9 @@ RUN go get github.com/docker/docker/api/types && \
go get github.com/gorilla/mux && \
go get github.com/patrickmn/go-cache && \
go get github.com/frikky/shuffle-shared && \
go get github.com/satori/go.uuid
go get github.com/satori/go.uuid && \
go get github.com/fsouza/go-dockerclient && \
go get google.golang.org/grpc/balancer/grpclb@v1.37.1
RUN go build
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker .
+2 -1
View File
@@ -13,7 +13,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/frikky/shuffle-shared v0.0.40
github.com/fsouza/go-dockerclient v1.7.2 // indirect
github.com/fsouza/go-dockerclient v1.7.2
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/mux v1.8.0
@@ -22,4 +22,5 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
google.golang.org/grpc v1.37.1 // indirect
)
+21 -22
View File
@@ -853,7 +853,8 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
appname = strings.Replace(appname, ".", "-", -1)
appversion = strings.Replace(appversion, ".", "-", -1)
image := fmt.Sprintf("%s:%s_%s", baseimagename, strings.ToLower(action.AppName), action.AppVersion)
parsedAppname := strings.Replace(strings.ToLower(action.AppName), " ", "-", -1)
image := fmt.Sprintf("%s:%s_%s", baseimagename, parsedAppname, action.AppVersion)
if strings.Contains(image, " ") {
image = strings.ReplaceAll(image, " ", "-")
}
@@ -957,14 +958,12 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
// Uses a few ways of getting / checking if an app is available
// 1. Try original with lowercase
// 2. Go to original
// 2. Go to original (no spaces)
// 3. Add remote repo location
// 4. Actually download last repo
images := []string{
image,
fmt.Sprintf("%s:%s_%s", baseimagename, action.AppName, action.AppVersion),
fmt.Sprintf("%s/%s:%s_%s", registryName, baseimagename, strings.ToLower(action.AppName), action.AppVersion),
fmt.Sprintf("%s:%s_%s", baseimagename, strings.Replace(action.AppName, " ", "-", -1), action.AppVersion),
fmt.Sprintf("%s/%s:%s_%s", registryName, baseimagename, parsedAppname, action.AppVersion),
}
// If cleanup is set, it should run for efficiency
@@ -973,26 +972,26 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
err = deployApp(dockercli, images[0], identifier, env, workflowExecution)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
log.Printf("[WARNING] Failed CLEANUP execution. Downloading image remotely.")
image = images[2]
reader, err := dockercli.ImagePull(context.Background(), image, pullOptions)
if err != nil {
log.Printf("[ERROR] Failed getting %s. The couldn't be find locally, AND is missing.", image)
shutdown(workflowExecution, action.ID, err.Error(), true)
log.Printf("[ERROR] Failed getting %s. Couldn't be find locally, AND is missing.", image)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
buildBuf := new(strings.Builder)
_, err = io.Copy(buildBuf, reader)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
if err != nil && !strings.Contains(fmt.Sprintf("Docker error: %s", err.Error()), "Conflict. The container name") {
log.Printf("[ERROR] Error in IO copy: %s", err)
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
} else {
if strings.Contains(buildBuf.String(), "errorDetail") {
log.Printf("[ERROR] Docker build:\n%s\nERROR ABOVE: Trying to pull tags from: %s", buildBuf.String(), image)
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
log.Printf("[INFO] Successfully downloaded %s", image)
@@ -1003,13 +1002,13 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
log.Printf("[ERROR] Failed deploying image for the FOURTH time. Aborting if the image doesn't exist")
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
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, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
}
}
@@ -1018,7 +1017,7 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
err = deployApp(dockercli, images[0], identifier, env, workflowExecution)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
// Trying to replace with lowercase to deploy again. This seems to work with Dockerhub well.
@@ -1031,7 +1030,7 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
err = deployApp(dockercli, image, identifier, env, workflowExecution)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
image = images[2]
@@ -1042,25 +1041,25 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
err = deployApp(dockercli, image, identifier, env, workflowExecution)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
log.Printf("[WARNING] Failed deploying image THREE TIMES. Attempting to download the latter as last resort.")
reader, err := dockercli.ImagePull(context.Background(), image, pullOptions)
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
log.Printf("[ERROR] Failed getting %s. The couldn't be find locally, AND is missing.", image)
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
buildBuf := new(strings.Builder)
_, err = io.Copy(buildBuf, reader)
if err != nil {
log.Printf("[ERROR] Error in IO copy: %s", err)
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
} else {
if strings.Contains(buildBuf.String(), "errorDetail") {
log.Printf("[ERROR] Docker build:\n%s\nERROR ABOVE: Trying to pull tags from: %s", buildBuf.String(), image)
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
log.Printf("[INFO] Successfully downloaded %s", image)
@@ -1070,13 +1069,13 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
if err != nil && !strings.Contains(err.Error(), "Conflict. The container name") {
log.Printf("[ERROR] Failed deploying image for the FOURTH time. Aborting if the image doesn't exist")
if strings.Contains(err.Error(), "exited prematurely") {
shutdown(workflowExecution, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
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, action.ID, err.Error(), true)
shutdown(workflowExecution, action.ID, fmt.Sprintf("Docker error: %s", err.Error()), true)
}
}
}