Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 6ea0330

Browse files
committed
add logic control to force recreate
1 parent 5e0b76a commit 6ea0330

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

compose/compose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Test_UpAndDown(t *testing.T) {
4949

5050
ctx := context.Background()
5151

52-
err = deployer.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "")
52+
err = deployer.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "", false)
5353
if err != nil {
5454
t.Fatal(err)
5555
}

compose/internal/composebinary/composebinary.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func NewComposeWrapper(binaryPath, configPath string) (libstack.Deployer, error)
3232
}
3333

3434
// Deploy creates and starts containers
35-
func (wrapper *ComposeWrapper) Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string) error {
36-
output, err := wrapper.Command(newUpCommand(filePaths), workingDir, host, projectName, envFilePath)
35+
func (wrapper *ComposeWrapper) Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string, forceRereate bool) error {
36+
output, err := wrapper.Command(newUpCommand(filePaths, forceRereate), workingDir, host, projectName, envFilePath)
3737
if len(output) != 0 {
3838
log.Printf("[libstack,composebinary] [message: finish deploying] [output: %s] [err: %s]", output, err)
3939
}
@@ -114,8 +114,13 @@ func newCommand(command []string, filePaths []string) composeCommand {
114114
}
115115
}
116116

117-
func newUpCommand(filePaths []string) composeCommand {
118-
return newCommand([]string{"up", "-d", "--force-recreate"}, filePaths)
117+
func newUpCommand(filePaths []string, forceRereate bool) composeCommand {
118+
args := []string{"up", "-d"}
119+
//set `--force-recreate` flag if forceRereate param is true
120+
if forceRereate {
121+
args = append(args, "--force-recreate")
122+
}
123+
return newCommand(args, filePaths)
119124
}
120125

121126
func newDownCommand(filePaths []string) composeCommand {

compose/internal/composebinary/composebinary_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ services:
7979
}
8080

8181
ctx := context.Background()
82-
err = w.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "")
82+
err = w.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "", false)
8383
if err != nil {
8484
t.Fatal(err)
8585
}

compose/internal/composeplugin/composeplugin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func NewPluginWrapper(binaryPath, configPath string) (libstack.Deployer, error)
6262
}
6363

6464
// Up create and start containers
65-
func (wrapper *PluginWrapper) Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string) error {
66-
output, err := wrapper.command(newUpCommand(filePaths), workingDir, host, projectName, envFilePath)
65+
func (wrapper *PluginWrapper) Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string, forceRereate bool) error {
66+
output, err := wrapper.command(newUpCommand(filePaths, forceRereate), workingDir, host, projectName, envFilePath)
6767
if len(output) != 0 {
6868
log.Printf("[libstack,composebinary] [message: finish deploying] [output: %s] [err: %s]", output, err)
6969
}
@@ -91,7 +91,6 @@ func (wrapper *PluginWrapper) Pull(ctx context.Context, workingDir, host, projec
9191
return err
9292
}
9393

94-
9594
// Command exectue a docker-compose commanåd
9695
func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, projectName, envFilePath string) ([]byte, error) {
9796
program := utils.ProgramPath(wrapper.binaryPath, "docker")
@@ -149,7 +148,7 @@ func newCommand(command []string, filePaths []string) composeCommand {
149148
}
150149
}
151150

152-
func newUpCommand(filePaths []string) composeCommand {
151+
func newUpCommand(filePaths []string, forceRereate bool) composeCommand {
153152
return newCommand([]string{"up", "-d"}, filePaths)
154153
}
155154

compose/internal/composeplugin/composeplugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ services:
7979
}
8080

8181
ctx := context.Background()
82-
err = w.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "")
82+
err = w.Deploy(ctx, "", "", "test1", []string{filePathOriginal, filePathOverride}, "", false)
8383
if err != nil {
8484
t.Fatal(err)
8585
}

libstack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
type Deployer interface {
8-
Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string) error
8+
Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string, forceRereate bool) error
99
Remove(ctx context.Context, workingDir, host, projectName string, filePaths []string) error
1010
Pull(ctx context.Context, workingDir, host, projectName string, filePaths []string) error
1111
}

0 commit comments

Comments
 (0)