|
|
|
@ -44,19 +44,26 @@ func NewSwarmStackManager(binaryPath, configPath string, signatureService portai
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Login executes the docker login command against a list of registries (including DockerHub).
|
|
|
|
|
func (manager *SwarmStackManager) Login(registries []portainer.Registry, endpoint *portainer.Endpoint) {
|
|
|
|
|
command, args := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
func (manager *SwarmStackManager) Login(registries []portainer.Registry, endpoint *portainer.Endpoint) error {
|
|
|
|
|
command, args, err := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
for _, registry := range registries {
|
|
|
|
|
if registry.Authentication {
|
|
|
|
|
registryArgs := append(args, "login", "--username", registry.Username, "--password", registry.Password, registry.URL)
|
|
|
|
|
runCommandAndCaptureStdErr(command, registryArgs, nil, "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Logout executes the docker logout command.
|
|
|
|
|
func (manager *SwarmStackManager) Logout(endpoint *portainer.Endpoint) error {
|
|
|
|
|
command, args := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
command, args, err := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
args = append(args, "logout")
|
|
|
|
|
return runCommandAndCaptureStdErr(command, args, nil, "")
|
|
|
|
|
}
|
|
|
|
@ -64,7 +71,10 @@ func (manager *SwarmStackManager) Logout(endpoint *portainer.Endpoint) error {
|
|
|
|
|
// Deploy executes the docker stack deploy command.
|
|
|
|
|
func (manager *SwarmStackManager) Deploy(stack *portainer.Stack, prune bool, endpoint *portainer.Endpoint) error {
|
|
|
|
|
filePaths := stackutils.GetStackFilePaths(stack)
|
|
|
|
|
command, args := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
command, args, err := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if prune {
|
|
|
|
|
args = append(args, "stack", "deploy", "--prune", "--with-registry-auth")
|
|
|
|
@ -84,7 +94,10 @@ func (manager *SwarmStackManager) Deploy(stack *portainer.Stack, prune bool, end
|
|
|
|
|
|
|
|
|
|
// Remove executes the docker stack rm command.
|
|
|
|
|
func (manager *SwarmStackManager) Remove(stack *portainer.Stack, endpoint *portainer.Endpoint) error {
|
|
|
|
|
command, args := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
command, args, err := manager.prepareDockerCommandAndArgs(manager.binaryPath, manager.configPath, endpoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
args = append(args, "stack", "rm", stack.Name)
|
|
|
|
|
return runCommandAndCaptureStdErr(command, args, nil, "")
|
|
|
|
|
}
|
|
|
|
@ -108,7 +121,7 @@ func runCommandAndCaptureStdErr(command string, args []string, env []string, wor
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (manager *SwarmStackManager) prepareDockerCommandAndArgs(binaryPath, configPath string, endpoint *portainer.Endpoint) (string, []string) {
|
|
|
|
|
func (manager *SwarmStackManager) prepareDockerCommandAndArgs(binaryPath, configPath string, endpoint *portainer.Endpoint) (string, []string, error) {
|
|
|
|
|
// Assume Linux as a default
|
|
|
|
|
command := path.Join(binaryPath, "docker")
|
|
|
|
|
|
|
|
|
@ -121,7 +134,10 @@ func (manager *SwarmStackManager) prepareDockerCommandAndArgs(binaryPath, config
|
|
|
|
|
|
|
|
|
|
endpointURL := endpoint.URL
|
|
|
|
|
if endpoint.Type == portainer.EdgeAgentOnDockerEnvironment {
|
|
|
|
|
tunnel := manager.reverseTunnelService.GetTunnelDetails(endpoint.ID)
|
|
|
|
|
tunnel, err := manager.reverseTunnelService.GetActiveTunnel(endpoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", nil, err
|
|
|
|
|
}
|
|
|
|
|
endpointURL = fmt.Sprintf("tcp://127.0.0.1:%d", tunnel.Port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,7 +157,7 @@ func (manager *SwarmStackManager) prepareDockerCommandAndArgs(binaryPath, config
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return command, args
|
|
|
|
|
return command, args, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (manager *SwarmStackManager) updateDockerCLIConfiguration(configPath string) error {
|
|
|
|
|