Skip to content

Commit

Permalink
support gpus: all alias
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Jan 23, 2025
1 parent 3e21e9f commit 11509c6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
26 changes: 26 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3581,3 +3581,29 @@ services:
},
})
}
<<<<<<< Updated upstream

Check failure on line 3584 in loader/loader_test.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

syntax error: non-declaration statement outside function body

Check failure on line 3584 in loader/loader_test.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

expected declaration, found '<<' (typecheck)
=======

func TestOmitEmptyDNS(t *testing.T) {
p, err := loadYAML(`
name: load-empty-dsn
services:
test:
dns: ${UNSET_VAR}
`)
assert.NilError(t, err)
assert.Equal(t, len(p.Services["test"].DNS), 0)
}

func TestAllGPUS(t *testing.T) {
p, err := loadYAML(`
name: load-all-gpus
services:
test:
gpus: all
`)
assert.NilError(t, err)
assert.Equal(t, len(p.Services["test"].Gpus), 1)
assert.Equal(t, p.Services["test"].Gpus[0].Count, types.DeviceCount(-1))
}
>>>>>>> Stashed changes

Check failure on line 3609 in loader/loader_test.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

syntax error: non-declaration statement outside function body (typecheck)
30 changes: 17 additions & 13 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,23 @@

"gpus": {
"id": "#/definitions/gpus",
"type": "array",
"items": {
"type": "object",
"properties": {
"capabilities": {"$ref": "#/definitions/list_of_strings"},
"count": {"type": ["string", "integer"]},
"device_ids": {"$ref": "#/definitions/list_of_strings"},
"driver":{"type": "string"},
"options":{"$ref": "#/definitions/list_or_dict"}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
}
"oneOf": [
{"type": "string", "enum": ["all"]},
{"type": "array",
"items": {
"type": "object",
"properties": {
"capabilities": {"$ref": "#/definitions/list_of_strings"},
"count": {"type": ["string", "integer"]},
"device_ids": {"$ref": "#/definitions/list_of_strings"},
"driver":{"type": "string"},
"options":{"$ref": "#/definitions/list_or_dict"}
}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
}
]
},

"include": {
Expand Down
1 change: 1 addition & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func init() {
transformers["services.*.depends_on"] = transformDependsOn
transformers["services.*.env_file"] = transformEnvFile
transformers["services.*.extends"] = transformExtends
transformers["services.*.gpus"] = transformGpus
transformers["services.*.networks"] = transformServiceNetworks
transformers["services.*.volumes.*"] = transformVolumeMount
transformers["services.*.devices.*"] = transformDeviceMapping
Expand Down
38 changes: 38 additions & 0 deletions transform/gpus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2020 The Compose Specification Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package transform

import (
"fmt"

"github.com/compose-spec/compose-go/v2/tree"
)

func transformGpus(data any, p tree.Path, ignoreParseError bool) (any, error) {
switch v := data.(type) {
case []any:
return transformSequence(v, p, ignoreParseError)
case string:
return []any{
map[string]any{
"count": "all",
},
}, nil
default:
return data, fmt.Errorf("%s: invalid type %T for gpus", p, v)
}
}

0 comments on commit 11509c6

Please sign in to comment.