Also give all compose generated objects a label via the template.
Clayton Coleman authored on 2016/05/13 06:41:15... | ... |
@@ -148,6 +148,10 @@ func (o *DockerComposeOptions) Run() error { |
148 | 148 |
return err |
149 | 149 |
} |
150 | 150 |
|
151 |
+ template.ObjectLabels = map[string]string{ |
|
152 |
+ "compose": template.Name, |
|
153 |
+ } |
|
154 |
+ |
|
151 | 155 |
// all the types generated into the template should be known |
152 | 156 |
if errs := app.AsVersionedObjects(template.Objects, kapi.Scheme, kapi.Scheme, o.OutputVersions...); len(errs) > 0 { |
153 | 157 |
for _, err := range errs { |
... | ... |
@@ -237,6 +237,7 @@ func Generate(paths ...string) (*templateapi.Template, error) { |
237 | 237 |
commonMounts := make(map[string]string) |
238 | 238 |
for _, k := range pod.List() { |
239 | 239 |
v := p.Configs[k] |
240 |
+ glog.V(4).Infof("compose service: %#v", v) |
|
240 | 241 |
var inputImage *app.ImageRef |
241 | 242 |
if len(v.Image) != 0 { |
242 | 243 |
image, err := g.FromName(v.Image) |
... | ... |
@@ -206,6 +206,9 @@ os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app- |
206 | 206 |
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o name --as-template=other --dry-run' 'template/other' |
207 | 207 |
os::cmd::expect_failure 'diff --suppress-common-lines -y <(oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o yaml) test/fixtures/app-scenarios/docker-compose/complex/docker-compose.imported.yaml | grep -v secret' |
208 | 208 |
|
209 |
+# verify a docker-compose.yml schema 2 resource can be transformed, and that it sets env vars correctly. |
|
210 |
+os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/wordpress/docker-compose.yml -o yaml --as-template=other --dry-run' 'value: wordpress' |
|
211 |
+ |
|
209 | 212 |
# check new-build |
210 | 213 |
os::cmd::expect_failure_and_text 'oc new-build mysql -o yaml' 'you must specify at least one source repository URL' |
211 | 214 |
os::cmd::expect_success_and_text 'oc new-build mysql --binary -o yaml --to mysql:bin' 'type: Binary' |
212 | 215 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
0 |
+version: "2" |
|
1 |
+services: |
|
2 |
+ WP: |
|
3 |
+ image: "centurylink/wordpress:3.9.1" |
|
4 |
+ links: |
|
5 |
+ - "DB:DB_1" |
|
6 |
+ ports: |
|
7 |
+ - "8080:80" |
|
8 |
+ environment: |
|
9 |
+ - "DB_PASSWORD=pass@word01" |
|
10 |
+ - DB_NAME=wordpress |
|
11 |
+ dns: |
|
12 |
+ - 8.8.8.8 |
|
13 |
+ - 9.9.9.9 |
|
14 |
+ hostname: wordpress |
|
15 |
+ domainname: wordpress.mysite.com |
|
16 |
+ DB: |
|
17 |
+ image: "centurylink/mysql:5.5" |
|
18 |
+ ports: |
|
19 |
+ - "3306:3306" |
|
20 |
+ environment: |
|
21 |
+ - "MYSQL_ROOT_PASSWORD=pass@word01" |
|
22 |
+ mem_limit: "1000000000" |
|
23 |
+ cpu_shares: "40" |
... | ... |
@@ -27,17 +27,35 @@ var ( |
27 | 27 |
} |
28 | 28 |
) |
29 | 29 |
|
30 |
+type rawSchema struct { |
|
31 |
+ Version string `yaml:"version"` |
|
32 |
+ Services rawServiceMap `yaml:"services"` |
|
33 |
+} |
|
34 |
+ |
|
30 | 35 |
type rawService map[string]interface{} |
31 | 36 |
type rawServiceMap map[string]rawService |
32 | 37 |
|
33 | 38 |
func mergeProject(p *Project, file string, bytes []byte) (map[string]*ServiceConfig, error) { |
34 | 39 |
configs := make(map[string]*ServiceConfig) |
35 | 40 |
|
36 |
- datas := make(rawServiceMap) |
|
37 |
- if err := yaml.Unmarshal(bytes, &datas); err != nil { |
|
41 |
+ var schema rawSchema |
|
42 |
+ if err := yaml.Unmarshal(bytes, &schema); err != nil { |
|
38 | 43 |
return nil, err |
39 | 44 |
} |
40 | 45 |
|
46 |
+ var datas = make(rawServiceMap) |
|
47 |
+ switch { |
|
48 |
+ case schema.Version == "2": |
|
49 |
+ datas = schema.Services |
|
50 |
+ case len(schema.Version) == 0: |
|
51 |
+ datas = make(rawServiceMap) |
|
52 |
+ if err := yaml.Unmarshal(bytes, &datas); err != nil { |
|
53 |
+ return nil, err |
|
54 |
+ } |
|
55 |
+ default: |
|
56 |
+ return nil, fmt.Errorf("docker-compose file with schema version %q is not supported", schema.Version) |
|
57 |
+ } |
|
58 |
+ |
|
41 | 59 |
if err := interpolate(p.context.EnvironmentLookup, &datas); err != nil { |
42 | 60 |
return nil, err |
43 | 61 |
} |