Exemplo n.º 1
0
func (i *ImageRetainer) Retain(imageList []string) {
	log := i.Logger.Session("retain")

	log.Info("starting")
	defer log.Info("retained")

	for _, image := range imageList {
		log := log.WithData(lager.Data{"url": image})
		log.Info("retaining")

		rootfsURL, err := url.Parse(image)
		if err != nil {
			log.Error("parse-rootfs-failed", err)
			continue
		}

		var id layercake.ID
		if id, err = i.toID(rootfsURL); err != nil {
			log.Error("convert-to-id-failed", err)
			continue
		}

		i.GraphRetainer.Retain(log, id)
		i.GraphRetainer.Retain(log, layercake.NamespacedID(id, i.NamespaceCacheKey))

		log.Info("retaining-complete")
	}
}
Exemplo n.º 2
0
func (provider *ContainerLayerCreator) namespace(log lager.Logger, imageID layercake.ID) (layercake.ID, error) {
	namespacedImageID := layercake.NamespacedID(imageID, provider.namespacer.CacheKey())

	if _, err := provider.graph.Get(namespacedImageID); err != nil {
		if err := provider.createNamespacedLayer(log, namespacedImageID, imageID); err != nil {
			return nil, err
		}
	}

	return namespacedImageID, nil
}
				_, id := fakeGraphRetainer.RetainArgsForCall(0)
				Expect(id).To(Equal(layercake.LocalImageID{
					Path:         "/foo/bar/baz",
					ModifiedTime: time.Time{},
				}))
			})

			It("retains the namespaced version of the image", func() {
				imageRetainer.Retain([]string{
					"/foo/bar/baz",
				})

				Expect(fakeGraphRetainer.RetainCallCount()).To(Equal(2))
				_, id := fakeGraphRetainer.RetainArgsForCall(1)
				Expect(id).To(Equal(layercake.NamespacedID(layercake.LocalImageID{
					Path:         "/foo/bar/baz",
					ModifiedTime: time.Time{},
				}, "chip-sandwhich")))
			})
		})

		Context("and it is a docker image", func() {
			It("retains the image", func() {
				imageRetainer.Retain([]string{
					"docker://foo/bar/baz",
				})

				Expect(fakeGraphRetainer.RetainCallCount()).To(Equal(2))
				_, id := fakeGraphRetainer.RetainArgsForCall(0)
				Expect(id).To(Equal(layercake.DockerImageID("/fetched//bar/baz")))
			})
							ImageID: "some-image-id",
							Env:     []string{"env1=env1value", "env2=env2value"},
						},
						rootfs_provider.Spec{
							Namespaced: true,
							QuotaSize:  0,
						},
					)

					Expect(err).ToNot(HaveOccurred())
				})

				It("namespaces it, and creates a graph entry with it as the parent", func() {
					Expect(fakeCake.CreateCallCount()).To(Equal(2))
					id, parent, _ := fakeCake.CreateArgsForCall(0)
					Expect(id).To(Equal(layercake.NamespacedID(layercake.DockerImageID("some-image-id"), "jam")))
					Expect(parent).To(Equal(layercake.DockerImageID("some-image-id")))

					id, parent, containerID := fakeCake.CreateArgsForCall(1)
					Expect(id).To(Equal(layercake.ContainerID("some-id")))
					Expect(parent).To(Equal(layercake.NamespacedID(layercake.DockerImageID("some-image-id"), "jam")))
					Expect(containerID).To(Equal("some-id"))

					Expect(fakeNamespacer.NamespaceCallCount()).To(Equal(1))
					_, dst := fakeNamespacer.NamespaceArgsForCall(0)
					Expect(dst).To(Equal("/mount/point/" + layercake.NamespacedID(layercake.DockerImageID("some-image-id"), "jam").GraphID()))

					Expect(mountpoint).To(Equal("/mount/point/" + layercake.ContainerID("some-id").GraphID()))
					Expect(envvars).To(Equal(
						[]string{
							"env1=env1value",
Exemplo n.º 5
0
	BeforeEach(func() {
		var err error
		baseDirectory, err = ioutil.TempDir("", "aufsTestGraphRoot")
		Expect(err).NotTo(HaveOccurred())

		cake = new(fake_cake.FakeCake)
		runner = linux_command_runner.New()

		parentID = new(fake_id.FakeID)
		parentID.GraphIDReturns("graph-id")

		childID = new(fake_id.FakeID)
		testError = errors.New("bad")

		namespacedChildID = layercake.NamespacedID(parentID, "test")
		otherNamespacedChildID = layercake.NamespacedID(parentID, "test2")
	})

	AfterEach(func() {
		Expect(os.RemoveAll(baseDirectory)).To(Succeed())
	})

	JustBeforeEach(func() {
		aufsCake = &layercake.AufsCake{
			Cake:      cake,
			Runner:    runner,
			GraphRoot: baseDirectory,
		}
	})