From 081642fbf9a87414392dfafaa4f8a3f592c03fa2 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Tue, 29 Aug 2017 16:55: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 | 7 +++++++ cli/compose/loader/loader_test.go | 5 +++++ cli/compose/types/types.go | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cli/compose/loader/full-example.yml b/cli/compose/loader/full-example.yml index d193dccd31c9..0896c84309d9 100644 --- a/cli/compose/loader/full-example.yml +++ b/cli/compose/loader/full-example.yml @@ -2,6 +2,13 @@ version: "3.4" services: foo: + + build: + context: ./dir + dockerfile: Dockerfile-alternate + args: + foo: bar + cap_add: - ALL diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 295e91e1e781..4f5fe5e5ce4f 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -686,6 +686,11 @@ func TestFullExample(t *testing.T) { expectedServiceConfig := types.ServiceConfig{ Name: "foo", + Build: types.BuildConfig{ + Context: "./dir", + Dockerfile: "Dockerfile-alternative", + Args: 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 8feaf4289daa..38ec2bc269f7 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -6,7 +6,6 @@ import ( // UnsupportedProperties not yet supported by this implementation of the compose file var UnsupportedProperties = []string{ - "build", "cap_add", "cap_drop", "cgroup_parent", @@ -78,9 +77,10 @@ type Config struct { type ServiceConfig struct { Name string - CapAdd []string `mapstructure:"cap_add"` - CapDrop []string `mapstructure:"cap_drop"` - CgroupParent string `mapstructure:"cgroup_parent"` + Build BuildConfig `mapstructure:"build"` + CapAdd []string `mapstructure:"cap_add"` + CapDrop []string `mapstructure:"cap_drop"` + CgroupParent string `mapstructure:"cgroup_parent"` Command ShellCommand Configs []ServiceConfigObjConfig ContainerName string `mapstructure:"container_name"` @@ -125,6 +125,14 @@ 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 map[string]*string +} + // ShellCommand is a string or list of string args type ShellCommand []string