From 9bdb0763b9e667dc01adf36ba98a2b7bd47bdc75 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Wed, 13 Sep 2017 10:47:17 -0400 Subject: [PATCH] Add 'build' to types.go This adds 'build' to types.go in order for projects that use docker/cli to parse Docker Compose files to correctly retrieve `build` keys Signed-off-by: Charlie Drage --- cli/compose/loader/full-example.yml | 15 +++++++++++++++ cli/compose/loader/loader_test.go | 15 +++++++++++++-- cli/compose/types/types.go | 13 +++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cli/compose/loader/full-example.yml b/cli/compose/loader/full-example.yml index d193dccd31..4a6e8dbfd3 100644 --- a/cli/compose/loader/full-example.yml +++ b/cli/compose/loader/full-example.yml @@ -2,6 +2,21 @@ version: "3.4" services: foo: + + build: + context: ./dir + dockerfile: Dockerfile + args: + foo: bar + target: foo + network: foo + cache_from: + - foo + - bar + labels: [FOO=BAR] + + + cap_add: - ALL diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 295e91e1e7..b7bc3d7c2e 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -517,12 +517,14 @@ version: "3" services: web: image: web - build: ./web + build: + context: ./web links: - bar db: image: db - build: ./db + build: + context: ./db `)) assert.NoError(t, err) @@ -686,6 +688,15 @@ func TestFullExample(t *testing.T) { expectedServiceConfig := types.ServiceConfig{ Name: "foo", + Build: types.BuildConfig{ + Context: "./dir", + Dockerfile: "Dockerfile", + Args: map[string]*string{"foo": strPtr("bar")}, + Target: "foo", + Network: "foo", + CacheFrom: []string{"foo", "bar"}, + Labels: map[string]string{"FOO": "BAR"}, + }, CapAdd: []string{"ALL"}, CapDrop: []string{"NET_ADMIN", "SYS_ADMIN"}, CgroupParent: "m-executor-abcd", diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index 8feaf4289d..e190c41b4d 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -78,6 +78,7 @@ type Config struct { type ServiceConfig struct { Name string + Build BuildConfig CapAdd []string `mapstructure:"cap_add"` CapDrop []string `mapstructure:"cap_drop"` CgroupParent string `mapstructure:"cgroup_parent"` @@ -125,6 +126,18 @@ type ServiceConfig struct { WorkingDir string `mapstructure:"working_dir"` } +// BuildConfig is a type for build +// using the same format at libcompose: https://github.com/docker/libcompose/blob/master/yaml/build.go#L12 +type BuildConfig struct { + Context string + Dockerfile string + Args MappingWithEquals + Labels Labels + CacheFrom StringList `mapstructure:"cache_from"` + Network string + Target string +} + // ShellCommand is a string or list of string args type ShellCommand []string