@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/docker/app/internal"
16
16
"github.com/docker/app/internal/compose"
17
+ "github.com/docker/app/internal/validator"
17
18
"github.com/docker/app/internal/yaml"
18
19
"github.com/docker/app/types"
19
20
"github.com/docker/app/types/metadata"
@@ -49,6 +50,11 @@ func Init(errWriter io.Writer, name string, composeFile string) (string, error)
49
50
if composeFile == "" {
50
51
err = initFromScratch (name )
51
52
} else {
53
+ v := validator .NewValidatorWithDefaults ()
54
+ err = v .Validate (composeFile )
55
+ if err != nil {
56
+ return "" , err
57
+ }
52
58
err = initFromComposeFile (errWriter , name , composeFile )
53
59
}
54
60
if err != nil {
@@ -82,11 +88,11 @@ func checkComposeFileVersion(compose map[string]interface{}) error {
82
88
83
89
func getEnvFiles (svcName string , envFileEntry interface {}) ([]string , error ) {
84
90
var envFiles []string
85
- switch envFileEntry .(type ) {
91
+ switch envFileEntry := envFileEntry .(type ) {
86
92
case string :
87
- envFiles = append (envFiles , envFileEntry .( string ) )
93
+ envFiles = append (envFiles , envFileEntry )
88
94
case []interface {}:
89
- for _ , env := range envFileEntry .([] interface {}) {
95
+ for _ , env := range envFileEntry {
90
96
envFiles = append (envFiles , env .(string ))
91
97
}
92
98
default :
@@ -125,50 +131,6 @@ func checkEnvFiles(errWriter io.Writer, appName string, cfgMap map[string]interf
125
131
return nil
126
132
}
127
133
128
- func checkRelativePaths (cfgMap map [string ]interface {}) error {
129
- services := cfgMap ["services" ]
130
- servicesMap , ok := services .(map [string ]interface {})
131
- if ! ok {
132
- return fmt .Errorf ("invalid Compose file" )
133
- }
134
- for svcName , svc := range servicesMap {
135
- svcContent , ok := svc .(map [string ]interface {})
136
- if ! ok {
137
- return fmt .Errorf ("invalid service %q" , svcName )
138
- }
139
- v , ok := svcContent ["volumes" ]
140
- if ! ok {
141
- continue
142
- }
143
- volumes , ok := v .([]interface {})
144
- if ! ok {
145
- return fmt .Errorf ("invalid Compose file" )
146
- }
147
- for _ , volume := range volumes {
148
- switch volume .(type ) {
149
- case string :
150
- svol := volume .(string )
151
- source := strings .TrimRight (svol , ":" )
152
- if ! filepath .IsAbs (source ) {
153
- return fmt .Errorf ("invalid service %q: can't use relative path as volume source" , svcName )
154
- }
155
- case map [string ]interface {}:
156
- lvol := volume .(map [string ]interface {})
157
- src , ok := lvol ["source" ]
158
- if ! ok {
159
- return fmt .Errorf ("invalid volume in service %q" , svcName )
160
- }
161
- if ! filepath .IsAbs (src .(string )) {
162
- return fmt .Errorf ("invalid service %q: can't use relative path as volume source" , svcName )
163
- }
164
- default :
165
- return fmt .Errorf ("invalid Compose file" )
166
- }
167
- }
168
- }
169
- return nil
170
- }
171
-
172
134
func getParamsFromDefaultEnvFile (composeFile string , composeRaw []byte ) (map [string ]string , bool , error ) {
173
135
params := make (map [string ]string )
174
136
envs , err := opts .ParseEnvFile (filepath .Join (filepath .Dir (composeFile ), ".env" ))
@@ -217,9 +179,6 @@ func initFromComposeFile(errWriter io.Writer, name string, composeFile string) e
217
179
if err := checkEnvFiles (errWriter , name , cfgMap ); err != nil {
218
180
return err
219
181
}
220
- if err := checkRelativePaths (cfgMap ); err != nil {
221
- return err
222
- }
223
182
params , needsFilling , err := getParamsFromDefaultEnvFile (composeFile , composeRaw )
224
183
if err != nil {
225
184
return err
0 commit comments