Skip to content

Commit 6bf03b7

Browse files
crazy-maxOrlovEvgeny
authored andcommitted
make modelToProject and toOptions funcs public
Signed-off-by: CrazyMax <[email protected]> Signed-off-by: Evgenii Orlov <[email protected]>
1 parent 3dcedcb commit 6bf03b7

File tree

18 files changed

+83
-69
lines changed

18 files changed

+83
-69
lines changed

cli/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"strings"
2626

2727
"github.com/sirupsen/logrus"
28-
"gopkg.in/yaml.v3"
28+
"go.yaml.in/yaml/v3"
2929

3030
"github.com/compose-spec/compose-go/v2/consts"
3131
"github.com/compose-spec/compose-go/v2/dotenv"

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os"
2525

2626
"github.com/compose-spec/compose-go/v2/cli"
27-
"gopkg.in/yaml.v3"
27+
"go.yaml.in/yaml/v3"
2828
)
2929

3030
func main() {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ require (
1414
github.com/sirupsen/logrus v1.9.0
1515
github.com/stretchr/testify v1.8.4
1616
github.com/xhit/go-str2duration/v2 v2.1.0
17+
go.yaml.in/yaml/v3 v3.0.4
1718
golang.org/x/sync v0.3.0
1819
golang.org/x/text v0.14.0
19-
gopkg.in/yaml.v3 v3.0.1
2020
gotest.tools/v3 v3.4.0
2121
)
2222

2323
require (
2424
github.com/davecgh/go-spew v1.1.1 // indirect
2525
github.com/pmezard/go-difflib v1.0.0 // indirect
2626
golang.org/x/sys v0.5.0 // indirect
27+
gopkg.in/yaml.v3 v3.0.1 // indirect
2728
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
3131
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
3232
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
3333
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
34+
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
35+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
3436
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3537
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
3638
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

loader/loader.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
"github.com/compose-spec/compose-go/v2/validation"
4444
"github.com/go-viper/mapstructure/v2"
4545
"github.com/sirupsen/logrus"
46-
"gopkg.in/yaml.v3"
46+
"go.yaml.in/yaml/v3"
4747
)
4848

4949
// Options supported by Load
@@ -320,17 +320,17 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir strin
320320

321321
// LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
322322
func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {
323-
opts := toOptions(&configDetails, options)
323+
opts := ToOptions(&configDetails, options)
324324
dict, err := loadModelWithContext(ctx, &configDetails, opts)
325325
if err != nil {
326326
return nil, err
327327
}
328-
return modelToProject(dict, opts, configDetails)
328+
return ModelToProject(dict, opts, configDetails)
329329
}
330330

331331
// LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
332332
func LoadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (map[string]any, error) {
333-
opts := toOptions(&configDetails, options)
333+
opts := ToOptions(&configDetails, options)
334334
return loadModelWithContext(ctx, &configDetails, opts)
335335
}
336336

@@ -348,7 +348,7 @@ func loadModelWithContext(ctx context.Context, configDetails *types.ConfigDetail
348348
return load(ctx, *configDetails, opts, nil)
349349
}
350350

351-
func toOptions(configDetails *types.ConfigDetails, options []func(*Options)) *Options {
351+
func ToOptions(configDetails *types.ConfigDetails, options []func(*Options)) *Options {
352352
opts := &Options{
353353
Interpolate: &interp.Options{
354354
Substitute: template.Substitute,
@@ -557,8 +557,8 @@ func load(ctx context.Context, configDetails types.ConfigDetails, opts *Options,
557557
return dict, nil
558558
}
559559

560-
// modelToProject binds a canonical yaml dict into compose-go structs
561-
func modelToProject(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails) (*types.Project, error) {
560+
// ModelToProject binds a canonical yaml dict into compose-go structs
561+
func ModelToProject(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails) (*types.Project, error) {
562562
project := &types.Project{
563563
Name: opts.projectName,
564564
WorkingDir: configDetails.WorkingDir,

loader/normalize_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/compose-spec/compose-go/v2/types"
23-
"gopkg.in/yaml.v3"
23+
"go.yaml.in/yaml/v3"
2424
"gotest.tools/v3/assert"
2525
)
2626

@@ -78,23 +78,23 @@ networks:
7878
func TestNormalizeVolumes(t *testing.T) {
7979
project := `
8080
name: myProject
81-
volumes:
82-
myExternalVol:
81+
volumes:
82+
myExternalVol:
8383
external: true
8484
myvol: {}
85-
myNamedVol:
85+
myNamedVol:
8686
name: CustomName
8787
`
8888

8989
expected := `
9090
name: myProject
91-
volumes:
92-
myExternalVol:
91+
volumes:
92+
myExternalVol:
9393
name: myExternalVol
9494
external: true
95-
myvol:
95+
myvol:
9696
name: myProject_myvol
97-
myNamedVol:
97+
myNamedVol:
9898
name: CustomName
9999
`
100100
var model map[string]any
@@ -114,14 +114,14 @@ func TestNormalizeDependsOn(t *testing.T) {
114114
name: myProject
115115
services:
116116
foo:
117-
depends_on:
117+
depends_on:
118118
bar:
119119
condition: service_healthy
120120
required: true
121121
restart: true
122122
network_mode: service:zot
123123
124-
bar:
124+
bar:
125125
volumes_from:
126126
- zot
127127
- container:xxx
@@ -184,7 +184,7 @@ services:
184184
volumes_from: [quux]
185185
links: [corge]
186186
depends_on: # explicit dependency MUST not be overridden
187-
foo:
187+
foo:
188188
condition: service_healthy
189189
`
190190

@@ -199,25 +199,25 @@ services:
199199
volumes_from: [quux]
200200
links: [corge]
201201
depends_on: # explicit dependency MUST not be overridden
202-
foo:
202+
foo:
203203
condition: service_healthy
204-
bar:
204+
bar:
205205
condition: service_started
206206
restart: true
207207
required: true
208-
baz:
208+
baz:
209209
condition: service_started
210210
restart: true
211211
required: true
212-
qux:
212+
qux:
213213
condition: service_started
214214
restart: true
215215
required: true
216-
quux:
216+
quux:
217217
condition: service_started
218218
required: true
219219
restart: false
220-
corge:
220+
corge:
221221
condition: service_started
222222
restart: true
223223
required: true
@@ -243,13 +243,13 @@ networks:
243243
func TestImplicitContextPath(t *testing.T) {
244244
project := `
245245
name: myProject
246-
services:
246+
services:
247247
test:
248248
build: {}
249249
`
250250
expected := `
251251
name: myProject
252-
services:
252+
services:
253253
test:
254254
build:
255255
context: .
@@ -276,7 +276,7 @@ networks:
276276
func TestNormalizeDefaultNetwork(t *testing.T) {
277277
project := `
278278
name: myProject
279-
services:
279+
services:
280280
test:
281281
image: test
282282
`
@@ -286,8 +286,8 @@ name: myProject
286286
networks:
287287
default:
288288
name: myProject_default
289-
services:
290-
test:
289+
services:
290+
test:
291291
image: test
292292
networks:
293293
default: null
@@ -307,8 +307,8 @@ services:
307307
func TestNormalizeCustomNetwork(t *testing.T) {
308308
project := `
309309
name: myProject
310-
services:
311-
test:
310+
services:
311+
test:
312312
networks:
313313
my_network: null
314314
networks:
@@ -320,8 +320,8 @@ name: myProject
320320
networks:
321321
my_network:
322322
name: myProject_my_network
323-
services:
324-
test:
323+
services:
324+
test:
325325
networks:
326326
my_network: null
327327
`
@@ -340,8 +340,8 @@ services:
340340
func TestNormalizeEnvironment(t *testing.T) {
341341
project := `
342342
name: myProject
343-
services:
344-
test:
343+
services:
344+
test:
345345
environment:
346346
- FOO
347347
- BAR
@@ -353,8 +353,8 @@ name: myProject
353353
networks:
354354
default:
355355
name: myProject_default
356-
services:
357-
test:
356+
services:
357+
test:
358358
environment:
359359
- FOO
360360
- BAR=bar

loader/reset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strings"
2323

2424
"github.com/compose-spec/compose-go/v2/tree"
25-
"gopkg.in/yaml.v3"
25+
"go.yaml.in/yaml/v3"
2626
)
2727

2828
type ResetProcessor struct {

override/merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package override
1919
import (
2020
"testing"
2121

22-
"gopkg.in/yaml.v3"
22+
"go.yaml.in/yaml/v3"
2323
"gotest.tools/v3/assert"
2424
)
2525

parsing.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Compose file parsing
22

3-
This document describes the logic parsing and merging compose file
3+
This document describes the logic parsing and merging compose file
44
and overrides.
55

66
## Phase 1: parse yaml document
77

8-
Yaml document is parsed using de-facto standard [go-yaml](https://github.com/go-yaml/yaml)
8+
Yaml document is parsed using de-facto standard [go-yaml](https://github.com/yaml/go-yaml)
99
library. This one manages anchors and aliases, which are only supported within
1010
a yaml document (an override can't refer to another compose file anchor)
1111

@@ -74,27 +74,27 @@ for `!reset` to remove an element from original service definition.
7474
A compose file can use `include` to rely on compose resources defined by third-parties
7575
as a separate compose file
7676

77-
Included compose definition is fully parsed (as described in this document) then included
77+
Included compose definition is fully parsed (as described in this document) then included
7878
to the compose yaml model being processed. Conflicting resources are detected and rejected
7979

8080
The resulting compose model is equivalent to a copy/paste of the included compose model
8181
(fully resolved) into the local compose file.
8282

8383
# Phase 8: merge overrides
8484

85-
If loaded document is an override, the yaml tree is merged with the one from
85+
If loaded document is an override, the yaml tree is merged with the one from
8686
main compose file. `!reset` can be used to remove elements.
87-
The merge logic generally is "_append to lists, replace in mapping_" with a
87+
The merge logic generally is "_append to lists, replace in mapping_" with a
8888
few exceptions:
8989
- shell commands always are replaced by an override
90-
- `options` is only merged if both file declare the same `driver`, otherwise
90+
- `options` is only merged if both file declare the same `driver`, otherwise
9191
the override fully replaces the original.
9292
- Attributes which can be expressed both as a mapping and a sequence are converted
9393
so that merge can apply on equivalent data structures.
9494

9595
# Phase 9: enforce unicity
9696

97-
While modeled as a list, some attributes actually require some unicity to be
97+
While modeled as a list, some attributes actually require some unicity to be
9898
applied. Volume mount definition for a service typically must be unique
9999
regarding the target mount path. As such attribute can be defined as a single
100100
string and set by a variable, we have to apply the "_append to list_" merge
@@ -113,7 +113,7 @@ must result into an error being reported to the user
113113
networks:
114114
foo:
115115
external: true
116-
driver: macvlan # This will trigger an error, as external network should not have any resource creation parameter set
116+
driver: macvlan # This will trigger an error, as external network should not have any resource creation parameter set
117117
```
118118

119119
# Phase 11: transform into canonical representation
@@ -123,13 +123,13 @@ syntax. It also supports use of single string or list of strings for some
123123
repeatable attributes. Some attributes can be declared both as a list of
124124
key=value strings or as a yaml mapping.
125125

126-
During loading, all those attributes are transformed into canonical
126+
During loading, all those attributes are transformed into canonical
127127
representation, so that we get a single format that will match to go structs
128128
for binding.
129129

130130
# Phase 12: set-defaults
131131

132-
Some attributes are required by the model but optional in the compose file, as an implicit
132+
Some attributes are required by the model but optional in the compose file, as an implicit
133133
default value is defined by the specification, like [`build.context`](https://github.com/compose-spec/compose-spec/blob/master/build.md#context)
134134
During this phase, such unset attributes get default value assigned.
135135

@@ -162,7 +162,7 @@ volumes:
162162

163163
Eventually, the yaml tree can be unmarshalled into go structs. We rely on
164164
[mapstructure](https://github.com/go-viper/mapstructure/) library for this purpose.
165-
Decoder is configured so that custom decode function can be defined by target type,
165+
Decoder is configured so that custom decode function can be defined by target type,
166166
allowing type conversions. For example, byte units (`640k`) and durations set in yaml
167167
as plain string are actually modeled in go types as `int64`.
168168

schema/schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/santhosh-tekuri/jsonschema/v6"
25-
"gopkg.in/yaml.v3"
25+
"go.yaml.in/yaml/v3"
2626
"gotest.tools/v3/assert"
2727
)
2828

0 commit comments

Comments
 (0)