Skip to content

Commit c4e7bc8

Browse files
committed
adopt new loading pipeline to load compose files
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent ab50b76 commit c4e7bc8

17 files changed

Lines changed: 1563 additions & 135 deletions

loader/compose_model.go

Lines changed: 651 additions & 88 deletions
Large diffs are not rendered by default.

loader/loader.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -322,32 +322,30 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir strin
322322

323323
// LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
324324
func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {
325-
opts := ToOptions(&configDetails, options)
326-
dict, err := loadModelWithContext(ctx, &configDetails, opts)
325+
model, err := LoadLazyModel(ctx, configDetails, options...)
327326
if err != nil {
328327
return nil, err
329328
}
330-
return ModelToProject(dict, opts, configDetails)
329+
return model.Resolve()
331330
}
332331

333332
// LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
334333
func LoadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (map[string]any, error) {
335-
opts := ToOptions(&configDetails, options)
336-
return loadModelWithContext(ctx, &configDetails, opts)
337-
}
338-
339-
// LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
340-
func loadModelWithContext(ctx context.Context, configDetails *types.ConfigDetails, opts *Options) (map[string]any, error) {
341-
if len(configDetails.ConfigFiles) < 1 {
342-
return nil, errors.New("no compose file specified")
334+
project, err := LoadWithContext(ctx, configDetails, options...)
335+
if err != nil {
336+
return nil, err
343337
}
344-
345-
err := projectName(configDetails, opts)
338+
// Marshal the typed project back to a yaml dictionary for backward compatibility
339+
b, err := yaml.Marshal(project)
346340
if err != nil {
347341
return nil, err
348342
}
349-
350-
return load(ctx, *configDetails, opts, nil)
343+
var dict map[string]any
344+
if err := yaml.Unmarshal(b, &dict); err != nil {
345+
return nil, err
346+
}
347+
dict["name"] = project.Name
348+
return dict, nil
351349
}
352350

353351
func ToOptions(configDetails *types.ConfigDetails, options []func(*Options)) *Options {

loader/loader_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ networks:
109109
- subnet: 172.28.0.0/16
110110
`
111111

112-
var samplePortsConfig = []types.ServicePortConfig{
112+
var samplePortsConfig = types.ServicePorts{
113113
{
114114
Mode: "ingress",
115115
Target: 8080,
@@ -2281,7 +2281,7 @@ services:
22812281
capabilities: ["directX"]
22822282
`)
22832283
assert.NilError(t, err)
2284-
assert.DeepEqual(t, p.Services["test"].Gpus, []types.DeviceRequest{
2284+
assert.DeepEqual(t, p.Services["test"].Gpus, types.GpuDevices{
22852285
{
22862286
Driver: "nvidia",
22872287
Count: -1,
@@ -3889,10 +3889,10 @@ models:
38893889
ContextSize: 1024,
38903890
RuntimeFlags: []string{"--some-flag"},
38913891
})
3892-
assert.DeepEqual(t, p.Services["test_array"].Models, map[string]*types.ServiceModelConfig{
3892+
assert.DeepEqual(t, p.Services["test_array"].Models, types.ServiceModels{
38933893
"foo": nil,
38943894
})
3895-
assert.DeepEqual(t, p.Services["test_mapping"].Models, map[string]*types.ServiceModelConfig{
3895+
assert.DeepEqual(t, p.Services["test_mapping"].Models, types.ServiceModels{
38963896
"foo": {
38973897
EndpointVariable: "MODEL_URL",
38983898
ModelVariable: "MODEL",

0 commit comments

Comments
 (0)