@@ -4,11 +4,13 @@ import (
44 "fmt"
55 "os"
66
7+ "github.com/docker/app/internal/compose"
78 "github.com/docker/app/internal/packager"
89 "github.com/docker/app/render"
910 "github.com/docker/app/types"
1011 "github.com/docker/cli/cli"
1112 cliopts "github.com/docker/cli/opts"
13+ "github.com/pkg/errors"
1214 "github.com/spf13/cobra"
1315)
1416
@@ -23,22 +25,37 @@ func validateCmd() *cobra.Command {
2325 Short : "Checks the rendered application is syntactically correct" ,
2426 Args : cli .RequiresMaxArgs (1 ),
2527 RunE : func (cmd * cobra.Command , args []string ) error {
26- app , err := packager .Extract (firstOrEmpty (args ),
27- types .WithParametersFiles (opts .parametersFiles ... ),
28- )
29- if err != nil {
30- return err
31- }
32- defer app .Cleanup ()
33- argParameters := cliopts .ConvertKVStringsToMap (opts .overrides )
34- _ , err = render .Render (app , argParameters , nil )
35- if err != nil {
36- return err
37- }
38- fmt .Fprintf (os .Stdout , "Validated %q\n " , app .Path )
39- return nil
28+ return runValidate (args , opts )
4029 },
4130 }
4231 opts .parametersOptions .addFlags (cmd .Flags ())
4332 return cmd
4433}
34+
35+ func runValidate (args []string , opts validateOptions ) error {
36+ app , err := packager .Extract (firstOrEmpty (args ),
37+ types .WithParametersFiles (opts .parametersFiles ... ),
38+ )
39+ if err != nil {
40+ return err
41+ }
42+ defer app .Cleanup ()
43+ argParameters := cliopts .ConvertKVStringsToMap (opts .overrides )
44+ _ , err = render .Render (app , argParameters , nil )
45+ if err != nil {
46+ return err
47+ }
48+
49+ vars , err := compose .ExtractVariables (app .Composes ()[0 ], compose .ExtrapolationPattern )
50+ if err != nil {
51+ return errors .Wrap (err , "failed to parse compose file" )
52+ }
53+ for k := range app .Parameters ().Flatten () {
54+ if _ , ok := vars [k ]; ! ok {
55+ return fmt .Errorf ("%s is declared as parameter but not used by the compose file" , k )
56+ }
57+ }
58+
59+ fmt .Fprintf (os .Stdout , "Validated %q\n " , app .Path )
60+ return nil
61+ }
0 commit comments