Skip to content

Commit cb96a73

Browse files
authored
Merge pull request #461 from ndeloof/develop
introduce `develop` section
2 parents ba097a5 + b6527f6 commit cb96a73

File tree

5 files changed

+133
-17
lines changed

5 files changed

+133
-17
lines changed

loader/loader_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,3 +2774,55 @@ services:
27742774
assert.NilError(t, err)
27752775
assert.Equal(t, project.Services[0].Image, "nginx:override")
27762776
}
2777+
2778+
func TestLoadDevelopConfig(t *testing.T) {
2779+
project, err := Load(buildConfigDetails(`
2780+
name: load-develop
2781+
services:
2782+
frontend:
2783+
image: example/webapp
2784+
build: ./webapp
2785+
develop:
2786+
watch:
2787+
# sync static content
2788+
- path: ./webapp/html
2789+
action: sync
2790+
target: /var/www
2791+
ignore:
2792+
- node_modules/
2793+
2794+
backend:
2795+
image: example/backend
2796+
build: ./backend
2797+
develop:
2798+
watch:
2799+
# rebuild image and recreate service
2800+
- path: ./backend/src
2801+
action: rebuild
2802+
`, nil), func(options *Options) {
2803+
options.ResolvePaths = false
2804+
})
2805+
assert.NilError(t, err)
2806+
frontend, err := project.GetService("frontend")
2807+
assert.NilError(t, err)
2808+
assert.DeepEqual(t, *frontend.Develop, types.DevelopConfig{
2809+
Watch: []types.Trigger{
2810+
{
2811+
Path: "./webapp/html",
2812+
Action: types.WatchActionSync,
2813+
Target: "/var/www",
2814+
Ignore: []string{"node_modules/"},
2815+
},
2816+
},
2817+
})
2818+
backend, err := project.GetService("backend")
2819+
assert.NilError(t, err)
2820+
assert.DeepEqual(t, *backend.Develop, types.DevelopConfig{
2821+
Watch: []types.Trigger{
2822+
{
2823+
Path: "./backend/src",
2824+
Action: types.WatchActionRebuild,
2825+
},
2826+
},
2827+
})
2828+
}

loader/paths.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ func ResolveServiceRelativePaths(workingDir string, s *types.ServiceConfig) {
115115
}
116116
s.Volumes[i].Source = resolveMaybeUnixPath(workingDir, vol.Source)
117117
}
118+
119+
if s.Develop != nil {
120+
for i, w := range s.Develop.Watch {
121+
w.Path = absPath(workingDir, w.Path)
122+
s.Develop.Watch[i] = w
123+
}
124+
}
118125
}
119126

120127
func absPath(workingDir string, filePath string) string {

schema/compose-spec.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"type": "object",
9292

9393
"properties": {
94+
"develop": {"$ref": "#/definitions/development"},
9495
"deploy": {"$ref": "#/definitions/deployment"},
9596
"annotations": {"$ref": "#/definitions/list_or_dict"},
9697
"attach": {"type": "boolean"},
@@ -463,6 +464,26 @@
463464
"additionalProperties": false,
464465
"patternProperties": {"^x-": {}}
465466
},
467+
"development": {
468+
"id": "#/definitions/development",
469+
"type": ["object", "null"],
470+
"properties": {
471+
"watch": {
472+
"type": "array",
473+
"items": {
474+
"type": "object",
475+
"properties": {
476+
"ignore": {"type": "array", "items": {"type": "string"}},
477+
"path": {"type": "string"},
478+
"action": {"type": "string", "enum": ["rebuild", "sync"]},
479+
"target": {"type": "string"}
480+
}
481+
},
482+
"additionalProperties": false,
483+
"patternProperties": {"^x-": {}}
484+
}
485+
}
486+
},
466487
"deployment": {
467488
"id": "#/definitions/deployment",
468489
"type": ["object", "null"],

types/develop.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2020 The Compose Specification Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package types
18+
19+
type DevelopConfig struct {
20+
Watch []Trigger `json:"watch,omitempty"`
21+
}
22+
23+
type WatchAction string
24+
25+
const (
26+
WatchActionSync WatchAction = "sync"
27+
WatchActionRebuild WatchAction = "rebuild"
28+
)
29+
30+
type Trigger struct {
31+
Path string `json:"path,omitempty"`
32+
Action WatchAction `json:"action,omitempty"`
33+
Target string `json:"target,omitempty"`
34+
Ignore []string `json:"ignore,omitempty"`
35+
}

types/types.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,24 @@ type ServiceConfig struct {
8888
Name string `yaml:"-" json:"-"`
8989
Profiles []string `yaml:"profiles,omitempty" json:"profiles,omitempty"`
9090

91-
Annotations Mapping `yaml:"annotations,omitempty" json:"annotations,omitempty"`
92-
Attach *bool `yaml:"attach,omitempty" json:"attach,omitempty"`
93-
Build *BuildConfig `yaml:"build,omitempty" json:"build,omitempty"`
94-
BlkioConfig *BlkioConfig `yaml:"blkio_config,omitempty" json:"blkio_config,omitempty"`
95-
CapAdd []string `yaml:"cap_add,omitempty" json:"cap_add,omitempty"`
96-
CapDrop []string `yaml:"cap_drop,omitempty" json:"cap_drop,omitempty"`
97-
CgroupParent string `yaml:"cgroup_parent,omitempty" json:"cgroup_parent,omitempty"`
98-
Cgroup string `yaml:"cgroup,omitempty" json:"cgroup,omitempty"`
99-
CPUCount int64 `yaml:"cpu_count,omitempty" json:"cpu_count,omitempty"`
100-
CPUPercent float32 `yaml:"cpu_percent,omitempty" json:"cpu_percent,omitempty"`
101-
CPUPeriod int64 `yaml:"cpu_period,omitempty" json:"cpu_period,omitempty"`
102-
CPUQuota int64 `yaml:"cpu_quota,omitempty" json:"cpu_quota,omitempty"`
103-
CPURTPeriod int64 `yaml:"cpu_rt_period,omitempty" json:"cpu_rt_period,omitempty"`
104-
CPURTRuntime int64 `yaml:"cpu_rt_runtime,omitempty" json:"cpu_rt_runtime,omitempty"`
105-
CPUS float32 `yaml:"cpus,omitempty" json:"cpus,omitempty"`
106-
CPUSet string `yaml:"cpuset,omitempty" json:"cpuset,omitempty"`
107-
CPUShares int64 `yaml:"cpu_shares,omitempty" json:"cpu_shares,omitempty"`
91+
Annotations Mapping `yaml:"annotations,omitempty" json:"annotations,omitempty"`
92+
Attach *bool `yaml:"attach,omitempty" json:"attach,omitempty"`
93+
Build *BuildConfig `yaml:"build,omitempty" json:"build,omitempty"`
94+
Develop *DevelopConfig `yaml:"develop,omitempty" json:"develop,omitempty"`
95+
BlkioConfig *BlkioConfig `yaml:"blkio_config,omitempty" json:"blkio_config,omitempty"`
96+
CapAdd []string `yaml:"cap_add,omitempty" json:"cap_add,omitempty"`
97+
CapDrop []string `yaml:"cap_drop,omitempty" json:"cap_drop,omitempty"`
98+
CgroupParent string `yaml:"cgroup_parent,omitempty" json:"cgroup_parent,omitempty"`
99+
Cgroup string `yaml:"cgroup,omitempty" json:"cgroup,omitempty"`
100+
CPUCount int64 `yaml:"cpu_count,omitempty" json:"cpu_count,omitempty"`
101+
CPUPercent float32 `yaml:"cpu_percent,omitempty" json:"cpu_percent,omitempty"`
102+
CPUPeriod int64 `yaml:"cpu_period,omitempty" json:"cpu_period,omitempty"`
103+
CPUQuota int64 `yaml:"cpu_quota,omitempty" json:"cpu_quota,omitempty"`
104+
CPURTPeriod int64 `yaml:"cpu_rt_period,omitempty" json:"cpu_rt_period,omitempty"`
105+
CPURTRuntime int64 `yaml:"cpu_rt_runtime,omitempty" json:"cpu_rt_runtime,omitempty"`
106+
CPUS float32 `yaml:"cpus,omitempty" json:"cpus,omitempty"`
107+
CPUSet string `yaml:"cpuset,omitempty" json:"cpuset,omitempty"`
108+
CPUShares int64 `yaml:"cpu_shares,omitempty" json:"cpu_shares,omitempty"`
108109

109110
// Command for the service containers.
110111
// If set, overrides COMMAND from the image.

0 commit comments

Comments
 (0)