summaryrefslogtreecommitdiff
path: root/docker
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 /docker
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 'docker')
-rw-r--r--docker/compiler.go19
-rw-r--r--docker/instructions.go7
-rw-r--r--docker/instructions_test.go20
3 files changed, 29 insertions, 17 deletions
diff --git a/docker/compiler.go b/docker/compiler.go
index 5929692..b0d5dce 100644
--- a/docker/compiler.go
+++ b/docker/compiler.go
@@ -5,7 +5,6 @@ package docker
import (
"bytes"
- "strings"
"phabricator.wikimedia.org/source/blubber/build"
"phabricator.wikimedia.org/source/blubber/config"
@@ -61,22 +60,8 @@ func compileStage(buffer *bytes.Buffer, stage string, vcfg *config.VariantConfig
writeln(buffer, "FROM ", baseAndStage)
- compilePhase(buffer, vcfg, build.PhasePrivileged)
-
- compilePhase(buffer, vcfg, build.PhasePrivilegeDropped)
-
- if vcfg.Lives.In != "" {
- writeln(buffer, "WORKDIR ", vcfg.Lives.In)
- }
-
- compilePhase(buffer, vcfg, build.PhasePreInstall)
-
- compilePhase(buffer, vcfg, build.PhaseInstall)
-
- compilePhase(buffer, vcfg, build.PhasePostInstall)
-
- if len(vcfg.EntryPoint) > 0 {
- writeln(buffer, "ENTRYPOINT [\"", strings.Join(vcfg.EntryPoint, "\", \""), "\"]")
+ for _, phase := range build.Phases() {
+ compilePhase(buffer, vcfg, phase)
}
}
diff --git a/docker/instructions.go b/docker/instructions.go
index c031d01..8463b0e 100644
--- a/docker/instructions.go
+++ b/docker/instructions.go
@@ -31,6 +31,10 @@ func NewInstruction(bi build.Instruction) (Instruction, error) {
i.flags = []string{"from"}
}
+ case build.EntryPoint:
+ i.name = "ENTRYPOINT"
+ i.array = true
+
case build.Env:
i.name = "ENV"
i.separator = " "
@@ -45,6 +49,9 @@ func NewInstruction(bi build.Instruction) (Instruction, error) {
case build.Volume:
i.name = "VOLUME"
i.array = true
+
+ case build.WorkingDirectory:
+ i.name = "WORKDIR"
}
if i.name == "" {
diff --git a/docker/instructions_test.go b/docker/instructions_test.go
index 37eeaf1..6215841 100644
--- a/docker/instructions_test.go
+++ b/docker/instructions_test.go
@@ -61,6 +61,16 @@ func TestCopyFrom(t *testing.T) {
}
}
+func TestEntryPoint(t *testing.T) {
+ i := build.EntryPoint{[]string{"foo", "bar"}}
+
+ di, err := docker.NewInstruction(i)
+
+ if assert.NoError(t, err) {
+ assert.Equal(t, "ENTRYPOINT [\"foo\", \"bar\"]\n", di.Compile())
+ }
+}
+
func TestEnv(t *testing.T) {
i := build.Env{map[string]string{"foo": "bar", "bar": "foo"}}
@@ -101,6 +111,16 @@ func TestVolume(t *testing.T) {
}
}
+func TestWorkingDirectory(t *testing.T) {
+ i := build.WorkingDirectory{"/foo/dir"}
+
+ di, err := docker.NewInstruction(i)
+
+ if assert.NoError(t, err) {
+ assert.Equal(t, "WORKDIR \"/foo/dir\"\n", di.Compile())
+ }
+}
+
func TestEscapeRun(t *testing.T) {
i := build.Run{"/bin/true\nRUN echo HACKED!", []string{}}