mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
feat: improve docker errors (#3080)
* feat: improve docker errors Adding an error page with some more info to help debug issues. Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: forgot return Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: missing err Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
444218f51d
commit
ea7a696fab
@ -127,7 +127,10 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
return process(ctx, docker, artifacts.List())
|
||||
})
|
||||
}
|
||||
return g.Wait()
|
||||
if err := g.Wait(); err != nil {
|
||||
return fmt.Errorf("docker build failed: %w\nLearn more at https://goreleaser.com/errors/docker-build\n", err) // nolint:revive
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.Artifact) error {
|
||||
|
60
www/docs/errors/docker-build.md
Normal file
60
www/docs/errors/docker-build.md
Normal file
@ -0,0 +1,60 @@
|
||||
# Docker build failures
|
||||
|
||||
## `COPY failed: file not found in build context`
|
||||
|
||||
This usually happens when trying to build the binary again from source code in
|
||||
the Docker image build process.
|
||||
|
||||
The way GoReleaser works, the correct binary for the platform you're building
|
||||
should be already available, so you don't need to build it again and can still
|
||||
reuse the `Dockefile`.
|
||||
|
||||
Another common misconception is trying to copy the binary as if the context is
|
||||
the repository root.
|
||||
It's not.
|
||||
It's always a new temporary build context with the artifacts you can use in
|
||||
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**.
|
||||
|
||||
### Don't
|
||||
|
||||
Build the binary again.
|
||||
|
||||
```dockerfile
|
||||
FROM golang AS builder
|
||||
WORKDIR /app
|
||||
COPY cmd ./cmd
|
||||
COPY go.mod ./
|
||||
COPY *.go ./
|
||||
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o app .
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /app/app /app
|
||||
ENTRYPOINT ["/app"]
|
||||
```
|
||||
|
||||
### Don't
|
||||
|
||||
Copy from the `dist` folder.
|
||||
|
||||
```dockerfile
|
||||
FROM scratch
|
||||
COPY /dist/app_linux_amd64/app /app
|
||||
ENTRYPOINT ["/app"]
|
||||
```
|
||||
|
||||
### Do
|
||||
|
||||
Copy the clean file names from the root.
|
||||
|
||||
```dockerfile
|
||||
FROM scratch
|
||||
COPY app /app
|
||||
ENTRYPOINT ["/app"]
|
||||
```
|
||||
|
||||
!!! tip
|
||||
If you still want your users to be able to `docker build` without an extra
|
||||
step, you can have a `Dockerfile` just for GoReleaser, for example, a
|
||||
`goreleaser.dockefile`.
|
@ -134,6 +134,7 @@ nav:
|
||||
- Common errors:
|
||||
- errors/dirty.md
|
||||
- errors/multiple-tokens.md
|
||||
- errors/docker-build.md
|
||||
- errors/no-main.md
|
||||
- errors/resource-not-accessible-by-integration.md
|
||||
- errors/no-history.md
|
||||
|
Loading…
x
Reference in New Issue
Block a user