summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2018-02-27 13:09:27 -0800
committerDan Duvall <dduvall@wikimedia.org>2018-03-05 16:45:34 -0800
commit0902d688e99615150a674403e62c64b2f655c65c (patch)
treed1334d5373728576d83c4a37492ba56b24845a30 /config
parent8fa191f03d34178d251f6705c72821d32043e71f (diff)
downloadblubber-0902d688e99615150a674403e62c64b2f655c65c.tar.gz
Generalize instructions for entrypoint and working directory
Summary: Introduce new `build.EntryPoint` and `build.WorkingDirectory` instructions to allow configuration to inject them instead of hard coding their generation in the Docker compiler. Simplified the Docker compiler to simply iterate over build phases as returned by a new function `build.Phases()`. Depends on D990 Test Plan: Run `go test ./...`. Reviewers: thcipriani, demon, hashar, #release-engineering-team Reviewed By: thcipriani, #release-engineering-team Tags: #release-engineering-team Differential Revision: https://phabricator.wikimedia.org/D991
Diffstat (limited to 'config')
-rw-r--r--config/lives.go4
-rw-r--r--config/lives_test.go7
-rw-r--r--config/variant.go4
-rw-r--r--config/variant_test.go15
4 files changed, 29 insertions, 1 deletions
diff --git a/config/lives.go b/config/lives.go
index 8d705e7..665a734 100644
--- a/config/lives.go
+++ b/config/lives.go
@@ -48,6 +48,10 @@ func (lives LivesConfig) InstructionsForPhase(phase build.Phase) []build.Instruc
build.Chown(lives.UID, lives.GID, LocalLibPrefix),
),
}}
+ case build.PhasePrivilegeDropped:
+ return []build.Instruction{
+ build.WorkingDirectory{lives.In},
+ }
}
return []build.Instruction{}
diff --git a/config/lives_test.go b/config/lives_test.go
index eeb91ef..dec1f99 100644
--- a/config/lives_test.go
+++ b/config/lives_test.go
@@ -73,7 +73,12 @@ func TestLivesConfigInstructions(t *testing.T) {
})
t.Run("PhasePrivilegeDropped", func(t *testing.T) {
- assert.Empty(t, cfg.InstructionsForPhase(build.PhasePreInstall))
+ assert.Equal(t,
+ []build.Instruction{
+ build.WorkingDirectory{"/some/directory"},
+ },
+ cfg.InstructionsForPhase(build.PhasePrivilegeDropped),
+ )
})
t.Run("PhasePreInstall", func(t *testing.T) {
diff --git a/config/variant.go b/config/variant.go
index 0cb3f09..e3562bf 100644
--- a/config/variant.go
+++ b/config/variant.go
@@ -68,6 +68,10 @@ func (vc *VariantConfig) InstructionsForPhase(phase build.Phase) []build.Instruc
case build.PhasePostInstall:
switchUser = vc.Runs.As
instructions = build.ApplyUser(vc.Runs.UID, vc.Runs.GID, instructions)
+
+ if len(vc.EntryPoint) > 0 {
+ instructions = append(instructions, build.EntryPoint{vc.EntryPoint})
+ }
}
if switchUser != "" {
diff --git a/config/variant_test.go b/config/variant_test.go
index 6890f6d..f906e67 100644
--- a/config/variant_test.go
+++ b/config/variant_test.go
@@ -135,6 +135,21 @@ func TestVariantConfigInstructions(t *testing.T) {
cfg.InstructionsForPhase(build.PhasePostInstall),
)
})
+
+ t.Run("with entrypoint", func(t *testing.T) {
+ cfg := config.VariantConfig{
+ CommonConfig: config.CommonConfig{
+ EntryPoint: []string{"/foo", "bar"},
+ },
+ }
+
+ assert.Equal(t,
+ []build.Instruction{
+ build.EntryPoint{[]string{"/foo", "bar"}},
+ },
+ cfg.InstructionsForPhase(build.PhasePostInstall),
+ )
+ })
})
}