Skip to content

Commit

Permalink
Bump lifecycle module and use imgutil
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Joyce <djoyce@pivotal.io>
Signed-off-by: Andrew Meyer <ameyer@pivotal.io>
  • Loading branch information
Danny Joyce authored and ameyer-pivotal committed Apr 25, 2019
1 parent 0b2b8b9 commit 68f3f13
Show file tree
Hide file tree
Showing 126 changed files with 11,074 additions and 6,276 deletions.
10 changes: 5 additions & 5 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"strings"

"github.com/buildpack/lifecycle/image"
"github.com/buildpack/imgutil"
"github.com/docker/docker/api/types"
"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"
Expand Down Expand Up @@ -98,10 +98,10 @@ func (c *Client) processBuilderName(builderName string) (name.Reference, error)
return nil, errors.New("builder is a required parameter if the client has no default builder")
}
}
return name.ParseReference(builderName, name.WeakValidation);
return name.ParseReference(builderName, name.WeakValidation)
}

func (c *Client) processBuilderImage(img image.Image) (*builder.Builder, error) {
func (c *Client) processBuilderImage(img imgutil.Image) (*builder.Builder, error) {
builder, err := builder.GetBuilder(img)
if err != nil {
return nil, err
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *Client) processRunImageName(runImage, targetRegistry string, builderSta
return runImageName
}

func (c *Client) validateRunImage(context context.Context, name string, noPull bool, publish bool, expectedStack string) (image.Image, error) {
func (c *Client) validateRunImage(context context.Context, name string, noPull bool, publish bool, expectedStack string) (imgutil.Image, error) {
img, err := c.imageFetcher.Fetch(context, name, !publish, !noPull)
if err != nil {
return nil, err
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Client) parseBuildpack(bp string) (string, string) {
return parts[0], "latest"
}

func (c *Client) createEphemeralBuilder(rawBuilderImage image.Image, env map[string]string, group builder.GroupMetadata, buildpacks []buildpack.Buildpack) (*builder.Builder, error) {
func (c *Client) createEphemeralBuilder(rawBuilderImage imgutil.Image, env map[string]string, group builder.GroupMetadata, buildpacks []buildpack.Buildpack) (*builder.Builder, error) {
origBuilderName := rawBuilderImage.Name()
bldr, err := builder.New(rawBuilderImage, fmt.Sprintf("pack.local/builder/%x:latest", randString(10)))
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions build/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
"testing"
"time"

"github.com/buildpack/lifecycle/image"
"github.com/buildpack/imgutil"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/fatih/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack/builder"
"github.com/buildpack/pack/archive"
"github.com/buildpack/pack/build"
"github.com/buildpack/pack/builder"
"github.com/buildpack/pack/logging"
h "github.com/buildpack/pack/testhelpers"
)
Expand Down Expand Up @@ -62,9 +62,7 @@ func testLifecycle(t *testing.T, when spec.G, it spec.S) {
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
h.AssertNil(t, err)
subject = build.NewLifecycle(docker, logger)
imageFactory, err := image.NewFactory()
h.AssertNil(t, err)
builderImage, err := imageFactory.NewLocal(repoName)
builderImage, err := imgutil.NewLocalImage(repoName, docker)
h.AssertNil(t, err)
bldr, err := builder.GetBuilder(builderImage)
h.AssertNil(t, err)
Expand Down
21 changes: 11 additions & 10 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"testing"
"time"

"github.com/buildpack/lifecycle/image/fakes"
"github.com/buildpack/imgutil/fakes"
"github.com/docker/docker/client"
"github.com/fatih/color"
"github.com/sclevine/spec"
Expand Down Expand Up @@ -74,15 +74,15 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
)
fakeImageFetcher.LocalImages[defaultBuilderImage.Name()] = defaultBuilderImage

fakeDefaultRunImage = fakes.NewImage(t, "default/run", "", "")
fakeDefaultRunImage = fakes.NewImage("default/run", "", "")
h.AssertNil(t, fakeDefaultRunImage.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.LocalImages[fakeDefaultRunImage.Name()] = fakeDefaultRunImage

fakeMirror1 = fakes.NewImage(t, "registry1.example.com/run/mirror", "", "")
fakeMirror1 = fakes.NewImage("registry1.example.com/run/mirror", "", "")
h.AssertNil(t, fakeMirror1.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.LocalImages[fakeMirror1.Name()] = fakeMirror1

fakeMirror2 = fakes.NewImage(t, "registry2.example.com/run/mirror", "", "")
fakeMirror2 = fakes.NewImage("registry2.example.com/run/mirror", "", "")
h.AssertNil(t, fakeMirror2.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.LocalImages[fakeMirror2.Name()] = fakeMirror2
var err error
Expand Down Expand Up @@ -225,7 +225,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
})
fakeImageFetcher.LocalImages[customBuilderImage.Name()] = customBuilderImage

fakeRunImage = fakes.NewImage(t, "some/run", "", "")
fakeRunImage = fakes.NewImage("some/run", "", "")
h.AssertNil(t, fakeRunImage.SetLabel("io.buildpacks.stack.id", "some.stack.id"))
fakeImageFetcher.LocalImages[fakeRunImage.Name()] = fakeRunImage
})
Expand All @@ -251,7 +251,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
)

it.Before(func() {
fakeRunImage = fakes.NewImage(t, "custom/run", "", "")
fakeRunImage = fakes.NewImage("custom/run", "", "")
fakeImageFetcher.LocalImages[fakeRunImage.Name()] = fakeRunImage
})

Expand Down Expand Up @@ -331,11 +331,11 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
},
}

fakeLocalMirror = fakes.NewImage(t, "local/mirror", "", "")
fakeLocalMirror = fakes.NewImage("local/mirror", "", "")
h.AssertNil(t, fakeLocalMirror.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.LocalImages[fakeLocalMirror.Name()] = fakeLocalMirror

fakeLocalMirror1 = fakes.NewImage(t, "registry1.example.com/local/mirror", "", "")
fakeLocalMirror1 = fakes.NewImage("registry1.example.com/local/mirror", "", "")
h.AssertNil(t, fakeLocalMirror1.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.LocalImages[fakeLocalMirror1.Name()] = fakeLocalMirror1
})
Expand Down Expand Up @@ -471,7 +471,8 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
"key2": "value2",
},
}))
layerTar := defaultBuilderImage.FindLayerWithPath("/platform/env")
layerTar, err := defaultBuilderImage.FindLayerWithPath("/platform/env")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/platform/env/key1", `value1`)
assertTarFileContents(t, layerTar, "/platform/env/key2", `value2`)
})
Expand All @@ -482,7 +483,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
var remoteRunImage *fakes.Image

it.Before(func() {
remoteRunImage = fakes.NewImage(t, "default/run", "", "")
remoteRunImage = fakes.NewImage("default/run", "", "")
h.AssertNil(t, remoteRunImage.SetLabel("io.buildpacks.stack.id", defaultBuilderStackID))
fakeImageFetcher.RemoteImages[remoteRunImage.Name()] = remoteRunImage
})
Expand Down
10 changes: 5 additions & 5 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/buildpack/lifecycle/image"
"github.com/buildpack/imgutil"
"github.com/pkg/errors"

"github.com/buildpack/pack/archive"
Expand All @@ -30,15 +30,15 @@ const (
)

type Builder struct {
image image.Image
image imgutil.Image
buildpacks []buildpack.Buildpack
metadata Metadata
env map[string]string
UID, GID int
StackID string
}

func GetBuilder(img image.Image) (*Builder, error) {
func GetBuilder(img imgutil.Image) (*Builder, error) {
uid, gid, err := userAndGroupIDs(img)
if err != nil {
return nil, err
Expand Down Expand Up @@ -88,7 +88,7 @@ func (b *Builder) GetStackInfo() stack.Metadata {
return b.metadata.Stack
}

func New(img image.Image, name string) (*Builder, error) {
func New(img imgutil.Image, name string) (*Builder, error) {
uid, gid, err := userAndGroupIDs(img)
if err != nil {
return nil, err
Expand Down Expand Up @@ -240,7 +240,7 @@ func (b *Builder) Save() error {
return err
}

func userAndGroupIDs(img image.Image) (int, int, error) {
func userAndGroupIDs(img imgutil.Image) (int, int, error) {
sUID, err := img.Env(envUID)
if err != nil {
return 0, 0, errors.Wrap(err, "reading builder env variables")
Expand Down
30 changes: 18 additions & 12 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package builder_test
import (
"archive/tar"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/buildpack/lifecycle/image/fakes"
"github.com/buildpack/imgutil/fakes"
"github.com/fatih/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
Expand All @@ -33,7 +32,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
)

it.Before(func() {
baseImage = fakes.NewImage(t, "base/image", "", "")
baseImage = fakes.NewImage("base/image", "", "")
})

it.After(func() {
Expand Down Expand Up @@ -143,25 +142,29 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
})

it("adds the buildpack as an image layer", func() {
layerTar := baseImage.FindLayerWithPath("/buildpacks/some-buildpack-id/some-buildpack-version")
layerTar, err := baseImage.FindLayerWithPath("/buildpacks/some-buildpack-id/some-buildpack-version")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/buildpacks/some-buildpack-id/some-buildpack-version/buildpack-file", "buildpack-contents")

layerTar = baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id/other-buildpack-version")
layerTar, err = baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id/other-buildpack-version")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/buildpacks/other-buildpack-id/other-buildpack-version/buildpack-file", "buildpack-contents")
})

it("adds a symlink to the buildpack layer if latest is true", func() {
layerTar := baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id")
fmt.Println("LAYER TAR", layerTar)
layerTar, err := baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id")
h.AssertNil(t, err)
assertTarFileSymlink(t, layerTar, "/buildpacks/other-buildpack-id/latest", "/buildpacks/other-buildpack-id/other-buildpack-version")
assertTarFileOwner(t, layerTar, "/buildpacks/other-buildpack-id/latest", 1234, 4321)
})

it("adds the buildpack contents with the correct uid and gid", func() {
layerTar := baseImage.FindLayerWithPath("/buildpacks/some-buildpack-id/some-buildpack-version")
layerTar, err := baseImage.FindLayerWithPath("/buildpacks/some-buildpack-id/some-buildpack-version")
h.AssertNil(t, err)
assertTarFileOwner(t, layerTar, "/buildpacks/some-buildpack-id/some-buildpack-version/buildpack-file", 1234, 4321)

layerTar = baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id/other-buildpack-version")
layerTar, err = baseImage.FindLayerWithPath("/buildpacks/other-buildpack-id/other-buildpack-version")
h.AssertNil(t, err)
assertTarFileOwner(t, layerTar, "/buildpacks/other-buildpack-id/other-buildpack-version/buildpack-file", 1234, 4321)
})

Expand Down Expand Up @@ -275,7 +278,8 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
})

it("adds the order.toml to the image", func() {
layerTar := baseImage.FindLayerWithPath("/buildpacks/order.toml")
layerTar, err := baseImage.FindLayerWithPath("/buildpacks/order.toml")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/buildpacks/order.toml", `[[groups]]
[[groups.buildpacks]]
Expand Down Expand Up @@ -368,7 +372,8 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
})

it("adds the stack.toml to the image", func() {
layerTar := baseImage.FindLayerWithPath("/buildpacks/stack.toml")
layerTar, err := baseImage.FindLayerWithPath("/buildpacks/stack.toml")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/buildpacks/stack.toml", `[run-image]
image = "some/run"
mirrors = ["some/mirror", "other/mirror"]
Expand Down Expand Up @@ -398,7 +403,8 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
})

it("adds the env vars as files to the image", func() {
layerTar := baseImage.FindLayerWithPath("/platform/env")
layerTar, err := baseImage.FindLayerWithPath("/platform/env")
h.AssertNil(t, err)
assertTarFileContents(t, layerTar, "/platform/env/SOME_KEY", `some-val`)
assertTarFileContents(t, layerTar, "/platform/env/OTHER_KEY", `other-val`)
})
Expand Down
9 changes: 2 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ func DefaultClient(config *config.Config, logger *logging.Logger) (*Client, erro
return nil, err
}

imageFetcher, err := image.NewFetcher(logger, dockerClient)
if err != nil {
return nil, err
}

return &Client{
config: config,
logger: logger,
imageFetcher: imageFetcher,
imageFetcher: image.NewFetcher(logger, dockerClient),
buildpackFetcher: buildpack.NewFetcher(logger, config.Path()),
lifecycle: build.NewLifecycle(dockerClient, logger),
docker: dockerClient,
}, nil
}
}
4 changes: 2 additions & 2 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"runtime"
"testing"

"github.com/buildpack/lifecycle/image/fakes"
"github.com/buildpack/imgutil/fakes"
"github.com/fatih/color"
"github.com/golang/mock/gomock"
"github.com/sclevine/spec"
Expand Down Expand Up @@ -48,7 +48,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
mockImageFetcher = mocks.NewMockImageFetcher(mockController)
mockBPFetcher = mocks.NewMockBuildpackFetcher(mockController)

fakeBuildImage = fakes.NewImage(t, "some/build-image", "", "")
fakeBuildImage = fakes.NewImage("some/build-image", "", "")
h.AssertNil(t, fakeBuildImage.SetLabel("io.buildpacks.stack.id", "some.stack.id"))
h.AssertNil(t, fakeBuildImage.SetEnv("CNB_USER_ID", "1234"))
h.AssertNil(t, fakeBuildImage.SetEnv("CNB_GROUP_ID", "4321"))
Expand Down
12 changes: 3 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@ module github.com/buildpack/pack

require (
github.com/BurntSushi/toml v0.3.1
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/buildpack/lifecycle v0.1.1-0.20190417162324-d5a3c2de9ca1
github.com/buildpack/imgutil v0.0.0-20190425152312-609d2e9be7ee
github.com/buildpack/lifecycle v0.1.1-0.20190425153938-c98efaecd3c0
github.com/dgodd/dockerdial v1.0.1
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v0.7.3-0.20190307005417-54dddadc7d5d
github.com/docker/go-connections v0.4.0
github.com/fatih/color v1.7.0
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.0 // indirect
github.com/google/go-cmp v0.2.0
github.com/google/go-containerregistry v0.0.0-20190306174256-678f6c51f585
github.com/gorilla/mux v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/onsi/gomega v1.5.0
github.com/pkg/errors v0.8.1
github.com/sclevine/spec v1.2.0
github.com/sirupsen/logrus v1.3.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 // indirect
golang.org/x/sys v0.0.0-20190306220723-b294cbcfc56d // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190306222511-6e86cb5d2f12 // indirect
)
Loading

0 comments on commit 68f3f13

Please sign in to comment.