@@ -26,11 +26,12 @@ type buildFile struct {
2626 builder * Builder
2727 srv * Server
2828
29- image string
30- maintainer string
31- config * Config
32- context string
33- verbose bool
29+ image string
30+ maintainer string
31+ config * Config
32+ context string
33+ verbose bool
34+ utilizeCache bool
3435
3536 tmpContainers map [string ]struct {}
3637 tmpImages map [string ]struct {}
@@ -92,17 +93,21 @@ func (b *buildFile) CmdRun(args string) error {
9293 b .config .Cmd = nil
9394 MergeConfig (b .config , config )
9495
96+ defer func (cmd []string ) { b .config .Cmd = cmd }(cmd )
97+
9598 utils .Debugf ("Command to be executed: %v" , b .config .Cmd )
9699
97- if cache , err := b .srv .ImageGetCached (b .image , b .config ); err != nil {
98- return err
99- } else if cache != nil {
100- fmt .Fprintf (b .out , " ---> Using cache\n " )
101- utils .Debugf ("[BUILDER] Use cached version" )
102- b .image = cache .ID
103- return nil
104- } else {
105- utils .Debugf ("[BUILDER] Cache miss" )
100+ if b .utilizeCache {
101+ if cache , err := b .srv .ImageGetCached (b .image , b .config ); err != nil {
102+ return err
103+ } else if cache != nil {
104+ fmt .Fprintf (b .out , " ---> Using cache\n " )
105+ utils .Debugf ("[BUILDER] Use cached version" )
106+ b .image = cache .ID
107+ return nil
108+ } else {
109+ utils .Debugf ("[BUILDER] Cache miss" )
110+ }
106111 }
107112
108113 cid , err := b .run ()
@@ -112,7 +117,7 @@ func (b *buildFile) CmdRun(args string) error {
112117 if err := b .commit (cid , cmd , "run" ); err != nil {
113118 return err
114119 }
115- b . config . Cmd = cmd
120+
116121 return nil
117122}
118123
@@ -397,16 +402,19 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
397402 b .config .Cmd = []string {"/bin/sh" , "-c" , "#(nop) " + comment }
398403 defer func (cmd []string ) { b .config .Cmd = cmd }(cmd )
399404
400- if cache , err := b .srv .ImageGetCached (b .image , b .config ); err != nil {
401- return err
402- } else if cache != nil {
403- fmt .Fprintf (b .out , " ---> Using cache\n " )
404- utils .Debugf ("[BUILDER] Use cached version" )
405- b .image = cache .ID
406- return nil
407- } else {
408- utils .Debugf ("[BUILDER] Cache miss" )
405+ if b .utilizeCache {
406+ if cache , err := b .srv .ImageGetCached (b .image , b .config ); err != nil {
407+ return err
408+ } else if cache != nil {
409+ fmt .Fprintf (b .out , " ---> Using cache\n " )
410+ utils .Debugf ("[BUILDER] Use cached version" )
411+ b .image = cache .ID
412+ return nil
413+ } else {
414+ utils .Debugf ("[BUILDER] Cache miss" )
415+ }
409416 }
417+
410418 container , err := b .builder .Create (b .config )
411419 if err != nil {
412420 return err
@@ -500,7 +508,7 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
500508 return "" , fmt .Errorf ("An error occured during the build\n " )
501509}
502510
503- func NewBuildFile (srv * Server , out io.Writer , verbose bool ) BuildFile {
511+ func NewBuildFile (srv * Server , out io.Writer , verbose , utilizeCache bool ) BuildFile {
504512 return & buildFile {
505513 builder : NewBuilder (srv .runtime ),
506514 runtime : srv .runtime ,
@@ -510,5 +518,6 @@ func NewBuildFile(srv *Server, out io.Writer, verbose bool) BuildFile {
510518 tmpContainers : make (map [string ]struct {}),
511519 tmpImages : make (map [string ]struct {}),
512520 verbose : verbose ,
521+ utilizeCache : utilizeCache ,
513522 }
514523}
0 commit comments