Skip to content

Commit 0eea9f8

Browse files
authored
Merge pull request #487 from ndeloof/build-ulimits-v1
add support for build.ulimits
2 parents 5c2ad73 + d91e0e9 commit 0eea9f8

File tree

3 files changed

+76
-48
lines changed

3 files changed

+76
-48
lines changed

loader/loader_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,3 +2909,30 @@ networks:
29092909
})
29102910
assert.ErrorContains(t, err, "service redis declares mutually exclusive `network_mode` and `networks`")
29112911
}
2912+
2913+
func TestBuildUlimits(t *testing.T) {
2914+
yaml := `
2915+
name: test-build-ulimits
2916+
services:
2917+
test:
2918+
build:
2919+
context: .
2920+
ulimits:
2921+
nproc: 65535
2922+
nofile:
2923+
soft: 20000
2924+
hard: 40000
2925+
`
2926+
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
2927+
ConfigFiles: []types.ConfigFile{
2928+
{
2929+
Content: []byte(yaml),
2930+
},
2931+
},
2932+
})
2933+
assert.NilError(t, err)
2934+
assert.DeepEqual(t, p.Services[0].Build.Ulimits, map[string]*types.UlimitsConfig{
2935+
"nproc": {Single: 65535},
2936+
"nofile": {Soft: 20000, Hard: 40000},
2937+
})
2938+
}

schema/compose-spec.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"privileged": {"type": "boolean"},
121121
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
122122
"tags": {"type": "array", "items": {"type": "string"}},
123+
"ulimits": {"$ref": "#/definitions/ulimits"},
123124
"platforms": {"type": "array", "items": {"type": "string"}}
124125
},
125126
"additionalProperties": false,
@@ -356,26 +357,7 @@
356357
"storage_opt": {"type": "object"},
357358
"tmpfs": {"$ref": "#/definitions/string_or_list"},
358359
"tty": {"type": "boolean"},
359-
"ulimits": {
360-
"type": "object",
361-
"patternProperties": {
362-
"^[a-z]+$": {
363-
"oneOf": [
364-
{"type": "integer"},
365-
{
366-
"type": "object",
367-
"properties": {
368-
"hard": {"type": "integer"},
369-
"soft": {"type": "integer"}
370-
},
371-
"required": ["soft", "hard"],
372-
"additionalProperties": false,
373-
"patternProperties": {"^x-": {}}
374-
}
375-
]
376-
}
377-
}
378-
},
360+
"ulimits": {"$ref": "#/definitions/ulimits"},
379361
"user": {"type": "string"},
380362
"uts": {"type": "string"},
381363
"userns_mode": {"type": "string"},
@@ -613,12 +595,12 @@
613595
"items": {
614596
"type": "object",
615597
"properties": {
616-
"capabilities": {"$ref": "#/definitions/list_of_strings"},
617-
"count": {"type": ["string", "integer"]},
618-
"device_ids": {"$ref": "#/definitions/list_of_strings"},
619-
"driver":{"type": "string"},
620-
"options":{"$ref": "#/definitions/list_or_dict"}
621-
},
598+
"capabilities": {"$ref": "#/definitions/list_of_strings"},
599+
"count": {"type": ["string", "integer"]},
600+
"device_ids": {"$ref": "#/definitions/list_of_strings"},
601+
"driver":{"type": "string"},
602+
"options":{"$ref": "#/definitions/list_or_dict"}
603+
},
622604
"additionalProperties": false,
623605
"patternProperties": {"^x-": {}}
624606
}
@@ -835,7 +817,6 @@
835817
},
836818
"additionalProperties": false
837819
},
838-
839820
"service_config_or_secret": {
840821
"type": "array",
841822
"items": {
@@ -856,7 +837,26 @@
856837
]
857838
}
858839
},
859-
840+
"ulimits": {
841+
"type": "object",
842+
"patternProperties": {
843+
"^[a-z]+$": {
844+
"oneOf": [
845+
{"type": "integer"},
846+
{
847+
"type": "object",
848+
"properties": {
849+
"hard": {"type": "integer"},
850+
"soft": {"type": "integer"}
851+
},
852+
"required": ["soft", "hard"],
853+
"additionalProperties": false,
854+
"patternProperties": {"^x-": {}}
855+
}
856+
]
857+
}
858+
}
859+
},
860860
"constraints": {
861861
"service": {
862862
"id": "#/definitions/constraints/service",
@@ -872,4 +872,4 @@
872872
}
873873
}
874874
}
875-
}
875+
}

types/types.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,26 @@ func (s set) toSlice() []string {
276276

277277
// BuildConfig is a type for build
278278
type BuildConfig struct {
279-
Context string `yaml:"context,omitempty" json:"context,omitempty"`
280-
Dockerfile string `yaml:"dockerfile,omitempty" json:"dockerfile,omitempty"`
281-
DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"`
282-
Args MappingWithEquals `yaml:"args,omitempty" json:"args,omitempty"`
283-
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
284-
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
285-
CacheFrom StringList `yaml:"cache_from,omitempty" json:"cache_from,omitempty"`
286-
CacheTo StringList `yaml:"cache_to,omitempty" json:"cache_to,omitempty"`
287-
NoCache bool `yaml:"no_cache,omitempty" json:"no_cache,omitempty"`
288-
AdditionalContexts Mapping `yaml:"additional_contexts,omitempty" json:"additional_contexts,omitempty"`
289-
Pull bool `yaml:"pull,omitempty" json:"pull,omitempty"`
290-
ExtraHosts HostsList `yaml:"extra_hosts,omitempty" json:"extra_hosts,omitempty"`
291-
Isolation string `yaml:"isolation,omitempty" json:"isolation,omitempty"`
292-
Network string `yaml:"network,omitempty" json:"network,omitempty"`
293-
Target string `yaml:"target,omitempty" json:"target,omitempty"`
294-
Secrets []ServiceSecretConfig `yaml:"secrets,omitempty" json:"secrets,omitempty"`
295-
Tags StringList `yaml:"tags,omitempty" json:"tags,omitempty"`
296-
Platforms StringList `yaml:"platforms,omitempty" json:"platforms,omitempty"`
297-
Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty"`
279+
Context string `yaml:"context,omitempty" json:"context,omitempty"`
280+
Dockerfile string `yaml:"dockerfile,omitempty" json:"dockerfile,omitempty"`
281+
DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"`
282+
Args MappingWithEquals `yaml:"args,omitempty" json:"args,omitempty"`
283+
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
284+
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
285+
CacheFrom StringList `yaml:"cache_from,omitempty" json:"cache_from,omitempty"`
286+
CacheTo StringList `yaml:"cache_to,omitempty" json:"cache_to,omitempty"`
287+
NoCache bool `yaml:"no_cache,omitempty" json:"no_cache,omitempty"`
288+
AdditionalContexts Mapping `yaml:"additional_contexts,omitempty" json:"additional_contexts,omitempty"`
289+
Pull bool `yaml:"pull,omitempty" json:"pull,omitempty"`
290+
ExtraHosts HostsList `yaml:"extra_hosts,omitempty" json:"extra_hosts,omitempty"`
291+
Isolation string `yaml:"isolation,omitempty" json:"isolation,omitempty"`
292+
Network string `yaml:"network,omitempty" json:"network,omitempty"`
293+
Target string `yaml:"target,omitempty" json:"target,omitempty"`
294+
Secrets []ServiceSecretConfig `yaml:"secrets,omitempty" json:"secrets,omitempty"`
295+
Tags StringList `yaml:"tags,omitempty" json:"tags,omitempty"`
296+
Ulimits map[string]*UlimitsConfig `yaml:"ulimits,omitempty" json:"ulimits,omitempty"`
297+
Platforms StringList `yaml:"platforms,omitempty" json:"platforms,omitempty"`
298+
Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty"`
298299

299300
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
300301
}

0 commit comments

Comments
 (0)