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

Commit d741077

Browse files
authored
feat(compose): function to validate stack file format [EE-4905] (#32)
* feat: function to validate stack file format * feat(compose): catch potential output on validate
1 parent 1dd2852 commit d741077

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

compose/internal/composeplugin/composeplugin.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ func (wrapper *PluginWrapper) Deploy(ctx context.Context, filePaths []string, op
4444
return err
4545
}
4646

47-
log.Info().
48-
Str("message", "Stack deployment successful")
47+
log.Info().Msg("Stack deployment successful")
4948

5049
log.Debug().
5150
Str("output", string(output)).
@@ -63,8 +62,7 @@ func (wrapper *PluginWrapper) Remove(ctx context.Context, filePaths []string, op
6362
return err
6463
}
6564

66-
log.Info().
67-
Str("message", "Stack removal successful")
65+
log.Info().Msg("Stack removal successful")
6866

6967
log.Debug().
7068
Str("output", string(output)).
@@ -83,8 +81,7 @@ func (wrapper *PluginWrapper) Pull(ctx context.Context, filePaths []string, opti
8381
return err
8482
}
8583

86-
log.Info().
87-
Str("message", "Stack pull successful")
84+
log.Info().Msg("Stack pull successful")
8885

8986
log.Debug().
9087
Str("output", string(output)).
@@ -94,6 +91,24 @@ func (wrapper *PluginWrapper) Pull(ctx context.Context, filePaths []string, opti
9491
return err
9592
}
9693

94+
// Validate stack file
95+
func (wrapper *PluginWrapper) Validate(ctx context.Context, filePaths []string, options libstack.Options) error {
96+
output, err := wrapper.command(newValidateCommand(filePaths), options)
97+
if len(output) != 0 {
98+
if err != nil {
99+
return err
100+
}
101+
102+
log.Info().Msg("Valid stack format")
103+
104+
log.Debug().
105+
Str("output", string(output)).
106+
Msg("docker compose")
107+
}
108+
109+
return nil
110+
}
111+
97112
// Command execute a docker-compose command
98113
func (wrapper *PluginWrapper) command(command composeCommand, options libstack.Options) ([]byte, error) {
99114
program := utils.ProgramPath(wrapper.binaryPath, "docker-compose")
@@ -196,6 +211,10 @@ func newPullCommand(filePaths []string) composeCommand {
196211
return newCommand([]string{"pull"}, filePaths)
197212
}
198213

214+
func newValidateCommand(filePaths []string) composeCommand {
215+
return newCommand([]string{"config", "--quiet"}, filePaths)
216+
}
217+
199218
func (command *composeCommand) WithHost(host string) {
200219
// prepend compatibility flags such as this one as they must appear before the
201220
// regular global args otherwise docker-compose will throw an error

libstack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Deployer interface {
88
Deploy(ctx context.Context, filePaths []string, options DeployOptions) error
99
Remove(ctx context.Context, filePaths []string, options Options) error
1010
Pull(ctx context.Context, filePaths []string, options Options) error
11+
Validate(ctx context.Context, filePaths []string, options Options) error
1112
}
1213

1314
type Options struct {

0 commit comments

Comments
 (0)