func (s *DockerRegistrySuite) TestPullMigration(c *check.C) {
	repoName := privateRegistryURL + "/dockercli/migration"

	baseImage := repoName + ":base"
	_, err := buildImage(baseImage, fmt.Sprintf(`
	    FROM scratch
	    ENV IMAGE base
	    CMD echo %s
	`, baseImage), true)
	if err != nil {
		c.Fatal(err)
	}

	baseIDBeforePush := imageID(c, baseImage)
	baseParentBeforePush := imageParent(c, baseImage)

	derivedImage := repoName + ":derived"
	_, err = buildImage(derivedImage, fmt.Sprintf(`
	    FROM %s
	    CMD echo %s
	`, baseImage, derivedImage), true)
	if err != nil {
		c.Fatal(err)
	}

	derivedIDBeforePush := imageID(c, derivedImage)

	dockerCmd(c, "push", derivedImage)

	// Remove derived image from the local store
	dockerCmd(c, "rmi", derivedImage)

	// Repull
	dockerCmd(c, "pull", derivedImage)

	// Check that the parent of this pulled image is the original base
	// image
	derivedIDAfterPull1 := imageID(c, derivedImage)
	derivedParentAfterPull1 := imageParent(c, derivedImage)

	if derivedIDAfterPull1 == derivedIDBeforePush {
		c.Fatal("image's ID should have changed on after deleting and pulling")
	}

	if derivedParentAfterPull1 != baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) does not match base image's ID (%s)", derivedParentAfterPull1, baseIDBeforePush)
	}

	// Confirm that repushing and repulling does not change the computed ID
	dockerCmd(c, "push", derivedImage)
	dockerCmd(c, "rmi", derivedImage)
	dockerCmd(c, "pull", derivedImage)

	derivedIDAfterPull2 := imageID(c, derivedImage)
	derivedParentAfterPull2 := imageParent(c, derivedImage)

	if derivedIDAfterPull2 != derivedIDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a repush/repull")
	}

	if derivedParentAfterPull2 != baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) does not match base image's ID (%s)", derivedParentAfterPull2, baseIDBeforePush)
	}

	// Remove everything, repull, and make sure everything uses computed IDs
	dockerCmd(c, "rmi", baseImage, derivedImage)
	dockerCmd(c, "pull", derivedImage)

	derivedIDAfterPull3 := imageID(c, derivedImage)
	derivedParentAfterPull3 := imageParent(c, derivedImage)
	derivedGrandparentAfterPull3 := imageParent(c, derivedParentAfterPull3)

	if derivedIDAfterPull3 != derivedIDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a second repull")
	}

	if derivedParentAfterPull3 == baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) should not match base image's original ID (%s)", derivedParentAfterPull3, derivedIDBeforePush)
	}

	if derivedGrandparentAfterPull3 == baseParentBeforePush {
		c.Fatal("base image's parent ID should have been rewritten on pull")
	}
}
// TestPullMigration verifies that pulling an image based on layers
// that already exists locally will reuse those existing layers.
TestPullMigration verifies that pulling an image based on layers
that already exists locally will reuse those existing layers.
// TestPullMigration verifies that pulling an image based on layers // that already exists locally will reuse those existing layers .
func (s *DockerRegistrySuite) TestPullMigration(c *check.C) {
	repoName := privateRegistryURL + "/dockercli/migration"
	baseImage := repoName + ":base"
	_, err := buildImage(baseImage, fmt.Sprintf(`
	    FROM scratch
	    ENV IMAGE base
	    CMD echo %s
	`, baseImage), true)
	if err != nil {
		c.Fatal(err)
	}
	baseIDBeforePush := imageID(c, baseImage)
	baseParentBeforePush := imageParent(c, baseImage)
	derivedImage := repoName + ":derived"
	_, err = buildImage(derivedImage, fmt.Sprintf(`
	    FROM %s
	    CMD echo %s
	`, baseImage, derivedImage), true)
	if err != nil {
		c.Fatal(err)
	}
	derivedIDBeforePush := imageID(c, derivedImage)
	dockerCmd(c, "push", derivedImage)
	dockerCmd(c, "rmi", derivedImage)
	dockerCmd(c, "pull", derivedImage)
	derivedIDAfterPull1 := imageID(c, derivedImage)
	derivedParentAfterPull1 := imageParent(c, derivedImage)
	if derivedIDAfterPull1 == derivedIDBeforePush {
		c.Fatal("image's ID should have changed on after deleting and pulling")
	}
	if derivedParentAfterPull1 != baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) does not match base image's ID (%s)", derivedParentAfterPull1, baseIDBeforePush)
	}
	dockerCmd(c, "push", derivedImage)
	dockerCmd(c, "rmi", derivedImage)
	dockerCmd(c, "pull", derivedImage)
	derivedIDAfterPull2 := imageID(c, derivedImage)
	derivedParentAfterPull2 := imageParent(c, derivedImage)
	if derivedIDAfterPull2 != derivedIDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a repush/repull")
	}
	if derivedParentAfterPull2 != baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) does not match base image's ID (%s)", derivedParentAfterPull2, baseIDBeforePush)
	}
	dockerCmd(c, "rmi", baseImage, derivedImage)
	dockerCmd(c, "pull", derivedImage)
	derivedIDAfterPull3 := imageID(c, derivedImage)
	derivedParentAfterPull3 := imageParent(c, derivedImage)
	derivedGrandparentAfterPull3 := imageParent(c, derivedParentAfterPull3)
	if derivedIDAfterPull3 != derivedIDAfterPull1 {
		c.Fatal("image's ID unexpectedly changed after a second repull")
	}
	if derivedParentAfterPull3 == baseIDBeforePush {
		c.Fatalf("pulled image's parent ID (%s) should not match base image's original ID (%s)", derivedParentAfterPull3, derivedIDBeforePush)
	}
	if derivedGrandparentAfterPull3 == baseParentBeforePush {
		c.Fatal("base image's parent ID should have been rewritten on pull")
	}
}
func ( s * DockerRegistrySuite ) TestPullMigration ( c * check . C ) { repoName := privateRegistryURL + " " baseImage := repoName + " " _ , err := buildImage ( baseImage , fmt . Sprintf ( `
	    FROM scratch
	    ENV IMAGE base
	    CMD echo %s
	` , baseImage ) , true ) if err != nil { c . Fatal ( err ) } baseIDBeforePush := imageID ( c , baseImage ) baseParentBeforePush := imageParent ( c , baseImage ) derivedImage := repoName + " " _ , err = buildImage ( derivedImage , fmt . Sprintf ( `
	    FROM %s
	    CMD echo %s
	` , baseImage , derivedImage ) , true ) if err != nil { c . Fatal ( err ) } derivedIDBeforePush := imageID ( c , derivedImage ) dockerCmd ( c , " " , derivedImage ) dockerCmd ( c , " " , derivedImage ) dockerCmd ( c , " " , derivedImage ) derivedIDAfterPull1 := imageID ( c , derivedImage ) derivedParentAfterPull1 := imageParent ( c , derivedImage ) if derivedIDAfterPull1 == derivedIDBeforePush { c . Fatal ( " " ) } if derivedParentAfterPull1 != baseIDBeforePush { c . Fatalf ( " " , derivedParentAfterPull1 , baseIDBeforePush ) } dockerCmd ( c , " " , derivedImage ) dockerCmd ( c , " " , derivedImage ) dockerCmd ( c , " " , derivedImage ) derivedIDAfterPull2 := imageID ( c , derivedImage ) derivedParentAfterPull2 := imageParent ( c , derivedImage ) if derivedIDAfterPull2 != derivedIDAfterPull1 { c . Fatal ( " " ) } if derivedParentAfterPull2 != baseIDBeforePush { c . Fatalf ( " " , derivedParentAfterPull2 , baseIDBeforePush ) } dockerCmd ( c , " " , baseImage , derivedImage ) dockerCmd ( c , " " , derivedImage ) derivedIDAfterPull3 := imageID ( c , derivedImage ) derivedParentAfterPull3 := imageParent ( c , derivedImage ) derivedGrandparentAfterPull3 := imageParent ( c , derivedParentAfterPull3 ) if derivedIDAfterPull3 != derivedIDAfterPull1 { c . Fatal ( " " ) } if derivedParentAfterPull3 == baseIDBeforePush { c . Fatalf ( " " , derivedParentAfterPull3 , derivedIDBeforePush ) } if derivedGrandparentAfterPull3 == baseParentBeforePush { c . Fatal ( " " ) } }
TestPullMigration verifies that pulling an image based on layers
that already exists locally will reuse those existing layers.
TestPullMigration verifies that pulling an image based on layers that already exists locally will reuse those existing layers .
// Remove derived image from the local store // Repull // Check that the parent of this pulled image is the original base // image // Confirm that repushing and repulling does not change the computed ID // Remove everything, repull, and make sure everything uses computed IDs