Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# syntax=tonistiigi/dockerfile:runmount20181002

FROM golang:1.11-alpine AS build
# syntax=docker/dockerfile-upstream:experimental
FROM golang:1.12-alpine AS build
WORKDIR /go/src/github.com/tonistiigi/buildkit-pack
RUN apk add --no-cache file
RUN apk add --no-cache file git
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
CGO_ENABLED=0 go build -o /out/pack ./cmd/pack && file /out/pack | grep "statically linked"
GO111MODULE=on CGO_ENABLED=0 go build -o /out/pack ./cmd/pack && file /out/pack | grep "statically linked"

FROM scratch
COPY --from=build /out/pack /bin/pack
ENTRYPOINT ["/bin/pack"]
ENTRYPOINT ["/bin/pack"]
43 changes: 38 additions & 5 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/frontend/gateway/client"
gwpb "github.com/moby/buildkit/frontend/gateway/pb"
"github.com/moby/buildkit/solver/pb"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
Expand All @@ -16,13 +17,15 @@ import (
const (
keyStack = "stack"
LocalNameContext = "context"
InputNameManifest = "manifest"
buildArgPrefix = "build-arg:"
keyBuildpackOrder = "buildpackOrder"
keySkipDetect = "skipDetect"
)

func Build(ctx context.Context, c client.Client) (*client.Result, error) {
opts := c.BuildOpts().Opts
gwcaps := c.BuildOpts().Caps

// also accept build args from Moby
for k, v := range opts {
Expand All @@ -31,6 +34,39 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
}
}

var (
manifest llb.State
src llb.State
)

// Use frontend input instead of `llb.Local` if supported by the gateway capabilities.
if (&gwcaps).Supports(gwpb.CapFrontendInputs) == nil {
inputs, err := c.Inputs(ctx)
if err != nil {
return nil, err
}

inputManifest, ok := inputs[InputNameManifest]
if ok {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if either of these cases, if input is not found it should default to llb.Local. Even if CapFrontendInputs is supported.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hinshun looks like this needs addressing if you still want to get this merged

manifest = inputManifest
}

inputContext, ok := inputs[LocalNameContext]
if ok {
src = inputContext
}

} else {
manifest = llb.Local(LocalNameContext,
llb.SessionID(c.BuildOpts().SessionID),
llb.IncludePatterns([]string{"manifest.yml"}),
llb.SharedKeyHint("manifest.yml"),
llb.WithCustomName("load manifest.yml"),
)

src = llb.Local(LocalNameContext, llb.SessionID(c.BuildOpts().SessionID), llb.SharedKeyHint("pack-src"))
}

stack := "cflinuxfs2"
if v, ok := opts[keyStack]; ok {
stack = v
Expand All @@ -41,7 +77,7 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
return nil, err
}

m, err := readManifest(ctx, c)
m, err := readManifest(ctx, c, manifest)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -74,9 +110,6 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {

// TODO: read buildpacks and download directly

// TODO: git/http sources
src := llb.Local(LocalNameContext, llb.SessionID(c.BuildOpts().SessionID), llb.SharedKeyHint("pack-src"))

builderImage := llb.Image(buildName, llb.WithMetaResolver(c))

for k, v := range env {
Expand Down Expand Up @@ -126,7 +159,7 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {

var config []byte
eg.Go(func() error {
_, c, err := c.ResolveImageConfig(ctx, runName, client.ResolveImageConfigOpt{})
_, c, err := c.ResolveImageConfig(ctx, runName, llb.ResolveImageConfigOpt{})
if err != nil {
return err
}
Expand Down
18 changes: 12 additions & 6 deletions cmd/pack-cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ func newSolveOpt(clicontext *cli.Context, w io.WriteCloser) (*client.SolveOpt, e
// }

return &client.SolveOpt{
Exporter: "docker",
ExporterAttrs: map[string]string{
"name": clicontext.String("tag"),
Exports: []client.ExportEntry{
{
Type: client.ExporterDocker,
Attrs: map[string]string{
"name": clicontext.String("tag"),
},
Output: func(_ map[string]string) (io.WriteCloser, error) {
return w, nil
},
},
},
ExporterOutput: w,
LocalDirs: localDirs,
FrontendAttrs: frontendAttrs,
LocalDirs: localDirs,
FrontendAttrs: frontendAttrs,
}, nil
}

Expand Down
41 changes: 41 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module github.com/tonistiigi/buildkit-pack

go 1.12

require (
github.com/Microsoft/go-winio v0.4.14
github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50
github.com/containerd/containerd v1.4.0-0.20191014053712-acdcf13d5eaf
github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible
github.com/docker/docker v1.14.0-0.20190319215453-e7b5f7dbe98c
github.com/gogo/googleapis v1.1.0
github.com/gogo/protobuf v1.2.0
github.com/golang/protobuf v1.2.0
github.com/google/shlex v0.0.0-20150127133951-6f45313302b9
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/moby/buildkit v0.0.0-20181003224033-f07efb78e3f1
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/image-spec v1.0.1
github.com/opentracing/opentracing-go v0.0.0-20171003133519-1361b9cd60be
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.1
github.com/tonistiigi/fsutil v0.0.0-20191018213012-0f039a052ca1
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5
golang.org/x/net v0.0.0-20190522155817-f3200d17e092
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20190812073006-9eafafc0a87e
golang.org/x/text v0.3.0
golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8
google.golang.org/grpc v1.23.0
gopkg.in/yaml.v2 v2.2.2
)

replace github.com/moby/buildkit => github.com/hinshun/buildkit v0.0.0-20200124224350-99d18890d310

replace github.com/hashicorp/go-immutable-radix => github.com/tonistiigi/go-immutable-radix v0.0.0-20170803185627-826af9ccf0fe

replace github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305
Loading