Skip to content

implement normalization as a yaml transformation#589

Merged
jhrotko merged 2 commits intocompose-spec:mainfrom
ndeloof:normalize
Feb 27, 2024
Merged

implement normalization as a yaml transformation#589
jhrotko merged 2 commits intocompose-spec:mainfrom
ndeloof:normalize

Conversation

@ndeloof
Copy link
Copy Markdown
Collaborator

@ndeloof ndeloof commented Feb 22, 2024

This re-implement "normalization" of the compose model as a plain yaml tree (map[string]any) not relying on compose-go structs conversion. This will make it possible to run the full compose processing (i.e docker compose config) without using go bindings, and then restore support for --no-interpolate and such

note: I dropped support for service.dockerfile and service.log_driver as those were defined by compose file v1 format, and using those should be rejected by schema validation

Also introduce LoadModel in addition to the existing LoadProject so compose-go can be used to partially process a compose file, as illustrated with the included command line:

$ compose-spec --format json --no-interpolation --no-normalization compose.yaml  
{
  "services": {
    "test": {
      "command": "env | grep DEBUG",
      "environment": [
        "DEBUG=${FOO}"
      ],
      "image": "alpine",
      "ports": [
        "${PORT}:80"
      ],
      "x-test": "test"
    }
  }
}

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Copy link
Copy Markdown
Collaborator

@glours glours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Just few nits to fix

loader/loader.go Outdated
Comment on lines +304 to +305
// LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
func loadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, opts *Options) (map[string]any, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
func loadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, opts *Options) (map[string]any, error) {
// loadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
func loadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, opts *Options) (map[string]any, error) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this one intentionally public, as LoadProjectWithContext for third party directly passing configDetails

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants