Skip to content

Commit a2d2821

Browse files
Josh Mattilamaryamklabib
authored andcommitted
Adds support for multiple stemcells in kiln bake
- Backwards compatible with past usage of stemcell helper: "$( stemcell )" - Change stemcell template helper to take osname as an argument for multiple stemcells only - Deprecate stemcell-tarball in favor of stemcell-directory Co-authored-by: Josh Mattila <jmattila@pivotal.io> Co-authored-by: Maryam Labib <mlabib@pivotal.io>
1 parent 688957b commit a2d2821

File tree

19 files changed

+675
-65
lines changed

19 files changed

+675
-65
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ $ kiln bake \
1919
--version 2.0.0 \
2020
--metadata /path/to/metadata.yml \
2121
--releases-directory /path/to/releases \
22-
--stemcell-tarball /path/to/stemcell.tgz \
22+
--stemcells-directory /path/to/stemcells/first \
23+
--stemcells-directory /path/to/stemcells/second \
2324
--migrations-directory /path/to/migrations \
2425
--output-file /path/to/cf-2.0.0-build.4.pivotal
2526
```
@@ -201,7 +202,8 @@ $ kiln bake \
201202
--metadata /path/to/metadata.yml \
202203
--releases-directory /path/to/releases/first \
203204
--releases-directory /path/to/releases/second \
204-
--stemcell-tarball /path/to/stemcell.tgz \
205+
--stemcells-directory /path/to/stemcells/first \
206+
--stemcells-directory /path/to/stemcells/second \
205207
--output-file /path/to/cf-2.0.0-build.4.pivotal
206208
```
207209

@@ -223,7 +225,30 @@ runtime_configs:
223225

224226
Example [runtime-configs](example-tile/runtime-configs) directory.
225227

226-
##### `--stemcell-tarball`
228+
##### `--stemcells-directory`
229+
230+
The `--stemcell-directory` flag takes a path to a directory containing one
231+
or more stemcells.
232+
233+
To include information about the stemcell in your metadata you can use the
234+
`stemcell` template helper. It takes a single argument that specifies which
235+
stemcell os.
236+
237+
The `stemcell` helper does not support multiple versions of the same operating
238+
system currently.
239+
240+
```
241+
$ cat /path/to/metadata
242+
---
243+
stemcell_criteria: $( stemcell "ubuntu-xenial" )
244+
additional_stemcells_criteria:
245+
- $( stemcell "windows" )
246+
```
247+
248+
##### `--stemcell-tarball` (Deprecated)
249+
250+
*Warning: `--stemcell-tarball` will be removed in a future version of kiln.
251+
Use `--stemcells-directory` in the future.*
227252

228253
The `--stemcell-tarball` flag takes a path to a stemcell.
229254

acceptance/bake_test.go

Lines changed: 134 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ var _ = Describe("bake command", func() {
4141
someOtherInstanceGroupsDirectory = "fixtures/instance-groups2"
4242
someJobsDirectory = "fixtures/jobs"
4343
someOtherJobsDirectory = "fixtures/jobs2"
44+
multiStemcellDirectory = "fixtures/multiple-stemcells"
45+
singleStemcellDirectory = "fixtures/single-stemcell"
4446
variableFile = "fixtures/variables-file"
4547
someVarFile = "fixtures/var-dir/var-file.yml"
4648
someAssetsYMLPath = "fixtures/assets.yml"
4749
cfSHA1 = "b383f3177e4fc4f0386b7a06ddbc3f57e7dbf09f"
4850
diegoSHA1 = "ade2a81b4bfda4eb7062cb1a9314f8941ae11d06"
49-
stemcellTarball = "fixtures/stemcell.tgz"
5051
metadata = "fixtures/metadata.yml"
5152
metadataWithStemcellCriteria = "fixtures/metadata-with-stemcell-criteria.yml"
53+
metadataWithMultipleStemcells = "fixtures/metadata-with-multiple-stemcells.yml"
54+
metadataWithStemcellTarball = "fixtures/metadata-with-stemcell-tarball.yml"
5255
)
5356

5457
BeforeEach(func() {
@@ -78,7 +81,6 @@ var _ = Describe("bake command", func() {
7881
"--releases-directory", otherReleasesDirectory,
7982
"--releases-directory", someReleasesDirectory,
8083
"--runtime-configs-directory", someRuntimeConfigsDirectory,
81-
"--stemcell-tarball", stemcellTarball,
8284
"--variable", "some-variable=some-variable-value",
8385
"--variables-file", someVarFile,
8486
"--version", "1.2.3",
@@ -90,12 +92,12 @@ var _ = Describe("bake command", func() {
9092
})
9193

9294
It("generates a tile with the correct metadata", func() {
93-
commandWithArgs = append(commandWithArgs, "--migrations-directory",
94-
"fixtures/extra-migrations",
95-
"--migrations-directory",
96-
"fixtures/migrations",
97-
"--variables-file",
98-
variableFile)
95+
commandWithArgs = append(commandWithArgs,
96+
"--migrations-directory", "fixtures/extra-migrations",
97+
"--migrations-directory", "fixtures/migrations",
98+
"--variables-file", variableFile,
99+
"--stemcells-directory", singleStemcellDirectory,
100+
)
99101

100102
command := exec.Command(pathToMain, commandWithArgs...)
101103

@@ -174,7 +176,7 @@ var _ = Describe("bake command", func() {
174176
Expect(string(contents)).To(Equal("some_migration\n"))
175177

176178
Eventually(session.Err).Should(gbytes.Say("Reading release manifests"))
177-
Eventually(session.Err).Should(gbytes.Say("Reading stemcell manifest"))
179+
Eventually(session.Err).Should(gbytes.Say("Reading stemcells from directories"))
178180
Eventually(session.Err).Should(gbytes.Say(fmt.Sprintf("Building %s", outputFile)))
179181
Eventually(session.Err).Should(gbytes.Say(fmt.Sprintf("Adding metadata/metadata.yml to %s...", outputFile)))
180182
Eventually(session.Err).Should(gbytes.Say(fmt.Sprintf("Adding migrations/v1/201603041539_custom_buildpacks.js to %s...", outputFile)))
@@ -184,9 +186,108 @@ var _ = Describe("bake command", func() {
184186
Eventually(session.Err).ShouldNot(gbytes.Say(fmt.Sprintf("Adding releases/not-a-tarball.txt to %s...", outputFile)))
185187
})
186188

189+
Context("when multiple stemcells are provided", func() {
190+
BeforeEach(func() {
191+
commandWithArgs = []string{
192+
"bake",
193+
"--releases-directory", someReleasesDirectory,
194+
"--icon", someIconPath,
195+
"--metadata", metadataWithMultipleStemcells,
196+
"--stemcells-directory", multiStemcellDirectory,
197+
"--output-file", outputFile,
198+
"--version", "1.2.3",
199+
}
200+
})
201+
202+
It("interpolates metadata file using multiple stemcells", func() {
203+
command := exec.Command(pathToMain, commandWithArgs...)
204+
205+
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
206+
Expect(err).NotTo(HaveOccurred())
207+
208+
Eventually(session).Should(gexec.Exit(0))
209+
210+
archive, err := os.Open(outputFile)
211+
Expect(err).NotTo(HaveOccurred())
212+
213+
archiveInfo, err := archive.Stat()
214+
Expect(err).NotTo(HaveOccurred())
215+
216+
zr, err := zip.NewReader(archive, archiveInfo.Size())
217+
Expect(err).NotTo(HaveOccurred())
218+
219+
var file io.ReadCloser
220+
for _, f := range zr.File {
221+
if f.Name == "metadata/metadata.yml" {
222+
file, err = f.Open()
223+
Expect(err).NotTo(HaveOccurred())
224+
break
225+
}
226+
}
227+
228+
Expect(file).NotTo(BeNil(), "metadata was not found in built tile")
229+
metadataContents, err := ioutil.ReadAll(file)
230+
Expect(err).NotTo(HaveOccurred())
231+
232+
renderedYAML := fmt.Sprintf(expectedMetadataWithMultipleStemcells, cfSHA1)
233+
Expect(metadataContents).To(HelpfullyMatchYAML(renderedYAML))
234+
})
235+
})
236+
237+
Context("when the --stemcell-tarball flag is provided", func() {
238+
BeforeEach(func() {
239+
commandWithArgs = []string{
240+
"bake",
241+
"--releases-directory", someReleasesDirectory,
242+
"--icon", someIconPath,
243+
"--metadata", metadataWithStemcellTarball,
244+
"--stemcell-tarball", singleStemcellDirectory + "/stemcell.tgz",
245+
"--output-file", outputFile,
246+
"--version", "1.2.3",
247+
}
248+
})
249+
250+
It("interpolates metadata file using a single stemcell", func() {
251+
command := exec.Command(pathToMain, commandWithArgs...)
252+
253+
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
254+
Expect(err).NotTo(HaveOccurred())
255+
256+
Eventually(session).Should(gexec.Exit(0))
257+
258+
archive, err := os.Open(outputFile)
259+
Expect(err).NotTo(HaveOccurred())
260+
261+
archiveInfo, err := archive.Stat()
262+
Expect(err).NotTo(HaveOccurred())
263+
264+
zr, err := zip.NewReader(archive, archiveInfo.Size())
265+
Expect(err).NotTo(HaveOccurred())
266+
267+
var file io.ReadCloser
268+
for _, f := range zr.File {
269+
if f.Name == "metadata/metadata.yml" {
270+
file, err = f.Open()
271+
Expect(err).NotTo(HaveOccurred())
272+
break
273+
}
274+
}
275+
276+
Expect(file).NotTo(BeNil(), "metadata was not found in built tile")
277+
metadataContents, err := ioutil.ReadAll(file)
278+
Expect(err).NotTo(HaveOccurred())
279+
280+
renderedYAML := fmt.Sprintf(expectedMetadataWithStemcellTarball, cfSHA1)
281+
Expect(metadataContents).To(HelpfullyMatchYAML(renderedYAML))
282+
})
283+
})
284+
187285
Context("when the --sha256 flag is provided", func() {
188286
BeforeEach(func() {
189-
commandWithArgs = append(commandWithArgs, "--sha256")
287+
commandWithArgs = append(commandWithArgs,
288+
"--sha256",
289+
"--stemcells-directory", singleStemcellDirectory,
290+
)
190291
})
191292

192293
It("outputs a sha256 checksum of the file to stderr", func() {
@@ -234,12 +335,11 @@ var _ = Describe("bake command", func() {
234335
"--version", "1.2.3",
235336
"--assets-file", someAssetsYMLPath,
236337
}
237-
commandWithArgs = append(commandWithArgs, "--migrations-directory",
238-
"fixtures/extra-migrations",
239-
"--migrations-directory",
240-
"fixtures/migrations",
241-
"--variables-file",
242-
variableFile)
338+
commandWithArgs = append(commandWithArgs,
339+
"--migrations-directory", "fixtures/extra-migrations",
340+
"--migrations-directory", "fixtures/migrations",
341+
"--variables-file", variableFile,
342+
)
243343

244344
command := exec.Command(pathToMain, commandWithArgs...)
245345

@@ -364,6 +464,7 @@ var _ = Describe("bake command", func() {
364464
Eventually(session.Err).Should(gbytes.Say("cannot unmarshal"))
365465
})
366466
})
467+
367468
Context("when the --metadata-only flag is specified", func() {
368469
BeforeEach(func() {
369470
commandWithArgs = []string{
@@ -382,7 +483,7 @@ var _ = Describe("bake command", func() {
382483
"--releases-directory", otherReleasesDirectory,
383484
"--releases-directory", someReleasesDirectory,
384485
"--runtime-configs-directory", someRuntimeConfigsDirectory,
385-
"--stemcell-tarball", stemcellTarball,
486+
"--stemcells-directory", singleStemcellDirectory,
386487
"--variable", "some-variable=some-variable-value",
387488
"--variables-file", someVarFile,
388489
"--version", "1.2.3",
@@ -404,7 +505,10 @@ var _ = Describe("bake command", func() {
404505

405506
Context("when the --stub-releases flag is specified", func() {
406507
It("creates a tile with empty release tarballs", func() {
407-
commandWithArgs = append(commandWithArgs, "--stub-releases")
508+
commandWithArgs = append(commandWithArgs,
509+
"--stemcells-directory", singleStemcellDirectory,
510+
"--stub-releases",
511+
)
408512

409513
command := exec.Command(pathToMain, commandWithArgs...)
410514

@@ -436,6 +540,10 @@ var _ = Describe("bake command", func() {
436540

437541
Context("when no migrations are provided", func() {
438542
It("creates empty migrations folder", func() {
543+
commandWithArgs = append(commandWithArgs,
544+
"--stemcells-directory", singleStemcellDirectory,
545+
)
546+
439547
command := exec.Command(pathToMain, commandWithArgs...)
440548

441549
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
@@ -484,7 +592,9 @@ var _ = Describe("bake command", func() {
484592
commandWithArgs = append(commandWithArgs,
485593
"--embed", otherFileToEmbed,
486594
"--embed", someFileToEmbed,
487-
"--stub-releases")
595+
"--stub-releases",
596+
"--stemcells-directory", singleStemcellDirectory,
597+
)
488598

489599
command := exec.Command(pathToMain, commandWithArgs...)
490600

@@ -552,7 +662,9 @@ var _ = Describe("bake command", func() {
552662

553663
commandWithArgs = append(commandWithArgs,
554664
"--embed", dirToAdd,
555-
"--stub-releases")
665+
"--stub-releases",
666+
"--stemcells-directory", singleStemcellDirectory,
667+
)
556668
command := exec.Command(pathToMain, commandWithArgs...)
557669

558670
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
@@ -588,7 +700,7 @@ var _ = Describe("bake command", func() {
588700
})
589701
})
590702

591-
Context("when neither --assets-file nor --stemcell-tarball are provided", func() {
703+
Context("when neither --assets-file nor --stemcells-directory are provided", func() {
592704
It("generates a tile with unchanged stemcell criteria", func() {
593705
commandWithArgs = []string{
594706
"bake",
@@ -705,7 +817,7 @@ var _ = Describe("bake command", func() {
705817
"--jobs-directory", someOtherJobsDirectory,
706818
"--properties-directory", somePropertiesDirectory,
707819
"--runtime-configs-directory", someRuntimeConfigsDirectory,
708-
"--stemcell-tarball", stemcellTarball,
820+
"--stemcells-directory", singleStemcellDirectory,
709821
"--bosh-variables-directory", someBOSHVariablesDirectory,
710822
"--variable", "some-variable=some-variable-value",
711823
"--variables-file", someVarFile,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: cool-product-name
3+
metadata_version: '1.7'
4+
some_releases:
5+
- $( release "cf" )
6+
icon_img: $( icon )
7+
product_version: $( version )
8+
label: Pivotal Elastic Runtime
9+
stemcell_criteria: $( stemcell "ubuntu-trusty" )
10+
additional_stemcells_criteria:
11+
- $( stemcell "windows" )
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: cool-product-name
3+
metadata_version: '1.7'
4+
some_releases:
5+
- $( release "cf" )
6+
icon_img: $( icon )
7+
product_version: $( version )
8+
label: Pivotal Elastic Runtime
9+
stemcell_criteria: $( stemcell )

acceptance/fixtures/stemcell.tgz renamed to acceptance/fixtures/multiple-stemcells/stemcell-1.tgz

File renamed without changes.
348 Bytes
Binary file not shown.
191 Bytes
Binary file not shown.

acceptance/fixtures_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,39 @@ stemcell_criteria:
9898
requires_cpi: false
9999
enable_patch_security_updates: true
100100
`
101+
102+
var expectedMetadataWithMultipleStemcells = `---
103+
icon_img: aS1hbS1zb21lLWltYWdl
104+
label: Pivotal Elastic Runtime
105+
metadata_version: "1.7"
106+
name: cool-product-name
107+
product_version: 1.2.3
108+
some_releases:
109+
- file: cf-release-235.0.0-3215.4.0.tgz
110+
name: cf
111+
version: "235"
112+
sha1: %s
113+
stemcell_criteria:
114+
os: ubuntu-trusty
115+
version: "3215.4"
116+
additional_stemcells_criteria:
117+
- os: windows
118+
version: "2019.4"
119+
`
120+
121+
var expectedMetadataWithStemcellTarball = `---
122+
icon_img: aS1hbS1zb21lLWltYWdl
123+
label: Pivotal Elastic Runtime
124+
metadata_version: "1.7"
125+
name: cool-product-name
126+
product_version: 1.2.3
127+
some_releases:
128+
- file: cf-release-235.0.0-3215.4.0.tgz
129+
name: cf
130+
version: "235"
131+
sha1: %s
132+
stemcell_criteria:
133+
os: ubuntu-trusty
134+
version: "3215.4"
135+
`
136+

acceptance/help_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Usage: kiln [options] bake [<args>]
3131
--version, -v bool prints the kiln release version (default: false)
3232
3333
Command Arguments:
34-
--assets-file, -a string path to assets file (NOTE: mutually exclusive with --stemcell-tarball)
34+
--assets-file, -a string path to assets file (NOTE: mutually exclusive with --stemcell-directory)
3535
--bosh-variables-directory, -vd string (variadic) path to a directory containing BOSH variables
3636
--embed, -e string (variadic) path to files to include in the tile /embed directory
3737
--forms-directory, -f string (variadic) path to a directory containing forms
@@ -46,7 +46,8 @@ Command Arguments:
4646
--releases-directory, -rd string (variadic) path to a directory containing release tarballs
4747
--runtime-configs-directory, -rcd string (variadic) path to a directory containing runtime configs
4848
--sha256 bool calculates a SHA256 checksum of the output file
49-
--stemcell-tarball, -st string path to a stemcell tarball (NOTE: mutually exclusive with --assets-file)
49+
--stemcell-tarball, -st string deprecated -- path to a stemcell tarball (NOTE: mutually exclusive with --assets-file)
50+
--stemcells-directory, -sd string (variadic) path to a directory containing stemcells (NOTE: mutually exclusive with --assets-file or --stemcell-tarball)
5051
--stub-releases, -sr bool skips importing release tarballs into the tile
5152
--variable, -vr string (variadic) key value pairs of variables to interpolate
5253
--variables-file, -vf string (variadic) path to a file containing variables to interpolate

0 commit comments

Comments
 (0)