summaryrefslogtreecommitdiff
path: root/config/builder_test.go
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2018-08-06 10:40:03 -0700
committerDan Duvall <dduvall@wikimedia.org>2018-08-14 09:01:06 -0700
commit374976d445b605f2ea1618cc6d2c5006d046fa28 (patch)
treeaffd3e67b38463d15e7fc00bfc400130974732b8 /config/builder_test.go
parente7ce38ca630ae04b748308a2a0986393d6555ffc (diff)
downloadblubber-374976d445b605f2ea1618cc6d2c5006d046fa28.tar.gz
Refactor builder to support file requirements and run pre-install
The builder configuration has proven useful for supporting generic pre-entrypoint commands such as dependency managers not otherwise supported by specific Blubber configuration. Adding additional `builder.requirements` config expands support for such commands by allowing the user to specify files that should be copied into the image before the builder command runs. To support this extra configuration, `builder` had to be changed from a simple string to a mapping. The builder command must now by given as `builder.command`. The pattern of creating parent directories, copying files, and executing one or more commands prior to the entrypoint has become a common one. Some of the implementation of this pattern was moved from `PythonConfig` into shared build macros `build.SortFilesByDir` and `build.SyncFiles`. All config types that must have requirements files copied over independently of the entire source tree (`PythonConfig`, `BuilderConfig`, `NodeConfig`) now delegate to these functions. Change-Id: I67f33034f22cee2851ec866cfb07ab20c23eba8c
Diffstat (limited to 'config/builder_test.go')
-rw-r--r--config/builder_test.go50
1 files changed, 43 insertions, 7 deletions
diff --git a/config/builder_test.go b/config/builder_test.go
index a35221e..773ddd1 100644
--- a/config/builder_test.go
+++ b/config/builder_test.go
@@ -13,23 +13,37 @@ func TestBuilderConfigYAML(t *testing.T) {
cfg, err := config.ReadConfig([]byte(`---
version: v2
base: foo
+ builder:
+ command: [make, -f, Makefile, test]
+ requirements: [Makefile]
variants:
+ test: {}
build:
- builder: [make, -f, Makefile]`))
+ builder:
+ command: [make]
+ requirements: []`))
if assert.NoError(t, err) {
- variant, err := config.ExpandVariant(cfg, "build")
+ variant, err := config.ExpandVariant(cfg, "test")
- assert.Equal(t, []string{"make", "-f", "Makefile"}, variant.Builder)
+ if assert.NoError(t, err) {
+ assert.Equal(t, []string{"make", "-f", "Makefile", "test"}, variant.Builder.Command)
+ assert.Equal(t, []string{"Makefile"}, variant.Builder.Requirements)
+ }
- assert.Nil(t, err)
+ variant, err = config.ExpandVariant(cfg, "build")
+
+ if assert.NoError(t, err) {
+ assert.Equal(t, []string{"make"}, variant.Builder.Command)
+ assert.Equal(t, []string{}, variant.Builder.Requirements)
+ }
}
}
func TestBuilderConfigInstructions(t *testing.T) {
- cfg := config.BuilderConfig{Builder: []string{"make", "-f", "Makefile"}}
+ cfg := config.BuilderConfig{Command: []string{"make", "-f", "Makefile"}}
- t.Run("PhasePostInstall", func(t *testing.T) {
+ t.Run("PhasePreInstall", func(t *testing.T) {
assert.Equal(t,
[]build.Instruction{
build.Run{
@@ -37,7 +51,29 @@ func TestBuilderConfigInstructions(t *testing.T) {
[]string{"-f", "Makefile"},
},
},
- cfg.InstructionsForPhase(build.PhasePostInstall),
+ cfg.InstructionsForPhase(build.PhasePreInstall),
+ )
+ })
+}
+
+func TestBuilderConfigInstructionsWithRequirements(t *testing.T) {
+ cfg := config.BuilderConfig{
+ Command: []string{"make", "-f", "Makefile", "foo"},
+ Requirements: []string{"Makefile", "foo", "bar/baz"},
+ }
+
+ t.Run("PhasePreInstall", func(t *testing.T) {
+ assert.Equal(t,
+ []build.Instruction{
+ build.Run{"mkdir -p", []string{"bar/"}},
+ build.Copy{[]string{"Makefile", "foo"}, "./"},
+ build.Copy{[]string{"bar/baz"}, "bar/"},
+ build.Run{
+ "make",
+ []string{"-f", "Makefile", "foo"},
+ },
+ },
+ cfg.InstructionsForPhase(build.PhasePreInstall),
)
})
}