Skip to content

Commit

Permalink
Add 'build' to types.go
Browse files Browse the repository at this point in the history
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 <charlie@charliedrage.com>
  • Loading branch information
cdrage committed Aug 29, 2017
1 parent e600621 commit be81f80
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cli/compose/loader/full-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ version: "3.4"

services:
foo:

build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
foo: bar

cap_add:
- ALL

Expand Down
5 changes: 5 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": strPtr("bar")},
},
CapAdd: []string{"ALL"},
CapDrop: []string{"NET_ADMIN", "SYS_ADMIN"},
CgroupParent: "m-executor-abcd",
Expand Down
15 changes: 12 additions & 3 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,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"`
Expand Down Expand Up @@ -125,6 +126,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

Expand Down

0 comments on commit be81f80

Please sign in to comment.