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

Commit 5e0b76a

Browse files
author
Hao Zhang
authored
Merge pull request #16 from portainer/feat/EE-1332/pull-image-when-redeploy-stack
feat:(image): support pull image EE-1332
2 parents 10a04c9 + 0d07a7f commit 5e0b76a

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

compose/internal/composebinary/composebinary.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ func (wrapper *ComposeWrapper) Remove(ctx context.Context, workingDir, host, pro
5151
return err
5252
}
5353

54+
// Pull an image associated with a service defined in a docker-compose.yml or docker-stack.yml file,
55+
// but does not start containers based on those images.
56+
func (wrapper *ComposeWrapper) Pull(ctx context.Context, workingDir, host, projectName string, filePaths []string) error {
57+
output, err := wrapper.Command(newPullCommand(filePaths), workingDir, host, projectName, "")
58+
if len(output) != 0 {
59+
log.Printf("[libstack,composebinary] [message: finish deploying] [output: %s] [err: %s]", output, err)
60+
}
61+
62+
return err
63+
}
64+
5465
// Command executes a docker-compose command
5566
func (wrapper *ComposeWrapper) Command(command composeCommand, workingDir, host, projectName, envFilePath string) ([]byte, error) {
5667
program := utils.ProgramPath(wrapper.binaryPath, "docker-compose")
@@ -111,6 +122,10 @@ func newDownCommand(filePaths []string) composeCommand {
111122
return newCommand([]string{"down", "--remove-orphans"}, filePaths)
112123
}
113124

125+
func newPullCommand(filePaths []string) composeCommand {
126+
return newCommand([]string{"pull"}, filePaths)
127+
}
128+
114129
func (command *composeCommand) WithProjectName(projectName string) {
115130
command.args = append(command.args, "-p", projectName)
116131
}

compose/internal/composeplugin/composeplugin.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ func (wrapper *PluginWrapper) Remove(ctx context.Context, workingDir, host, proj
8181
return err
8282
}
8383

84+
// Pull images
85+
func (wrapper *PluginWrapper) Pull(ctx context.Context, workingDir, host, projectName string, filePaths []string) error {
86+
output, err := wrapper.command(newPullCommand(filePaths), workingDir, host, projectName, "")
87+
if len(output) != 0 {
88+
log.Printf("[libstack,composebinary] [message: finish pulling] [output: %s] [err: %s]", output, err)
89+
}
90+
91+
return err
92+
}
93+
94+
8495
// Command exectue a docker-compose commanåd
8596
func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, projectName, envFilePath string) ([]byte, error) {
8697
program := utils.ProgramPath(wrapper.binaryPath, "docker")
@@ -146,6 +157,10 @@ func newDownCommand(filePaths []string) composeCommand {
146157
return newCommand([]string{"down", "--remove-orphans"}, filePaths)
147158
}
148159

160+
func newPullCommand(filePaths []string) composeCommand {
161+
return newCommand([]string{"pull"}, filePaths)
162+
}
163+
149164
func (command *composeCommand) WithConfigPath(configPath string) {
150165
command.args = append(command.args, "--config", configPath)
151166
}

libstack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import (
77
type Deployer interface {
88
Deploy(ctx context.Context, workingDir, host, projectName string, filePaths []string, envFilePath string) error
99
Remove(ctx context.Context, workingDir, host, projectName string, filePaths []string) error
10+
Pull(ctx context.Context, workingDir, host, projectName string, filePaths []string) error
1011
}

0 commit comments

Comments
 (0)