Skip to content

Commit

Permalink
build: raise maximum size limit for dockerfile and fix size check
Browse files Browse the repository at this point in the history
Raise the maximum size limit for the dockerfile and correct the size
check. The size check was intended to use the size attribute from the
file stat, but the original gogo version confused the `Size()`
method (which returned the size of the proto message) with the `Size`
attribute (which was named `Size_`).

During the conversion, we noticed the mistake but kept the incorrect
behavior for the sake of keeping the conversion simple.

This also raises the maximum limit because 512 kB is likely a bit too
conservative. The limit has been raised to 2 MB and the limit has been
included in the error message.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
  • Loading branch information
jsternberg committed Oct 3, 2024
1 parent 1db8f67 commit d7de22c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions build/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (

"github.com/docker/buildx/driver"
"github.com/docker/buildx/util/progress"
"github.com/docker/go-units"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
gwclient "github.com/moby/buildkit/frontend/gateway/client"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)

const maxDockerfileSize = 2 * 1024 * 1024 // 2 MB

func createTempDockerfileFromURL(ctx context.Context, d *driver.DriverHandle, url string, pw progress.Writer) (string, error) {
c, err := driver.Boot(ctx, ctx, d, pw)
if err != nil {
Expand Down Expand Up @@ -44,8 +46,8 @@ func createTempDockerfileFromURL(ctx context.Context, d *driver.DriverHandle, ur
if err != nil {
return nil, err
}
if proto.Size(stat) > 512*1024 {
return nil, errors.Errorf("Dockerfile %s bigger than allowed max size", url)
if stat.Size > maxDockerfileSize {
return nil, errors.Errorf("Dockerfile %s bigger than allowed max size (%s)", url, units.HumanSize(maxDockerfileSize))
}

dt, err := ref.ReadFile(ctx, gwclient.ReadRequest{
Expand Down

0 comments on commit d7de22c

Please sign in to comment.