mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00

Removes gogo/protobuf from buildx and updates to a version of moby/buildkit where gogo is removed. This also changes how the proto files are generated. This is because newer versions of protobuf are more strict about name conflicts. If two files have the same name (even if they are relative paths) and are used in different protoc commands, they'll conflict in the registry. Since protobuf file generation doesn't work very well with `paths=source_relative`, this removes the `go:generate` expression and just relies on the dockerfile to perform the generation. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package build
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/docker/buildx/driver"
|
|
"github.com/docker/buildx/util/progress"
|
|
"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"
|
|
)
|
|
|
|
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 {
|
|
return "", err
|
|
}
|
|
var out string
|
|
ch, done := progress.NewChannel(pw)
|
|
defer func() { <-done }()
|
|
_, err = c.Build(ctx, client.SolveOpt{Internal: true}, "buildx", func(ctx context.Context, c gwclient.Client) (*gwclient.Result, error) {
|
|
def, err := llb.HTTP(url, llb.Filename("Dockerfile"), llb.WithCustomNamef("[internal] load %s", url)).Marshal(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res, err := c.Solve(ctx, gwclient.SolveRequest{
|
|
Definition: def.ToPB(),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ref, err := res.SingleRef()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
stat, err := ref.StatFile(ctx, gwclient.StatRequest{
|
|
Path: "Dockerfile",
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if proto.Size(stat) > 512*1024 {
|
|
return nil, errors.Errorf("Dockerfile %s bigger than allowed max size", url)
|
|
}
|
|
|
|
dt, err := ref.ReadFile(ctx, gwclient.ReadRequest{
|
|
Filename: "Dockerfile",
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dir, err := os.MkdirTemp("", "buildx")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "Dockerfile"), dt, 0600); err != nil {
|
|
return nil, err
|
|
}
|
|
out = dir
|
|
return nil, nil
|
|
}, ch)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return out, nil
|
|
}
|