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

Commit e292e19

Browse files
authored
Merge pull request #342 from kunalkushwaha/up-force-build
--build option for up command
2 parents e956acf + 6ef40dd commit e292e19

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
@@ -142,6 +142,7 @@ func ProjectUp(p project.APIProject, c *cli.Context) error {
142142
NoRecreate: c.Bool("no-recreate"),
143143
ForceRecreate: c.Bool("force-recreate"),
144144
NoBuild: c.Bool("no-build"),
145+
ForceBuild: c.Bool("build"),
145146
},
146147
}
147148
ctx, cancelFun := context.WithCancel(context.Background())

cli/command/command.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func UpCommand(factory app.ProjectFactory) cli.Command {
136136
Name: "force-recreate",
137137
Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
138138
},
139+
cli.BoolFlag{
140+
Name: "build",
141+
Usage: "Build images before starting containers.",
142+
},
139143
},
140144
}
141145
}

docker/service.go

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

79-
if err := s.ensureImageExists(ctx, options.NoBuild); err != nil {
79+
if err := s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil {
8080
return err
8181
}
8282

@@ -135,7 +135,11 @@ func (s *Service) collectContainers(ctx context.Context) ([]*container.Container
135135
return result, nil
136136
}
137137

138-
func (s *Service) ensureImageExists(ctx context.Context, noBuild bool) error {
138+
func (s *Service) ensureImageExists(ctx context.Context, noBuild bool, forceBuild bool) error {
139+
if forceBuild {
140+
return s.build(ctx, options.Build{})
141+
}
142+
139143
exists, err := s.ImageExists(ctx)
140144
if err != nil {
141145
return err
@@ -247,7 +251,7 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
247251

248252
var imageName = s.imageName()
249253
if len(containers) == 0 || !options.NoRecreate {
250-
if err = s.ensureImageExists(ctx, options.NoBuild); err != nil {
254+
if err = s.ensureImageExists(ctx, options.NoBuild, options.ForceBuild); err != nil {
251255
return err
252256
}
253257
}
@@ -258,7 +262,7 @@ func (s *Service) Up(ctx context.Context, options options.Up) error {
258262
// Run implements Service.Run. It runs a one of command within the service container.
259263
// It always create a new container.
260264
func (s *Service) Run(ctx context.Context, commandParts []string, options options.Run) (int, error) {
261-
err := s.ensureImageExists(ctx, false)
265+
err := s.ensureImageExists(ctx, false, false)
262266
if err != nil {
263267
return -1, err
264268
}
@@ -617,7 +621,7 @@ func (s *Service) Scale(ctx context.Context, scale int, timeout int) error {
617621
}
618622

619623
if len(containers) < scale {
620-
err := s.ensureImageExists(ctx, false)
624+
err := s.ensureImageExists(ctx, false, false)
621625
if err != nil {
622626
return err
623627
}

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)