From cc26da94ed292dc16c6bbfbd84c16c7e192f2f19 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 18 Jun 2018 10:48:03 +0200 Subject: [PATCH 1/2] Add `init` support in 3.7 schema > Run an init inside the container that forwards signals and reaps processes This is supported on `run` and now on Swarm services too, so it's also possible to have in on a composefile :). Signed-off-by: Vincent Demeester --- cli/compose/convert/service.go | 1 + cli/compose/loader/loader_test.go | 57 +++++++++++++++++++ cli/compose/schema/bindata.go | 44 +++++++------- .../schema/data/config_schema_v3.7.json | 1 + cli/compose/types/types.go | 6 +- 5 files changed, 85 insertions(+), 24 deletions(-) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 5407a0114a..08865968e3 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -150,6 +150,7 @@ func Service( ReadOnly: service.ReadOnly, Privileges: &privileges, Isolation: container.Isolation(service.Isolation), + Init: service.Init, }, LogDriver: logDriver, Resources: resources, diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 55b58cca17..6aeb367e4c 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -1415,3 +1415,60 @@ networks: } assert.DeepEqual(t, config, expected, cmpopts.EquateEmpty()) } + +func TestLoadInit(t *testing.T) { + booleanFalse := false + booleanTrue := true + config, err := loadYAML(` +version: '3.7' +services: + foo: + image: alpine`) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(config, &types.Config{ + Filename: "filename.yml", + Version: "3.7", + Services: types.Services{ + { + Name: "foo", + Image: "alpine", + }, + }, + }, cmpopts.EquateEmpty())) + config, err = loadYAML(` +version: '3.7' +services: + foo: + image: alpine + init: true`) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(config, &types.Config{ + Filename: "filename.yml", + Version: "3.7", + Services: types.Services{ + { + Name: "foo", + Image: "alpine", + Init: &booleanTrue, + }, + }, + }, cmpopts.EquateEmpty())) + config, err = loadYAML(` +version: '3.7' +services: + foo: + image: alpine + init: false`) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(config, &types.Config{ + Filename: "filename.yml", + Version: "3.7", + Services: types.Services{ + { + Name: "foo", + Image: "alpine", + Init: &booleanFalse, + }, + }, + }, cmpopts.EquateEmpty())) +} diff --git a/cli/compose/schema/bindata.go b/cli/compose/schema/bindata.go index e56e243201..9ec4891fa3 100644 --- a/cli/compose/schema/bindata.go +++ b/cli/compose/schema/bindata.go @@ -467,7 +467,7 @@ DoTuq9lAU9Q4O1xV/59X/w8AAP//zRo7vm9CAAA= "/data/config_schema_v3.7.json": { local: "data/config_schema_v3.7.json", - size: 17740, + size: 17777, modtime: 1518458244, compressed: ` H4sIAAAAAAAC/+xcS4/bOBK++1cYmrlNPwLsYBeb2x73tHvehiPQVNnmNEVyipTTTuD/vtDTEkWKlK1O @@ -484,27 +484,27 @@ q261wbY83KwjrNLhLgLuJuxwSkuXBdJY/zH3HK3XScGyeOL9HOJcZsN9iyLfAibnEfHokA5+36xcbyzt G8IEYCpIDkE7RshAGEZ4qhXQAXmrqQnNJFH+PEHYM23w5KS8cNHfWAYKRKbTOoKZ73qTDLpwZlE3kYmp K6WeprxUyr0l1sBUA0F6uHK8zAkTMUoFYfCkJKvd2LvzTyCOaWc3s8UA4shQirx10nFXe2/8i5IabneO 3UXbMH7XnenNUHrJTmJOys22a688V7DD8voC7PNQQmLCU87E8/ImDi8GSXqQ2lyDnpIDEG4O9AD0eWJ4 -n2owWmoTY+QsJ/swkaJBEi05MU2mZIrwajiZLKql3rRyvy9JfaY5Ck8igX2G7AgYiz6lukRVris4dO0H -w9AB6ZeHOgqdOH7VT5yP4a7rdrWfWBzGAeKBVnJCS9yLoHXIopqoIB2BgwvtiFjHuvSrgpX5QWKU6oKZ -hCDk9MHKeCuLg5it2jkjGvRtUV/PCx1/j7QJ19i/T471DPXOGR/jBabqY1nOnRvZhNHta4agaojQh76i -8hD9A6Ykmh8SNF381AUZ1IuP4yhb3VGDXif4mvBScaFXm5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jGcsuXzdLvGsBViZj+JlaqdaoLokwYbS6YbMkLNEkyTrVVWcuZthQE8ugFWGKEhGGRW +fajFrn2IBfp9VlEMy0EW5lp4StDMB7h221mvt6Wtx0yZUI/StqCnXrWxTrsEzSQGj4DIqjpYFHhBUJxR +okMA8YYkP0rOt4Q+p02P1BxQPoHGFUHCOXCm8xh0m2TAyekqy6kLWoTxAiElNKIk0uhKMCPx+iVz8pK2 +y1YkgXNbn1PMwLcmiOqesfFlfTLudwy1qdMQUjW/Dd3/2Zvaia0GXK4OlREDHybxYRL9DF0VG+ilzMGZ +BFimDVAVsfWKJIdchrpAbk/5WypH0CVM8BUg34sAHNR7EICMpgNr8Fw5Y9pXqqLcbtk19pCc1SHmEuZN +paj3EeN5bnR1pd8pgXiujI5yrV+ZyOTX+TBrAWkrTihY0OxWQWuDhAkzu1fBFotC2AGCoDB5LMc5o4m8 +0XIJeYVAsjcoGd2q/Bs+LnC6myk8Px4wCgyH2nNoza+tia7DjGmKYKBbuWteXMVbwrQVJM9NTivoqJMj +4UVEDeSqrhFf7iBi8Nn5rVNIpy3ZAgFaTBdXVBtRQ5VKtXwdI9wqtAln0Zki+VIeNrqxKnEGDO/BdxZb +4UlTv2/feTfusPRo9alLSN11stpEq9h7MJbbf5Ubs4uPriQaMYbQQ1S+bWba4wekL0fpeqdLa6g+PNoM +j/az2//7s9XmM9Dgp4YVVfjLzRssNOKbjXeg/59EraNL2KnWhupDrT+LWq2mm556x8WfKYlHdwav+rWe +bhs2meM/c/BFWN5N+UqV1qKNsKc5X/DeevhtAslOdfC/EgRcoN3RrVMrhbLqmhvtb9H9vqQdP/oyveRT +nEbFye/DBpf6q/LNQD4WSf11TQ8obKICc9f36nZ7TfvduKfjbxi9rsq/59X/AwAA//+9o87pcUUAAA== `, }, diff --git a/cli/compose/schema/data/config_schema_v3.7.json b/cli/compose/schema/data/config_schema_v3.7.json index 05566cf819..f1597df001 100644 --- a/cli/compose/schema/data/config_schema_v3.7.json +++ b/cli/compose/schema/data/config_schema_v3.7.json @@ -154,6 +154,7 @@ "healthcheck": {"$ref": "#/definitions/healthcheck"}, "hostname": {"type": "string"}, "image": {"type": "string"}, + "init": {"type": "boolean"}, "ipc": {"type": "string"}, "isolation": {"type": "string"}, "labels": {"$ref": "#/definitions/list_or_dict"}, diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index d59e1f1495..6c1a0dd758 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -119,7 +119,9 @@ type ServiceConfig struct { Hostname string `yaml:",omitempty"` HealthCheck *HealthCheckConfig `yaml:",omitempty"` Image string `yaml:",omitempty"` + Init *bool `yaml:",omitempty"` Ipc string `yaml:",omitempty"` + Isolation string `mapstructure:"isolation" yaml:"isolation,omitempty"` Labels Labels `yaml:",omitempty"` Links []string `yaml:",omitempty"` Logging *LoggingConfig `yaml:",omitempty"` @@ -142,8 +144,8 @@ type ServiceConfig struct { User string `yaml:",omitempty"` Volumes []ServiceVolumeConfig `yaml:",omitempty"` WorkingDir string `mapstructure:"working_dir" yaml:"working_dir,omitempty"` - Isolation string `mapstructure:"isolation" yaml:"isolation,omitempty"` - Extras map[string]interface{} `yaml:",inline"` + + Extras map[string]interface{} `yaml:",inline"` } // BuildConfig is a type for build From 38056740d6ea78eb559696196d4a3b32411554aa Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Mon, 25 Jun 2018 11:09:38 +0200 Subject: [PATCH 2/2] Refactor tests Signed-off-by: Silvin Lubecki --- cli/compose/loader/loader_test.go | 69 ++++++++++++++----------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 6aeb367e4c..7b72ad768c 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -1417,58 +1417,49 @@ networks: } func TestLoadInit(t *testing.T) { - booleanFalse := false booleanTrue := true - config, err := loadYAML(` + booleanFalse := false + + var testcases = []struct { + doc string + yaml string + init *bool + }{ + { + doc: "no init defined", + yaml: ` version: '3.7' services: foo: - image: alpine`) - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(config, &types.Config{ - Filename: "filename.yml", - Version: "3.7", - Services: types.Services{ - { - Name: "foo", - Image: "alpine", - }, + image: alpine`, }, - }, cmpopts.EquateEmpty())) - config, err = loadYAML(` + { + doc: "has true init", + yaml: ` version: '3.7' services: foo: image: alpine - init: true`) - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(config, &types.Config{ - Filename: "filename.yml", - Version: "3.7", - Services: types.Services{ - { - Name: "foo", - Image: "alpine", - Init: &booleanTrue, - }, + init: true`, + init: &booleanTrue, }, - }, cmpopts.EquateEmpty())) - config, err = loadYAML(` + { + doc: "has false init", + yaml: ` version: '3.7' services: foo: image: alpine - init: false`) - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(config, &types.Config{ - Filename: "filename.yml", - Version: "3.7", - Services: types.Services{ - { - Name: "foo", - Image: "alpine", - Init: &booleanFalse, - }, + init: false`, + init: &booleanFalse, }, - }, cmpopts.EquateEmpty())) + } + for _, testcase := range testcases { + t.Run(testcase.doc, func(t *testing.T) { + config, err := loadYAML(testcase.yaml) + assert.NilError(t, err) + assert.Check(t, is.Len(config.Services, 1)) + assert.Check(t, is.DeepEqual(config.Services[0].Init, testcase.init)) + }) + } }