Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 4298aee

Browse files
committed
Merge pull request #123 from vdemeester/carry-pr-58
Carry #58 : Add support build no cache
2 parents f712c90 + 356b18a commit 4298aee

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

cli/command/command.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func BuildCommand(factory app.ProjectFactory) cli.Command {
2121
Name: "build",
2222
Usage: "Build or rebuild services.",
2323
Action: app.WithProject(factory, app.ProjectBuild),
24+
Flags: []cli.Flag{
25+
cli.BoolFlag{
26+
Name: "no-cache",
27+
Usage: "Do not use cache when building the image",
28+
},
29+
},
2430
}
2531
}
2632

@@ -243,5 +249,7 @@ func Populate(context *project.Context, c *cli.Context) {
243249
context.Signal = c.Int("signal")
244250
} else if c.Command.Name == "rm" {
245251
context.Volume = c.Bool("v")
252+
} else if c.Command.Name == "build" {
253+
context.NoCache = c.Bool("no-cache")
246254
}
247255
}

docker/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (d *DaemonBuilder) Build(p *project.Project, service project.Service) (stri
6363
Name: tag,
6464
RmTmpContainer: true,
6565
Dockerfile: service.Config().Dockerfile,
66+
NoCache: d.context.NoCache,
6667
})
6768

6869
if err != nil {

integration/build_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7+
"strings"
78

89
. "gopkg.in/check.v1"
910
)
@@ -30,3 +31,58 @@ func (s *RunSuite) TestBuild(c *C) {
3031
c.Assert(err, IsNil)
3132
c.Assert(two.Config.Cmd, DeepEquals, []string{"echo", "two"})
3233
}
34+
35+
func (s *RunSuite) TestBuildWithNoCache1(c *C) {
36+
p := s.RandomProject()
37+
cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
38+
39+
output, err := cmd.Output()
40+
c.Assert(err, IsNil)
41+
42+
cmd = exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
43+
output, err = cmd.Output()
44+
c.Assert(err, IsNil)
45+
out := string(output[:])
46+
c.Assert(strings.Contains(out,
47+
"Using cache"),
48+
Equals, true, Commentf("%s", out))
49+
}
50+
51+
func (s *RunSuite) TestBuildWithNoCache2(c *C) {
52+
p := s.RandomProject()
53+
cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build")
54+
55+
output, err := cmd.Output()
56+
c.Assert(err, IsNil)
57+
58+
cmd = exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build", "--no-cache")
59+
output, err = cmd.Output()
60+
c.Assert(err, IsNil)
61+
out := string(output[:])
62+
c.Assert(strings.Contains(out,
63+
"Using cache"),
64+
Equals, false, Commentf("%s", out))
65+
}
66+
67+
func (s *RunSuite) TestBuildWithNoCache3(c *C) {
68+
p := s.RandomProject()
69+
cmd := exec.Command(s.command, "-f", "./assets/build/docker-compose.yml", "-p", p, "build", "--no-cache")
70+
cmd.Stdout = os.Stdout
71+
cmd.Stderr = os.Stderr
72+
cmd.Stdin = os.Stdin
73+
err := cmd.Run()
74+
75+
oneImageName := fmt.Sprintf("%s_one", p)
76+
twoImageName := fmt.Sprintf("%s_two", p)
77+
78+
c.Assert(err, IsNil)
79+
80+
client := GetClient(c)
81+
one, err := client.InspectImage(oneImageName)
82+
c.Assert(err, IsNil)
83+
c.Assert(one.Config.Cmd, DeepEquals, []string{"echo", "one"})
84+
85+
two, err := client.InspectImage(twoImageName)
86+
c.Assert(err, IsNil)
87+
c.Assert(two.Config.Cmd, DeepEquals, []string{"echo", "two"})
88+
}

project/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Context struct {
2323
Volume bool
2424
ForceRecreate bool
2525
NoRecreate bool
26+
NoCache bool
2627
Signal int
2728
ComposeFile string
2829
ComposeBytes []byte

0 commit comments

Comments
 (0)