Compare commits

...

3 Commits

Author SHA1 Message Date
Chaim Lev-Ari
ff330ccf40 chore(libstack): add debug info 2024-01-23 10:10:12 +02:00
hookenz
1371316d23 remove debug 2024-01-23 09:44:37 +02:00
Matt Hook
2741972041 support docker compose run 2024-01-23 09:44:37 +02:00
2 changed files with 51 additions and 3 deletions

View File

@@ -55,6 +55,27 @@ func (wrapper *PluginWrapper) Deploy(ctx context.Context, filePaths []string, op
return err
}
func (wrapper *PluginWrapper) Run(ctx context.Context, filePaths []string, serviceName string, options libstack.RunOptions) error {
output, err := wrapper.command(newRunCommand(filePaths, serviceName, runOptions{
remove: options.Remove,
args: options.Args,
}), options.Options)
if len(output) != 0 {
if err != nil {
return err
}
log.Info().Msg("Stack run successful")
log.Debug().
Str("output", string(output)).
Msg("docker compose")
}
return err
}
// Down stop and remove containers
func (wrapper *PluginWrapper) Remove(ctx context.Context, projectName string, filePaths []string, options libstack.Options) error {
output, err := wrapper.command(newDownCommand(projectName, filePaths), options)
@@ -145,10 +166,9 @@ func (wrapper *PluginWrapper) command(command composeCommand, options libstack.O
cmd.Env = append(cmd.Env, options.Env...)
log.Debug().
Str("command", program).
Strs("args", args).
Str("command", cmd.String()).
Interface("env", cmd.Env).
Msg("run command")
Msg("execute command")
cmd.Stderr = &stderr
@@ -156,6 +176,7 @@ func (wrapper *PluginWrapper) command(command composeCommand, options libstack.O
if err != nil {
errOutput := stderr.String()
log.Warn().
Str("command", cmd.String()).
Str("output", string(output)).
Str("error_output", errOutput).
Err(err).
@@ -208,6 +229,24 @@ func newUpCommand(filePaths []string, options upOptions) composeCommand {
return newCommand(args, filePaths)
}
type runOptions struct {
remove bool
args []string
}
func newRunCommand(filePaths []string, serviceName string, options runOptions) composeCommand {
args := []string{"run"}
if options.remove {
args = append(args, "--rm")
}
args = append(args, serviceName)
args = append(args, options.args...)
return newCommand(args, filePaths)
}
func newDownCommand(projectName string, filePaths []string) composeCommand {
cmd := newCommand([]string{"down", "--remove-orphans"}, filePaths)
cmd.WithProjectName(projectName)

View File

@@ -6,6 +6,7 @@ import (
type Deployer interface {
Deploy(ctx context.Context, filePaths []string, options DeployOptions) error
Run(ctx context.Context, filePaths []string, serviceName string, options RunOptions) error
// Remove stops and removes containers
//
// projectName or filePaths are required
@@ -47,3 +48,11 @@ type DeployOptions struct {
// When this is set, docker compose will output its logs to stdout
AbortOnContainerExit bool ``
}
type RunOptions struct {
Options
// Automatically remove the container when it exits
Remove bool
// A list of arguments to pass to the container
Args []string
}