Skip to content

Commit

Permalink
more explicit error message for docker buildx context error
Browse files Browse the repository at this point in the history
  • Loading branch information
tcurdt authored and caarlos0 committed Nov 4, 2023
1 parent cb656a3 commit 49f3973
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/pipe/docker/docker.go
Expand Up @@ -235,6 +235,9 @@ files in that dir:
Previous error:
%w`, tmp, strings.Join(files, "\n "), err)
}
if isBuildxContextError(err.Error()) {
return fmt.Errorf(`docker buildx not set to default context\nPlease switch with 'docker context use default'\nLearn more at https://goreleaser.com/errors/docker-build`)
}
return err
}

Expand Down Expand Up @@ -262,6 +265,10 @@ func isFileNotFoundError(out string) bool {
strings.Contains(out, ": not found")
}

func isBuildxContextError(out string) bool {
return strings.Contains(out, "buildx to switch to context")
}

func processImageTemplates(ctx *context.Context, docker config.Docker) ([]string, error) {
// nolint:prealloc
var images []string
Expand Down
8 changes: 8 additions & 0 deletions www/docs/errors/docker-build.md
Expand Up @@ -17,6 +17,14 @@ its root, so you can just `COPY binaryname /bin/binaryname` and etc.

Bellow you can find some **don'ts** as well as what you should **do**.

## `use docker --context=default buildx to switch to context "default"`

The "default" context is a built-in context in "docker buildx", and it is automatically created. This context typically points to the local Docker environment and is used by default for building images. It has to be active for `goreleaser` to build images with "buildx".

You can switch to the default context using `docker context use default`.

This change should be persistant.

### Don't

Build the binary again.
Expand Down

0 comments on commit 49f3973

Please sign in to comment.