-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for generating go module deps
This adds a new `Generate` field on `Source` which is a list of generator configs. Today the only type of generator we support is for go modules but we'll likely need to add support for other things, e.g. Rust cargo deps. Multiple geneator configs are allowed in the case of a source with multiple go modules defined in it. Signed-off-by: Brian Goff <[email protected]>
- Loading branch information
Showing
22 changed files
with
797 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package debug | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/dalec" | ||
"github.com/Azure/dalec/frontend" | ||
"github.com/moby/buildkit/client/llb" | ||
"github.com/moby/buildkit/frontend/gateway/client" | ||
gwclient "github.com/moby/buildkit/frontend/gateway/client" | ||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
const keyGomodWorker = "context:gomod-worker" | ||
|
||
// Gomods outputs all the gomodule dependencies for the spec | ||
func Gomods(ctx context.Context, client gwclient.Client) (*client.Result, error) { | ||
return frontend.BuildWithPlatform(ctx, client, func(ctx context.Context, client gwclient.Client, platform *ocispecs.Platform, spec *dalec.Spec, targetKey string) (gwclient.Reference, *dalec.DockerImageSpec, error) { | ||
sOpt, err := frontend.SourceOptFromClient(ctx, client) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
inputs, err := client.Inputs(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// Allow the client to override the worker image | ||
// This is useful for keeping pre-built worker image, especially for CI. | ||
worker, ok := inputs[keyGomodWorker] | ||
if !ok { | ||
worker = llb.Image("alpine:latest", llb.WithMetaResolver(client)). | ||
Run(llb.Shlex("apk add --no-cache go git ca-certificates patch")).Root() | ||
} | ||
|
||
st, err := spec.GomodDeps(sOpt, worker) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
def, err := st.Marshal(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
res, err := client.Solve(ctx, gwclient.SolveRequest{ | ||
Definition: def.ToPB(), | ||
}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
ref, err := res.SingleRef() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
return ref, nil, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.