diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 272bc5199..1cbda3c15 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -56,7 +56,7 @@ const ( ) var ( - dockerCli *client.Client + dockerCli client.CommonAPIClient registryConfig *h.TestRegistryConfig suiteManager *SuiteManager ) @@ -1481,7 +1481,7 @@ func createPackage(t *testing.T, configDir, tmpDir, packPath string) string { return packageImageName } -func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string) error { +func createStack(t *testing.T, dockerCli client.CommonAPIClient, runImageMirror string) error { t.Helper() t.Log("creating stack images...") @@ -1503,7 +1503,7 @@ func createStack(t *testing.T, dockerCli *client.Client, runImageMirror string) return nil } -func createStackImage(dockerCli *client.Client, repoName string, dir string) error { +func createStackImage(dockerCli client.CommonAPIClient, repoName string, dir string) error { ctx := context.Background() buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1) @@ -1661,7 +1661,7 @@ func terminateAtStep(t *testing.T, cmd *exec.Cmd, buf *bytes.Buffer, pattern str } } -func imageLabel(t *testing.T, dockerCli *client.Client, repoName, labelName string) string { +func imageLabel(t *testing.T, dockerCli client.CommonAPIClient, repoName, labelName string) string { t.Helper() inspect, _, err := dockerCli.ImageInspectWithRaw(context.Background(), repoName) h.AssertNil(t, err) diff --git a/client.go b/client.go index ad5ee068d..53e6c47d4 100644 --- a/client.go +++ b/client.go @@ -40,7 +40,7 @@ type Client struct { imageFetcher ImageFetcher downloader Downloader lifecycle Lifecycle - docker *dockerClient.Client + docker dockerClient.CommonAPIClient imageFactory ImageFactory } @@ -84,7 +84,7 @@ func WithCacheDir(path string) ClientOption { } // WithDockerClient supply your own docker client. -func WithDockerClient(docker *dockerClient.Client) ClientOption { +func WithDockerClient(docker dockerClient.CommonAPIClient) ClientOption { return func(c *Client) { c.docker = docker } diff --git a/go.mod b/go.mod index ea14c8603..14815f37e 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/Masterminds/semver v1.4.2 github.com/apex/log v1.1.2-0.20190827100214-baa5455d1012 - github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b + github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1 github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3 github.com/dgodd/dockerdial v1.0.1 github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7 diff --git a/go.sum b/go.sum index 4b745f320..f33e87ae4 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b h1:SDsB0hJtURA+5i5vIjLntzRNPEqdoz6q+0MShCWdctw= github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b/go.mod h1:E3lXJcNXcRefJQAHW5rqboonet+jtOml4qImbJhYGAo= +github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1 h1:1+v3XHezNuXCf7YWW77U8go0gYBmr4BbnSZyV0PYa80= +github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1/go.mod h1:E3lXJcNXcRefJQAHW5rqboonet+jtOml4qImbJhYGAo= github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3 h1:15zYyFmNbrtx5MmyVEKVgY2/eearqEqGJXLCjmvUo58= github.com/buildpacks/lifecycle v0.5.1-0.20191217221752-3b74c943b7b3/go.mod h1:ZIuIs9B6tjAW4dthhltKVyEUlhRfFWWix9eqoInMGX4= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/internal/build/build.go b/internal/build/build.go index 713b0c8f5..a9d7df9b8 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -25,7 +25,7 @@ var ( type Lifecycle struct { builder *builder.Builder logger logging.Logger - docker *client.Client + docker client.CommonAPIClient appPath string appOnce *sync.Once httpProxy string @@ -46,7 +46,7 @@ func init() { rand.Seed(time.Now().UTC().UnixNano()) } -func NewLifecycle(docker *client.Client, logger logging.Logger) *Lifecycle { +func NewLifecycle(docker client.CommonAPIClient, logger logging.Logger) *Lifecycle { return &Lifecycle{logger: logger, docker: docker} } diff --git a/internal/build/phase.go b/internal/build/phase.go index 0e8c3cd44..0a038eb88 100644 --- a/internal/build/phase.go +++ b/internal/build/phase.go @@ -23,7 +23,7 @@ import ( type Phase struct { name string logger logging.Logger - docker *client.Client + docker client.CommonAPIClient ctrConf *dcontainer.Config hostConf *dcontainer.HostConfig ctr dcontainer.ContainerCreateCreatedBody diff --git a/internal/build/phase_test.go b/internal/build/phase_test.go index 8cb7aee6a..d2828d538 100644 --- a/internal/build/phase_test.go +++ b/internal/build/phase_test.go @@ -28,7 +28,7 @@ import ( var ( repoName string - dockerCli *client.Client + dockerCli client.CommonAPIClient ) func TestPhase(t *testing.T) { @@ -56,7 +56,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) { var ( subject *build.Lifecycle outBuf, errBuf bytes.Buffer - docker *client.Client + docker client.CommonAPIClient ) it.Before(func() { @@ -333,7 +333,7 @@ func assertRunSucceeds(t *testing.T, phase *build.Phase, outBuf *bytes.Buffer, e phase.Cleanup() } -func CreateFakeLifecycle(appDir string, docker *client.Client, logger logging.Logger) (*build.Lifecycle, error) { +func CreateFakeLifecycle(appDir string, docker client.CommonAPIClient, logger logging.Logger) (*build.Lifecycle, error) { subject := build.NewLifecycle(docker, logger) builderImage, err := local.NewImage(repoName, docker, local.FromBaseImage(repoName)) if err != nil { diff --git a/internal/cache/image_cache.go b/internal/cache/image_cache.go index ec85baab3..187ad4858 100644 --- a/internal/cache/image_cache.go +++ b/internal/cache/image_cache.go @@ -11,11 +11,11 @@ import ( ) type ImageCache struct { - docker *client.Client + docker client.CommonAPIClient image string } -func NewImageCache(imageRef name.Reference, dockerClient *client.Client) *ImageCache { +func NewImageCache(imageRef name.Reference, dockerClient client.CommonAPIClient) *ImageCache { sum := sha256.Sum256([]byte(imageRef.Name())) return &ImageCache{ image: fmt.Sprintf("pack-cache-%x", sum[:6]), diff --git a/internal/cache/image_cache_test.go b/internal/cache/image_cache_test.go index 292e919f8..13f24cf1a 100644 --- a/internal/cache/image_cache_test.go +++ b/internal/cache/image_cache_test.go @@ -30,7 +30,7 @@ func TestImageCache(t *testing.T) { func testImageCache(t *testing.T, when spec.G, it spec.S) { when("#NewImageCache", func() { - var dockerClient *client.Client + var dockerClient client.CommonAPIClient it.Before(func() { var err error @@ -100,7 +100,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) { when("#Clear", func() { var ( imageName string - dockerClient *client.Client + dockerClient client.CommonAPIClient subject *cache.ImageCache ctx context.Context ) diff --git a/internal/cache/volume_cache.go b/internal/cache/volume_cache.go index f12391f70..9cc1893cc 100644 --- a/internal/cache/volume_cache.go +++ b/internal/cache/volume_cache.go @@ -10,11 +10,11 @@ import ( ) type VolumeCache struct { - docker *client.Client + docker client.CommonAPIClient volume string } -func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient *client.Client) *VolumeCache { +func NewVolumeCache(imageRef name.Reference, suffix string, dockerClient client.CommonAPIClient) *VolumeCache { sum := sha256.Sum256([]byte(imageRef.Name())) return &VolumeCache{ volume: fmt.Sprintf("pack-cache-%x.%s", sum[:6], suffix), diff --git a/internal/cache/volume_cache_test.go b/internal/cache/volume_cache_test.go index 94534bbe4..2238133e5 100644 --- a/internal/cache/volume_cache_test.go +++ b/internal/cache/volume_cache_test.go @@ -30,7 +30,7 @@ func TestVolumeCache(t *testing.T) { func testCache(t *testing.T, when spec.G, it spec.S) { when("#NewVolumeCache", func() { - var dockerClient *client.Client + var dockerClient client.CommonAPIClient it.Before(func() { var err error @@ -108,7 +108,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { when("#Clear", func() { var ( volumeName string - dockerClient *client.Client + dockerClient client.CommonAPIClient subject *cache.VolumeCache ctx context.Context ) diff --git a/internal/container/run.go b/internal/container/run.go index e615f04ba..218776a4c 100644 --- a/internal/container/run.go +++ b/internal/container/run.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" ) -func Run(ctx context.Context, docker *client.Client, ctrID string, out, errOut io.Writer) error { +func Run(ctx context.Context, docker client.CommonAPIClient, ctrID string, out, errOut io.Writer) error { bodyChan, errChan := docker.ContainerWait(ctx, ctrID, dcontainer.WaitConditionNextExit) if err := docker.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}); err != nil { diff --git a/internal/image/factory.go b/internal/image/factory.go index dbf3b377c..e31892a46 100644 --- a/internal/image/factory.go +++ b/internal/image/factory.go @@ -9,11 +9,11 @@ import ( ) type DefaultImageFactory struct { - dockerClient *client.Client + dockerClient client.CommonAPIClient keychain authn.Keychain } -func NewFactory(dockerClient *client.Client, keychain authn.Keychain) *DefaultImageFactory { +func NewFactory(dockerClient client.CommonAPIClient, keychain authn.Keychain) *DefaultImageFactory { return &DefaultImageFactory{ dockerClient: dockerClient, keychain: keychain, diff --git a/internal/image/fetcher.go b/internal/image/fetcher.go index 3ec4b667c..2538c2889 100644 --- a/internal/image/fetcher.go +++ b/internal/image/fetcher.go @@ -22,11 +22,11 @@ import ( ) type Fetcher struct { - docker *client.Client + docker client.CommonAPIClient logger logging.Logger } -func NewFetcher(logger logging.Logger, docker *client.Client) *Fetcher { +func NewFetcher(logger logging.Logger, docker client.CommonAPIClient) *Fetcher { return &Fetcher{ logger: logger, docker: docker, diff --git a/internal/image/fetcher_test.go b/internal/image/fetcher_test.go index 1f888b324..cdf855d1f 100644 --- a/internal/image/fetcher_test.go +++ b/internal/image/fetcher_test.go @@ -19,7 +19,7 @@ import ( h "github.com/buildpacks/pack/testhelpers" ) -var docker *client.Client +var docker client.CommonAPIClient var registryConfig *h.TestRegistryConfig func TestFetcher(t *testing.T) { diff --git a/testhelpers/testhelpers.go b/testhelpers/testhelpers.go index 930140ab6..8708e6448 100644 --- a/testhelpers/testhelpers.go +++ b/testhelpers/testhelpers.go @@ -174,11 +174,11 @@ func hasMatches(actual, exp string) bool { return len(matches) > 0 } -var dockerCliVal *client.Client +var dockerCliVal client.CommonAPIClient var dockerCliOnce sync.Once var dockerCliErr error -func dockerCli(t *testing.T) *client.Client { +func dockerCli(t *testing.T) client.CommonAPIClient { dockerCliOnce.Do(func() { dockerCliVal, dockerCliErr = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38")) }) @@ -236,7 +236,7 @@ func Eventually(t *testing.T, test func() bool, every time.Duration, timeout tim } } -func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile string) { +func CreateImage(t *testing.T, dockerCli client.CommonAPIClient, repoName, dockerFile string) { t.Helper() buildContext, err := archive.CreateSingleFileTarReader("Dockerfile", dockerFile) @@ -254,7 +254,7 @@ func CreateImage(t *testing.T, dockerCli *client.Client, repoName, dockerFile st AssertNil(t, errors.Wrapf(err, "building image %s", style.Symbol(repoName))) } -func CreateImageFromDir(t *testing.T, dockerCli *client.Client, repoName string, dir string) { +func CreateImageFromDir(t *testing.T, dockerCli client.CommonAPIClient, repoName string, dir string) { t.Helper() buildContext := archive.ReadDirAsTar(dir, "/", 0, 0, -1) @@ -301,7 +301,7 @@ func checkResponse(response dockertypes.ImageBuildResponse) error { return nil } -func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig *TestRegistryConfig, repoName, dockerFile string) string { +func CreateImageOnRemote(t *testing.T, dockerCli client.CommonAPIClient, registryConfig *TestRegistryConfig, repoName, dockerFile string) string { t.Helper() imageName := registryConfig.RepoName(repoName) @@ -311,7 +311,7 @@ func CreateImageOnRemote(t *testing.T, dockerCli *client.Client, registryConfig return imageName } -func DockerRmi(dockerCli *client.Client, repoNames ...string) error { +func DockerRmi(dockerCli client.CommonAPIClient, repoNames ...string) error { var err error ctx := context.Background() for _, name := range repoNames { @@ -327,7 +327,7 @@ func DockerRmi(dockerCli *client.Client, repoNames ...string) error { return err } -func PushImage(dockerCli *client.Client, ref string, registryConfig *TestRegistryConfig) error { +func PushImage(dockerCli client.CommonAPIClient, ref string, registryConfig *TestRegistryConfig) error { rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: registryConfig.RegistryAuth()}) if err != nil { return err @@ -418,7 +418,7 @@ func RunE(cmd *exec.Cmd) (string, error) { return string(output), nil } -func PullImageWithAuth(dockerCli *client.Client, ref, registryAuth string) error { +func PullImageWithAuth(dockerCli client.CommonAPIClient, ref, registryAuth string) error { rc, err := dockerCli.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{RegistryAuth: registryAuth}) if err != nil { return nil @@ -482,7 +482,7 @@ func SkipIf(t *testing.T, expression bool, reason string) { } } -func RunContainer(ctx context.Context, dockerCli *client.Client, id string, stdout io.Writer, stderr io.Writer) error { +func RunContainer(ctx context.Context, dockerCli client.CommonAPIClient, id string, stdout io.Writer, stderr io.Writer) error { bodyChan, errChan := dockerCli.ContainerWait(ctx, id, container.WaitConditionNextExit) if err := dockerCli.ContainerStart(ctx, id, dockertypes.ContainerStartOptions{}); err != nil { diff --git a/vendor/github.com/buildpacks/imgutil/image.go b/vendor/github.com/buildpacks/imgutil/image.go index 84e1af6a0..e387898e6 100644 --- a/vendor/github.com/buildpacks/imgutil/image.go +++ b/vendor/github.com/buildpacks/imgutil/image.go @@ -7,6 +7,8 @@ import ( "time" ) +var NormalizedDateTime = time.Date(1980, time.January, 1, 0, 0, 1, 0, time.UTC) + type SaveDiagnostic struct { ImageName string Cause error diff --git a/vendor/github.com/buildpacks/imgutil/local/local.go b/vendor/github.com/buildpacks/imgutil/local/local.go index 42b2a7428..4772acd08 100644 --- a/vendor/github.com/buildpacks/imgutil/local/local.go +++ b/vendor/github.com/buildpacks/imgutil/local/local.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/google/go-containerregistry/pkg/name" + v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/pkg/errors" "golang.org/x/sync/singleflight" @@ -26,7 +27,7 @@ import ( type Image struct { repoName string - docker *client.Client + docker client.CommonAPIClient inspect types.ImageInspect layerPaths []string currentTempImage string @@ -72,7 +73,7 @@ func FromBaseImage(imageName string) ImageOption { } } -func NewImage(repoName string, dockerClient *client.Client, ops ...ImageOption) (imgutil.Image, error) { +func NewImage(repoName string, dockerClient client.CommonAPIClient, ops ...ImageOption) (imgutil.Image, error) { inspect := defaultInspect() image := &Image{ @@ -419,16 +420,11 @@ func (i *Image) doSave() (types.ImageInspect, error) { } func (i *Image) newConfigFile() ([]byte, error) { - imgConfig := map[string]interface{}{ - "os": "linux", - "created": time.Now().Format(time.RFC3339), - "config": i.inspect.Config, - "rootfs": map[string][]string{ - "diff_ids": i.inspect.RootFS.Layers, - }, - "history": make([]struct{}, len(i.inspect.RootFS.Layers)), + cfg, err := v1Config(i.inspect) + if err != nil { + return nil, err } - return json.Marshal(imgConfig) + return json.Marshal(cfg) } func (i *Image) Delete() error { @@ -455,7 +451,7 @@ func (i *Image) downloadImageOnce(imageName string) (*FileSystemLocalImage, erro return v.(*FileSystemLocalImage), nil } -func downloadImage(docker *client.Client, imageName string) (*FileSystemLocalImage, error) { +func downloadImage(docker client.CommonAPIClient, imageName string) (*FileSystemLocalImage, error) { ctx := context.Background() tarFile, err := docker.ImageSave(ctx, []string{imageName}) @@ -592,7 +588,7 @@ func untar(r io.Reader, dest string) error { } } -func inspectOptionalImage(docker *client.Client, imageName string) (types.ImageInspect, error) { +func inspectOptionalImage(docker client.CommonAPIClient, imageName string) (types.ImageInspect, error) { var ( err error inspect types.ImageInspect @@ -611,6 +607,80 @@ func inspectOptionalImage(docker *client.Client, imageName string) (types.ImageI func defaultInspect() types.ImageInspect { return types.ImageInspect{ - Config: &container.Config{}, + Os: "linux", + Architecture: "amd64", + Config: &container.Config{}, + } +} + +func v1Config(inspect types.ImageInspect) (v1.ConfigFile, error) { + history := make([]v1.History, len(inspect.RootFS.Layers)) + for i, _ := range history { + // zero history + history[i] = v1.History{ + Created: v1.Time{Time: imgutil.NormalizedDateTime}, + } } + diffIDs := make([]v1.Hash, len(inspect.RootFS.Layers)) + for i, layer := range inspect.RootFS.Layers { + hash, err := v1.NewHash(layer) + if err != nil { + return v1.ConfigFile{}, err + } + diffIDs[i] = hash + } + exposedPorts := make(map[string]struct{}, len(inspect.Config.ExposedPorts)) + for key, val := range inspect.Config.ExposedPorts { + exposedPorts[string(key)] = val + } + var config v1.Config + if inspect.Config != nil { + var healthcheck *v1.HealthConfig + if inspect.Config.Healthcheck != nil { + healthcheck = &v1.HealthConfig{ + Test: inspect.Config.Healthcheck.Test, + Interval: inspect.Config.Healthcheck.Interval, + Timeout: inspect.Config.Healthcheck.Timeout, + StartPeriod: inspect.Config.Healthcheck.StartPeriod, + Retries: inspect.Config.Healthcheck.Retries, + } + } + config = v1.Config{ + AttachStderr: inspect.Config.AttachStderr, + AttachStdin: inspect.Config.AttachStdin, + AttachStdout: inspect.Config.AttachStdout, + Cmd: inspect.Config.Cmd, + Healthcheck: healthcheck, + Domainname: inspect.Config.Domainname, + Entrypoint: inspect.Config.Entrypoint, + Env: inspect.Config.Env, + Hostname: inspect.Config.Hostname, + Image: inspect.Config.Image, + Labels: inspect.Config.Labels, + OnBuild: inspect.Config.OnBuild, + OpenStdin: inspect.Config.OpenStdin, + StdinOnce: inspect.Config.StdinOnce, + Tty: inspect.Config.Tty, + User: inspect.Config.User, + Volumes: inspect.Config.Volumes, + WorkingDir: inspect.Config.WorkingDir, + ExposedPorts: exposedPorts, + ArgsEscaped: inspect.Config.ArgsEscaped, + NetworkDisabled: inspect.Config.NetworkDisabled, + MacAddress: inspect.Config.MacAddress, + StopSignal: inspect.Config.StopSignal, + Shell: inspect.Config.Shell, + } + } + return v1.ConfigFile{ + Architecture: inspect.Architecture, + Created: v1.Time{Time: imgutil.NormalizedDateTime}, + History: history, + OS: inspect.Os, + RootFS: v1.RootFS{ + Type: "layers", + DiffIDs: diffIDs, + }, + Config: config, + }, nil } diff --git a/vendor/github.com/buildpacks/imgutil/remote/remote.go b/vendor/github.com/buildpacks/imgutil/remote/remote.go index 6a619a92d..4d95c61de 100644 --- a/vendor/github.com/buildpacks/imgutil/remote/remote.go +++ b/vendor/github.com/buildpacks/imgutil/remote/remote.go @@ -11,8 +11,8 @@ import ( "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/empty" "github.com/google/go-containerregistry/pkg/v1/mutate" - "github.com/google/go-containerregistry/pkg/v1/random" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote/transport" "github.com/google/go-containerregistry/pkg/v1/tarball" @@ -102,7 +102,15 @@ func newV1Image(keychain authn.Keychain, repoName string) (v1.Image, error) { } func emptyImage() (v1.Image, error) { - return random.Image(0, 0) + cfg := &v1.ConfigFile{ + Architecture: "amd64", + OS: "linux", + RootFS: v1.RootFS{ + Type: "layers", + DiffIDs: []v1.Hash{}, + }, + } + return mutate.ConfigFile(empty.Image, cfg) } func referenceForRepoName(keychain authn.Keychain, ref string) (name.Reference, authn.Authenticator, error) { @@ -344,7 +352,7 @@ func (i *Image) Save(additionalNames ...string) error { allNames := append([]string{i.repoName}, additionalNames...) - i.image, err = mutate.CreatedAt(i.image, v1.Time{Time: time.Now()}) + i.image, err = mutate.CreatedAt(i.image, v1.Time{Time: imgutil.NormalizedDateTime}) if err != nil { return errors.Wrap(err, "set creation time") } @@ -353,13 +361,21 @@ func (i *Image) Save(additionalNames ...string) error { if err != nil { return errors.Wrap(err, "get image config") } + cfg = cfg.DeepCopy() layers, err := i.image.Layers() if err != nil { return errors.Wrap(err, "get image layers") } - cfg.History = make([]v1.History, len(layers)) + for i, _ := range cfg.History { + cfg.History[i] = v1.History{ + Created: v1.Time{Time: imgutil.NormalizedDateTime}, + } + } + + cfg.DockerVersion = "" + cfg.Container = "" i.image, err = mutate.ConfigFile(i.image, cfg) if err != nil { return errors.Wrap(err, "zeroing history") diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/random/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/random/doc.go deleted file mode 100644 index d3712767d..000000000 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/random/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 Google LLC All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package random provides a facility for synthesizing pseudo-random images. -package random diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/random/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/random/image.go deleted file mode 100644 index 14cc43819..000000000 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/random/image.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2018 Google LLC All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package random - -import ( - "archive/tar" - "bytes" - "crypto/rand" - "crypto/sha256" - "encoding/hex" - "fmt" - "io" - "io/ioutil" - mrand "math/rand" - "time" - - v1 "github.com/google/go-containerregistry/pkg/v1" - "github.com/google/go-containerregistry/pkg/v1/empty" - "github.com/google/go-containerregistry/pkg/v1/mutate" - "github.com/google/go-containerregistry/pkg/v1/partial" - "github.com/google/go-containerregistry/pkg/v1/types" -) - -// uncompressedLayer implements partial.UncompressedLayer from raw bytes. -type uncompressedLayer struct { - diffID v1.Hash - mediaType types.MediaType - content []byte -} - -// DiffID implements partial.UncompressedLayer -func (ul *uncompressedLayer) DiffID() (v1.Hash, error) { - return ul.diffID, nil -} - -// Uncompressed implements partial.UncompressedLayer -func (ul *uncompressedLayer) Uncompressed() (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewBuffer(ul.content)), nil -} - -// MediaType returns the media type of the layer -func (ul *uncompressedLayer) MediaType() (types.MediaType, error) { - return ul.mediaType, nil -} - -var _ partial.UncompressedLayer = (*uncompressedLayer)(nil) - -// Image returns a pseudo-randomly generated Image. -func Image(byteSize, layers int64) (v1.Image, error) { - adds := make([]mutate.Addendum, 0, 5) - for i := int64(0); i < layers; i++ { - layer, err := Layer(byteSize, types.DockerLayer) - if err != nil { - return nil, err - } - adds = append(adds, mutate.Addendum{ - Layer: layer, - History: v1.History{ - Author: "random.Image", - Comment: fmt.Sprintf("this is a random history %d", i), - CreatedBy: "random", - Created: v1.Time{time.Now()}, - }, - }) - } - - return mutate.Append(empty.Image, adds...) -} - -// Layer returns a layer with pseudo-randomly generated content. -func Layer(byteSize int64, mt types.MediaType) (v1.Layer, error) { - fileName := fmt.Sprintf("random_file_%d.txt", mrand.Int()) - - // Hash the contents as we write it out to the buffer. - var b bytes.Buffer - hasher := sha256.New() - mw := io.MultiWriter(&b, hasher) - - // Write a single file with a random name and random contents. - tw := tar.NewWriter(mw) - if err := tw.WriteHeader(&tar.Header{ - Name: fileName, - Size: byteSize, - Typeflag: tar.TypeRegA, - }); err != nil { - return nil, err - } - if _, err := io.CopyN(tw, rand.Reader, byteSize); err != nil { - return nil, err - } - if err := tw.Close(); err != nil { - return nil, err - } - - h := v1.Hash{ - Algorithm: "sha256", - Hex: hex.EncodeToString(hasher.Sum(make([]byte, 0, hasher.Size()))), - } - - return partial.UncompressedToLayer(&uncompressedLayer{ - diffID: h, - mediaType: mt, - content: b.Bytes(), - }) -} diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/random/index.go b/vendor/github.com/google/go-containerregistry/pkg/v1/random/index.go deleted file mode 100644 index fb992211a..000000000 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/random/index.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2018 Google LLC All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package random - -import ( - "bytes" - "encoding/json" - "fmt" - - v1 "github.com/google/go-containerregistry/pkg/v1" - "github.com/google/go-containerregistry/pkg/v1/partial" - "github.com/google/go-containerregistry/pkg/v1/types" -) - -type randomIndex struct { - images map[v1.Hash]v1.Image - manifest *v1.IndexManifest -} - -// Index returns a pseudo-randomly generated ImageIndex with count images, each -// having the given number of layers of size byteSize. -func Index(byteSize, layers, count int64) (v1.ImageIndex, error) { - manifest := v1.IndexManifest{ - SchemaVersion: 2, - Manifests: []v1.Descriptor{}, - } - - images := make(map[v1.Hash]v1.Image) - for i := int64(0); i < count; i++ { - img, err := Image(byteSize, layers) - if err != nil { - return nil, err - } - - rawManifest, err := img.RawManifest() - if err != nil { - return nil, err - } - digest, size, err := v1.SHA256(bytes.NewReader(rawManifest)) - if err != nil { - return nil, err - } - mediaType, err := img.MediaType() - if err != nil { - return nil, err - } - - manifest.Manifests = append(manifest.Manifests, v1.Descriptor{ - Digest: digest, - Size: size, - MediaType: mediaType, - }) - - images[digest] = img - } - - return &randomIndex{ - images: images, - manifest: &manifest, - }, nil -} - -func (i *randomIndex) MediaType() (types.MediaType, error) { - return types.OCIImageIndex, nil -} - -func (i *randomIndex) Digest() (v1.Hash, error) { - return partial.Digest(i) -} - -func (i *randomIndex) Size() (int64, error) { - return partial.Size(i) -} - -func (i *randomIndex) IndexManifest() (*v1.IndexManifest, error) { - return i.manifest, nil -} - -func (i *randomIndex) RawManifest() ([]byte, error) { - m, err := i.IndexManifest() - if err != nil { - return nil, err - } - return json.Marshal(m) -} - -func (i *randomIndex) Image(h v1.Hash) (v1.Image, error) { - if img, ok := i.images[h]; ok { - return img, nil - } - - return nil, fmt.Errorf("image not found: %v", h) -} - -func (i *randomIndex) ImageIndex(h v1.Hash) (v1.ImageIndex, error) { - // This is a single level index (for now?). - return nil, fmt.Errorf("image not found: %v", h) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index dfa65f280..8704a56ae 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/Microsoft/go-winio github.com/Microsoft/go-winio/pkg/guid # github.com/apex/log v1.1.2-0.20190827100214-baa5455d1012 github.com/apex/log -# github.com/buildpacks/imgutil v0.0.0-20191212154113-dc184e0d403b +# github.com/buildpacks/imgutil v0.0.0-20200127205531-eec2000815b1 github.com/buildpacks/imgutil github.com/buildpacks/imgutil/fakes github.com/buildpacks/imgutil/local @@ -94,7 +94,6 @@ github.com/google/go-containerregistry/pkg/v1 github.com/google/go-containerregistry/pkg/v1/empty github.com/google/go-containerregistry/pkg/v1/mutate github.com/google/go-containerregistry/pkg/v1/partial -github.com/google/go-containerregistry/pkg/v1/random github.com/google/go-containerregistry/pkg/v1/remote github.com/google/go-containerregistry/pkg/v1/remote/transport github.com/google/go-containerregistry/pkg/v1/stream