Skip to content

Commit

Permalink
add docker build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Nov 24, 2020
1 parent ad9c489 commit 764f25b
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 222 deletions.
212 changes: 198 additions & 14 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion docs/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,18 @@ For Cancelled Error code, use range 800 to 850.
| DEPLOY_SUCCESS | 202 | Deploy Success |
| BUILD_PUSH_ACCESS_DENIED | 101 | Build error due to push access denied |
| BUILD_PROJECT_NOT_FOUND | 102 | Build error due to GCP project not found. |
| BUILD_DOCKER_DAEMON_NOT_RUNNING | 103 | |
| BUILD_DOCKER_DAEMON_NOT_RUNNING | 103 | Docker build error due to docker daemon not running |
| BUILD_USER_ERROR | 104 | Docker build error due to invalid dockerfile |
| BUILD_DOCKER_UNAVAILABLE | 105 | Build error due to docker not available |
| BUILD_DOCKER_UNAUTHORIZED | 106 | Docker build error due to user not authorized to perform the action |
| BUILD_DOCKER_SYSTEM_ERR | 107 | Docker system build error |
| BUILD_DOCKER_NOT_MODIFIED_ERR | 108 | Docker build error due to Docker build container is already in the desired state |
| BUILD_DOCKER_NOT_IMPLEMENTED_ERR | 109 | Docker build error indicating a feature not supported |
| BUILD_DOCKER_DATA_LOSS_ERR | 110 | Docker build error indicates that for given build, data was lost or there is data corruption |
| BUILD_DOCKER_FORBIDDEN_ERR | 111 | Docker build error indicates user is forbidden to perform the build or step/action. |
| BUILD_DOCKER_CONFLICT_ERR | 112 | Docker build error due to some internal error and docker container state conflicts with the requested action and can't be performed |
| BUILD_DOCKER_ERROR_NOT_FOUND | 113 | Docker build error indicates the requested object does not exist |
| BUILD_DOCKER_INVALID_PARAM_ERR | 114 | Docker build error indication invalid parameter sent to docker command |
| STATUSCHECK_IMAGE_PULL_ERR | 300 | Container image pull error |
| STATUSCHECK_CONTAINER_CREATING | 301 | Container creating error |
| STATUSCHECK_RUN_CONTAINER_ERR | 302 | Container run error |
Expand Down Expand Up @@ -825,6 +836,7 @@ For Cancelled Error code, use range 800 to 850.
| DEVINIT_UNKNOWN | 507 | Dev Init failed due to unknown reason |
| CLEANUP_UNKNOWN | 508 | Cleanup failed due to unknown reason |
| INIT_UNKNOWN | 510 | Initialization of the Skaffold session failed due to unknown reason(s) |
| BUILD_DOCKER_UNKNOWN | 511 | Build failed due to docker unknown error |
| SYNC_INIT_ERROR | 601 | File Sync Initialize failure |
| DEVINIT_REGISTER_BUILD_DEPS | 701 | Failed to configure watcher for build dependencies in dev loop |
| DEVINIT_REGISTER_TEST_DEPS | 702 | Failed to configure watcher for test dependencies in dev loop |
Expand All @@ -835,6 +847,8 @@ For Cancelled Error code, use range 800 to 850.
| STATUSCHECK_DEADLINE_EXCEEDED | 801 | Deadline for status check exceeded |
| BUILD_CANCELLED | 802 | Build Cancelled |
| DEPLOY_CANCELLED | 803 | Deploy cancelled due to user cancellation or one or more deployers failed. |
| BUILD_DOCKER_CANCELLED | 804 | Docker build cancelled. |
| BUILD_DOCKER_DEADLINE | 805 | Build error due to docker deadline was reached before the docker action completed |
| INIT_CREATE_TAGGER_ERROR | 901 | Skaffold was unable to create the configured tagger |
| INIT_MINIKUBE_PAUSED_ERROR | 902 | Skaffold was unable to start as Minikube appears to be paused |
| INIT_MINIKUBE_NOT_RUNNING_ERROR | 903 | Skaffold was unable to start as Minikube appears to be stopped |
Expand Down Expand Up @@ -863,6 +877,8 @@ Enum for Suggestion codes
| DOCKER_AUTH_CONFIGURE | 104 | Run docker auth configure |
| CHECK_GCLOUD_PROJECT | 105 | Verify Gcloud Project |
| CHECK_DOCKER_RUNNING | 106 | Check if docker is running |
| FIX_USER_BUILD_ERR | 107 | Fix User Build Error |
| DOCKER_BUILD_RETRY | 108 | Docker build internal error, try again |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STATUS | 202 | Check minikube status |
| CHECK_CONTAINER_LOGS | 301 | Container run error |
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
}

if err != nil {
return "", err
return "", newBuildError(err)
}

if b.pushImages {
Expand Down
94 changes: 94 additions & 0 deletions pkg/skaffold/build/docker/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright 2020 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package docker

import (
"errors"

"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/jsonmessage"

sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
"github.com/GoogleContainerTools/skaffold/proto"
)

func newBuildError(err error) error {
errU := errors.Unwrap(err)
if errU == nil {
return err
}

switch errU.(type) {
case *jsonmessage.JSONError:
return sErrors.NewError(
err,
proto.ActionableErr{
Message: err.Error(),
ErrCode: proto.StatusCode_BUILD_USER_ERROR,
Suggestions: []*proto.Suggestion{
{
SuggestionCode: proto.SuggestionCode_FIX_USER_BUILD_ERR,
Action: "Please fix the Dockerfile and try again.",
},
},
})
default:
return sErrors.NewError(
err,
proto.ActionableErr{
Message: errU.Error(),
ErrCode: getErrorCode(errU),
Suggestions: []*proto.Suggestion{
{
SuggestionCode: proto.SuggestionCode_DOCKER_BUILD_RETRY,
Action: "Docker build ran into internal error. Please retry.\nIf this keeps happening, please open an issue.",
},
},
})
}
}

func getErrorCode(err error) proto.StatusCode {
switch err.(type) {
case errdefs.ErrNotFound:
return proto.StatusCode_BUILD_DOCKER_ERROR_NOT_FOUND
case errdefs.ErrInvalidParameter:
return proto.StatusCode_BUILD_DOCKER_INVALID_PARAM_ERR
case errdefs.ErrConflict:
return proto.StatusCode_BUILD_DOCKER_CONFLICT_ERR
case errdefs.ErrCancelled:
return proto.StatusCode_BUILD_DOCKER_CANCELLED
case errdefs.ErrForbidden:
return proto.StatusCode_BUILD_DOCKER_FORBIDDEN_ERR
case errdefs.ErrDataLoss:
return proto.StatusCode_BUILD_DOCKER_DATA_LOSS_ERR
case errdefs.ErrDeadline:
return proto.StatusCode_BUILD_DOCKER_DEADLINE
case errdefs.ErrNotImplemented:
return proto.StatusCode_BUILD_DOCKER_NOT_IMPLEMENTED_ERR
case errdefs.ErrNotModified:
return proto.StatusCode_BUILD_DOCKER_NOT_MODIFIED_ERR
case errdefs.ErrSystem:
return proto.StatusCode_BUILD_DOCKER_SYSTEM_ERR
case errdefs.ErrUnauthorized:
return proto.StatusCode_BUILD_DOCKER_UNAUTHORIZED
case errdefs.ErrUnavailable:
return proto.StatusCode_BUILD_DOCKER_UNAVAILABLE
default:
return proto.StatusCode_BUILD_DOCKER_UNKNOWN
}
}
51 changes: 51 additions & 0 deletions pkg/skaffold/errors/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2020 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package errors

import (
"github.com/GoogleContainerTools/skaffold/proto"
)

type Error interface {
Error() string
StatusCode() proto.StatusCode
Suggestions() []*proto.Suggestion
}

type errDef struct {
err error
ae proto.ActionableErr
}

func (e errDef) Error() string {
return e.ae.Message
}

func (e errDef) StatusCode() proto.StatusCode {
return e.ae.ErrCode
}

func (e errDef) Suggestions() []*proto.Suggestion {
return e.ae.Suggestions
}

func NewError(err error, ae proto.ActionableErr) errDef {
return errDef{
err: err,
ae: ae,
}
}
9 changes: 9 additions & 0 deletions pkg/skaffold/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func ActionableErr(phase Phase, err error) *proto.ActionableErr {
}

func ShowAIError(err error) error {
switch t := err.(type) {
case Error:
return fmt.Errorf("%s. %s", t.Error(), concatSuggestions(t.Suggestions()))
}

var knownProblems = append(knownBuildProblems, knownDeployProblems...)
for _, v := range append(knownProblems, knownInitProblems...) {
if v.regexp.MatchString(err.Error()) {
Expand Down Expand Up @@ -100,6 +105,10 @@ func IsOldImageManifestProblem(err error) (string, bool) {
}

func getErrorCodeFromError(phase Phase, err error) (proto.StatusCode, []*proto.Suggestion) {
switch t := err.(type) {
case Error:
return t.StatusCode(), t.Suggestions()
}
if problems, ok := allErrors[phase]; ok {
for _, v := range problems {
if v.regexp.MatchString(err.Error()) {
Expand Down
Loading

0 comments on commit 764f25b

Please sign in to comment.