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

Commit 6ef40dd

Browse files
committed
--build option for up command
Added --build option for `up` command Partial fix for #207 Signed-off-by: Kunal Kushwaha <[email protected]>
1 parent e1a83f7 commit 6ef40dd

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

cli/app/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func ProjectUp(p project.APIProject, c *cli.Context) error {
137137
NoRecreate: c.Bool("no-recreate"),
138138
ForceRecreate: c.Bool("force-recreate"),
139139
NoBuild: c.Bool("no-build"),
140+
ForceBuild: c.Bool("build"),
140141
},
141142
}
142143
ctx, cancelFun := context.WithCancel(context.Background())

cli/command/command.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func UpCommand(factory app.ProjectFactory) cli.Command {
127127
Name: "force-recreate",
128128
Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
129129
},
130+
cli.BoolFlag{
131+
Name: "build",
132+
Usage: "Build images before starting containers.",
133+
},
130134
},
131135
}
132136
}

docker/service.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *Service) Create(ctx context.Context, options options.Create) error {
7373
return err
7474
}
7575

76-
if err := s.ensureImageExists(ctx, options.NoBuild); err != nil {
76+
if err := s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil {
7777
return err
7878
}
7979

@@ -132,7 +132,11 @@ func (s *Service) collectContainers(ctx context.Context) ([]*Container, error) {
132132
return result, nil
133133
}
134134

135-
func (s *Service) ensureImageExists(ctx context.Context, noBuild bool) error {
135+
func (s *Service) ensureImageExists(ctx context.Context, noBuild bool, forceBuild bool) error {
136+
if forceBuild {
137+
return s.build(ctx, options.Build{})
138+
}
139+
136140
exists, err := s.ImageExists(ctx)
137141
if err != nil {
138142
return err
@@ -243,7 +247,7 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
243247

244248
var imageName = s.imageName()
245249
if len(containers) == 0 || !options.NoRecreate {
246-
if err = s.ensureImageExists(ctx, options.NoBuild); err != nil {
250+
if err = s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil {
247251
return err
248252
}
249253
}
@@ -254,7 +258,7 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
254258
// Run implements Service.Run. It runs a one of command within the service container.
255259
// It always create a new container.
256260
func (s *Service) Run(ctx context.Context, commandParts []string, options options.Run) (int, error) {
257-
err := s.ensureImageExists(ctx, false)
261+
err := s.ensureImageExists(ctx, false, false)
258262
if err != nil {
259263
return -1, err
260264
}
@@ -608,7 +612,7 @@ func (s *Service) Scale(ctx context.Context, scale int, timeout int) error {
608612
}
609613

610614
if len(containers) < scale {
611-
err := s.ensureImageExists(ctx, false)
615+
err := s.ensureImageExists(ctx, false, false)
612616
if err != nil {
613617
return err
614618
}

project/options/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Create struct {
2525
NoRecreate bool
2626
ForceRecreate bool
2727
NoBuild bool
28-
// ForceBuild bool
28+
ForceBuild bool
2929
}
3030

3131
// Run holds options of compose run.

0 commit comments

Comments
 (0)