diff options
author | Dan Duvall <dduvall@wikimedia.org> | 2017-05-09 09:54:09 -0700 |
---|---|---|
committer | Dan Duvall <dduvall@wikimedia.org> | 2017-05-10 20:41:09 -0700 |
commit | fb363428ed0e4bcbe7aee83f70a34981f4f092c0 (patch) | |
tree | 869706acf2182cd41c5d7bf4b4f98b1635086362 /docker | |
parent | d0ada7682fa323c52940c99113a8809aecfae06b (diff) | |
download | blubber-fb363428ed0e4bcbe7aee83f70a34981f4f092c0.tar.gz |
Decouple Docker compiler from apt/npm providers
Establish phases within Docker compiler to allow providers (apt, npm,
etc.) to inject their own run/copy instructions into to the Dockerfile
compilation process while leaving the compiler agnostic to the providers
themselves.
The instructions and phases are also generalized to leave room for
alternative compilers should they be needed in the future (e.g. aci
support via acbuild) but also as a general design constraint to leave
compiler implementation concerns out of providers.
Diffstat (limited to 'docker')
-rw-r--r-- | docker/compiler.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/docker/compiler.go b/docker/compiler.go index f5114c4..6b08355 100644 --- a/docker/compiler.go +++ b/docker/compiler.go @@ -3,6 +3,7 @@ package docker import ( "bytes" "strings" + "github.com/marxarelli/blubber/build" "github.com/marxarelli/blubber/config" ) @@ -33,26 +34,27 @@ func CompileStage(buffer *bytes.Buffer, stage string, vcfg *config.VariantConfig Writeln(buffer, "FROM ", vcfg.Base, " AS ", stage) Writeln(buffer, "USER root") - Writeln(buffer, "WORKDIR /srv") - CompileToCommands(buffer, vcfg.Apt) - CompileToCommands(buffer, vcfg.Runs) + + CompilePhase(buffer, vcfg, build.PhasePrivileged) if vcfg.Runs.As != "" { Writeln(buffer, "USER ", vcfg.Runs.As) } + CompilePhase(buffer, vcfg, build.PhasePrivilegeDropped) + if vcfg.Runs.In != "" { Writeln(buffer, "WORKDIR ", vcfg.Runs.In) } + CompilePhase(buffer, vcfg, build.PhasePreInstall) + if vcfg.SharedVolume { Writeln(buffer, "VOLUME [\"", vcfg.Runs.In, "\"]") } else { Writeln(buffer, "COPY . \"", vcfg.Runs.In, "\"") } - CompileToCommands(buffer, vcfg.Npm) - // Artifact copying for _, artifact := range vcfg.Artifacts { Write(buffer, "COPY ") @@ -64,14 +66,25 @@ func CompileStage(buffer *bytes.Buffer, stage string, vcfg *config.VariantConfig Writeln(buffer, artifact.Source, " ", artifact.Destination) } + CompilePhase(buffer, vcfg, build.PhasePostInstall) + if len(vcfg.EntryPoint) > 0 { Writeln(buffer, "ENTRYPOINT [\"", strings.Join(vcfg.EntryPoint, "\", \""), "\"]") } } -func CompileToCommands(buffer *bytes.Buffer, compileable config.CommandCompileable) { - for _, command := range compileable.Commands() { - Writeln(buffer, "RUN ", command) +func CompilePhase(buffer *bytes.Buffer, vcfg *config.VariantConfig, phase build.Phase) { + for _, instruction := range vcfg.InstructionsForPhase(phase) { + CompileInstruction(buffer, instruction) + } +} + +func CompileInstruction(buffer *bytes.Buffer, instruction build.Instruction) { + switch instruction.Type { + case build.Run: + Writeln(buffer, append([]string{"RUN "}, instruction.Arguments...)...) + case build.Copy: + Writeln(buffer, "COPY \"", instruction.Arguments[0], "\" \"", instruction.Arguments[1], "\"") } } |