From 247001a5b8d5b2516fd956e17557cdf0ba93d2e7 Mon Sep 17 00:00:00 2001 From: Emily Casey Date: Tue, 11 Dec 2018 12:59:49 -0500 Subject: [PATCH] points at pack/*:v3alpha2 images * Updates old defaults in config.toml Signed-off-by: Emily Casey Signed-off-by: Matthew McNew --- config/config.go | 23 +++++++++--- config/config_test.go | 76 +++++++++++++++++++++++++++++--------- testhelpers/testhelpers.go | 9 +++-- 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/config/config.go b/config/config.go index 152872dd1..7333d153f 100644 --- a/config/config.go +++ b/config/config.go @@ -41,13 +41,13 @@ func New(path string) (*Config, error) { if config.DefaultStackID == "" { config.DefaultStackID = "io.buildpacks.stacks.bionic" } - if config.DefaultBuilder == "" { - config.DefaultBuilder = "packs/samples" + if config.DefaultBuilder == "" || config.DefaultBuilder == "packs/samples" { + config.DefaultBuilder = "packs/samples:v3alpha2" } - appendStackIfMissing(config, Stack{ + upgradeStack(config, Stack{ ID: "io.buildpacks.stacks.bionic", - BuildImages: []string{"packs/build"}, - RunImages: []string{"packs/run"}, + BuildImages: []string{"packs/build:v3alpha2"}, + RunImages: []string{"packs/run:v3alpha2"}, }) config.configPath = configPath @@ -81,9 +81,20 @@ func previousConfig(path string) (*Config, error) { return config, nil } -func appendStackIfMissing(config *Config, stack Stack) { +func upgradeStack(config *Config, stack Stack) { for _, stk := range config.Stacks { if stk.ID == stack.ID { + for index, value := range stk.BuildImages { + if value == "packs/build"{ + stk.BuildImages[index] = stack.BuildImages[0] + } + } + + for index, value := range stk.RunImages { + if value == "packs/run"{ + stk.RunImages[index] = stack.RunImages[0] + } + } return } } diff --git a/config/config_test.go b/config/config_test.go index 9e14cb2bf..1adbce92f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -41,22 +41,22 @@ func testConfig(t *testing.T, when spec.G, it spec.S) { b, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml")) h.AssertNil(t, err) h.AssertContains(t, string(b), `default-stack-id = "io.buildpacks.stacks.bionic"`) - h.AssertContains(t, string(b), `default-builder = "packs/samples"`) + h.AssertContains(t, string(b), `default-builder = "packs/samples:v3alpha2"`) h.AssertContains(t, string(b), strings.TrimSpace(` [[stacks]] id = "io.buildpacks.stacks.bionic" - build-images = ["packs/build"] - run-images = ["packs/run"] + build-images = ["packs/build:v3alpha2"] + run-images = ["packs/run:v3alpha2"] `)) h.AssertEq(t, len(subject.Stacks), 1) h.AssertEq(t, subject.Stacks[0].ID, "io.buildpacks.stacks.bionic") h.AssertEq(t, len(subject.Stacks[0].BuildImages), 1) - h.AssertEq(t, subject.Stacks[0].BuildImages[0], "packs/build") + h.AssertEq(t, subject.Stacks[0].BuildImages[0], "packs/build:v3alpha2") h.AssertEq(t, len(subject.Stacks[0].RunImages), 1) - h.AssertEq(t, subject.Stacks[0].RunImages[0], "packs/run") + h.AssertEq(t, subject.Stacks[0].RunImages[0], "packs/run:v3alpha2") h.AssertEq(t, subject.DefaultStackID, "io.buildpacks.stacks.bionic") - h.AssertEq(t, subject.DefaultBuilder, "packs/samples") + h.AssertEq(t, subject.DefaultBuilder, "packs/samples:v3alpha2") }) when("path is missing", func() { @@ -98,8 +98,8 @@ default-builder = "some/builder" h.AssertContains(t, string(b), strings.TrimSpace(` [[stacks]] id = "io.buildpacks.stacks.bionic" - build-images = ["packs/build"] - run-images = ["packs/run"] + build-images = ["packs/build:v3alpha2"] + run-images = ["packs/run:v3alpha2"] `)) h.AssertContains(t, string(b), strings.TrimSpace(` [[stacks]] @@ -119,9 +119,9 @@ default-builder = "some/builder" h.AssertEq(t, subject.Stacks[1].ID, "io.buildpacks.stacks.bionic") h.AssertEq(t, len(subject.Stacks[1].BuildImages), 1) - h.AssertEq(t, subject.Stacks[1].BuildImages[0], "packs/build") + h.AssertEq(t, subject.Stacks[1].BuildImages[0], "packs/build:v3alpha2") h.AssertEq(t, len(subject.Stacks[1].RunImages), 1) - h.AssertEq(t, subject.Stacks[1].RunImages[0], "packs/run") + h.AssertEq(t, subject.Stacks[1].RunImages[0], "packs/run:v3alpha2") }) }) @@ -134,11 +134,11 @@ default-builder = "some/builder" [[stacks]] id = "io.buildpacks.stacks.bionic" build-images = ["some-other/build"] - run-images = ["some-other/run", "packs/run"] + run-images = ["some-other/run", "packs/run:v3alpha2"] `)) }) - it("does not modify the built-in stack", func() { + it("does not modify the built-in stack if it is customized", func() { subject, err := config.New(tmpDir) h.AssertNil(t, err) @@ -149,7 +149,7 @@ default-builder = "some/builder" [[stacks]] id = "io.buildpacks.stacks.bionic" build-images = ["some-other/build"] - run-images = ["some-other/run", "packs/run"] + run-images = ["some-other/run", "packs/run:v3alpha2"] `)) h.AssertEq(t, len(subject.Stacks), 1) @@ -158,8 +158,50 @@ default-builder = "some/builder" h.AssertEq(t, subject.Stacks[0].BuildImages[0], "some-other/build") h.AssertEq(t, len(subject.Stacks[0].RunImages), 2) h.AssertEq(t, subject.Stacks[0].RunImages[0], "some-other/run") - h.AssertEq(t, subject.Stacks[0].RunImages[1], "packs/run") + h.AssertEq(t, subject.Stacks[0].RunImages[1], "packs/run:v3alpha2") + h.AssertEq(t, subject.DefaultStackID, "io.buildpacks.stacks.bionic") + }) + }) + + when("config.toml has an outdated built-in stack", func() { + it.Before(func() { + w, err := os.Create(filepath.Join(tmpDir, "config.toml")) + h.AssertNil(t, err) + defer w.Close() + w.Write([]byte(` +default-builder = "packs/samples" + +[[stacks]] + id = "io.buildpacks.stacks.bionic" + build-images = ["packs/build"] + run-images = ["some-other/run", "packs/run"] +`)) + }) + + it("modifies old defaults", func() { + subject, err := config.New(tmpDir) + h.AssertNil(t, err) + + b, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml")) + h.AssertNil(t, err) + h.AssertContains(t, string(b), `default-stack-id = "io.buildpacks.stacks.bionic"`) + h.AssertContains(t, string(b), `default-builder = "packs/samples:v3alpha2"`) + h.AssertContains(t, string(b), strings.TrimSpace(` +[[stacks]] + id = "io.buildpacks.stacks.bionic" + build-images = ["packs/build:v3alpha2"] + run-images = ["some-other/run", "packs/run:v3alpha2"] +`)) + + h.AssertEq(t, len(subject.Stacks), 1) + h.AssertEq(t, subject.Stacks[0].ID, "io.buildpacks.stacks.bionic") + h.AssertEq(t, len(subject.Stacks[0].BuildImages), 1) + h.AssertEq(t, subject.Stacks[0].BuildImages[0], "packs/build:v3alpha2") + h.AssertEq(t, len(subject.Stacks[0].RunImages), 2) + h.AssertEq(t, subject.Stacks[0].RunImages[0], "some-other/run") + h.AssertEq(t, subject.Stacks[0].RunImages[1], "packs/run:v3alpha2") h.AssertEq(t, subject.DefaultStackID, "io.buildpacks.stacks.bionic") + h.AssertEq(t, subject.DefaultBuilder, "packs/samples:v3alpha2") }) }) }) @@ -336,8 +378,8 @@ default-stack-id = "stack-1" id = "stack-1" [[stacks]] id = "my.stack" - build-images = ["packs/build"] - run-images = ["packs/run"] + build-images = ["packs/build:v3alpha2"] + run-images = ["packs/run:v3alpha2"] [[stacks]] id = "stack-3" `), 0666)) @@ -372,7 +414,7 @@ default-stack-id = "stack-1" stack, err := subject.Get("my.stack") h.AssertNil(t, err) h.AssertEq(t, stack.BuildImages, []string{"packs/build-2"}) - h.AssertEq(t, stack.RunImages, []string{"packs/run"}) + h.AssertEq(t, stack.RunImages, []string{"packs/run:v3alpha2"}) err = subject.Update("my.stack", config.Stack{ RunImages: []string{"packs/run-3"}, diff --git a/testhelpers/testhelpers.go b/testhelpers/testhelpers.go index 18b6f1557..7e4134e2e 100644 --- a/testhelpers/testhelpers.go +++ b/testhelpers/testhelpers.go @@ -257,7 +257,7 @@ func DefaultBuildImage(t *testing.T, registryPort string) string { t.Helper() tag := packTag() getBuildImageOnce.Do(func() { - if tag == "latest" { + if tag == defaultTag { AssertNil(t, dockerCli(t).PullImage(fmt.Sprintf("packs/build:%s", tag))) } AssertNil(t, dockerCli(t).ImageTag( @@ -275,7 +275,7 @@ func DefaultRunImage(t *testing.T, registryPort string) string { t.Helper() tag := packTag() getRunImageOnce.Do(func() { - if tag == "latest" { + if tag == defaultTag { AssertNil(t, dockerCli(t).PullImage(fmt.Sprintf("packs/run:%s", tag))) } AssertNil(t, dockerCli(t).ImageTag( @@ -293,7 +293,7 @@ func DefaultBuilderImage(t *testing.T, registryPort string) string { t.Helper() tag := packTag() getBuilderImageOnce.Do(func() { - if tag == "latest" { + if tag == defaultTag { AssertNil(t, dockerCli(t).PullImage(fmt.Sprintf("packs/samples:%s", tag))) } AssertNil(t, dockerCli(t).ImageTag( @@ -429,10 +429,11 @@ func pushImage(dockerCli *docker.Client, ref string) error { return rc.Close() } +const defaultTag = "v3alpha2" func packTag() string { tag := os.Getenv("PACK_TAG") if tag == "" { - return "latest" + return defaultTag } return tag }