diff options
author | Dan Duvall <dduvall@wikimedia.org> | 2018-02-27 13:09:27 -0800 |
---|---|---|
committer | Dan Duvall <dduvall@wikimedia.org> | 2018-03-05 16:45:34 -0800 |
commit | 0902d688e99615150a674403e62c64b2f655c65c (patch) | |
tree | d1334d5373728576d83c4a37492ba56b24845a30 /build | |
parent | 8fa191f03d34178d251f6705c72821d32043e71f (diff) | |
download | blubber-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 'build')
-rw-r--r-- | build/instructions.go | 25 | ||||
-rw-r--r-- | build/instructions_test.go | 12 | ||||
-rw-r--r-- | build/phases.go | 12 |
3 files changed, 49 insertions, 0 deletions
diff --git a/build/instructions.go b/build/instructions.go index 91caa6b..295221e 100644 --- a/build/instructions.go +++ b/build/instructions.go @@ -109,6 +109,18 @@ func (cf CopyFrom) Compile() []string { return append([]string{cf.From}, cf.Copy.Compile()...) } +// EntryPoint is a build instruction for declaring a container's default +// runtime process. +type EntryPoint struct { + Command []string // command and arguments +} + +// Compile returns the quoted entrypoint command and arguments. +// +func (ep EntryPoint) Compile() []string { + return quoteAll(ep.Command) +} + // Env is a concrete build instruction for declaring a container's runtime // environment variables. // @@ -163,6 +175,19 @@ func (vol Volume) Compile() []string { return []string{quote(vol.Path)} } +// WorkingDirectory is a build instruction for defining the working directory +// for future command and entrypoint instructions. +// +type WorkingDirectory struct { + Path string // working directory path +} + +// Compile returns the quoted working directory path. +// +func (wd WorkingDirectory) Compile() []string { + return []string{quote(wd.Path)} +} + func compileSortedKeyValues(keyValues map[string]string) []string { defs := make([]string, 0, len(keyValues)) names := make([]string, 0, len(keyValues)) diff --git a/build/instructions_test.go b/build/instructions_test.go index f6e3628..29508e2 100644 --- a/build/instructions_test.go +++ b/build/instructions_test.go @@ -48,6 +48,12 @@ func TestCopyFrom(t *testing.T) { assert.Equal(t, []string{"foo", `"source1"`, `"source2"`, `"dest"`}, i.Compile()) } +func TestEntryPoint(t *testing.T) { + i := build.EntryPoint{[]string{"/bin/foo", "bar", "baz"}} + + assert.Equal(t, []string{`"/bin/foo"`, `"bar"`, `"baz"`}, i.Compile()) +} + func TestEnv(t *testing.T) { i := build.Env{map[string]string{ "fooname": "foovalue", @@ -87,3 +93,9 @@ func TestVolume(t *testing.T) { assert.Equal(t, []string{`"/foo/dir"`}, i.Compile()) } + +func TestWorkingDirectory(t *testing.T) { + i := build.WorkingDirectory{"/foo/path"} + + assert.Equal(t, []string{`"/foo/path"`}, i.Compile()) +} diff --git a/build/phases.go b/build/phases.go index 3480927..a656727 100644 --- a/build/phases.go +++ b/build/phases.go @@ -22,3 +22,15 @@ const ( type PhaseCompileable interface { InstructionsForPhase(phase Phase) []Instruction } + +// Phases returns all build phases in the order to be compiled. +// +func Phases() []Phase { + return []Phase{ + PhasePrivileged, + PhasePrivilegeDropped, + PhasePreInstall, + PhaseInstall, + PhasePostInstall, + } +} |