Skip to content

Commit

Permalink
points at pack/*:v3alpha2 images
Browse files Browse the repository at this point in the history
* Updates old defaults in config.toml

Signed-off-by: Emily Casey <ecasey@pivotal.io>
Signed-off-by: Matthew McNew <mmcnew@pivotal.io>
  • Loading branch information
ekcasey authored and matthewmcnew committed Dec 11, 2018
1 parent 85da90b commit 247001a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 27 deletions.
23 changes: 17 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
76 changes: 59 additions & 17 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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]]
Expand All @@ -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")
})
})

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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")
})
})
})
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"},
Expand Down
9 changes: 5 additions & 4 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 247001a

Please sign in to comment.