Skip to content

config: use correct YAML marshal func#9712

Merged
milas merged 1 commit intodocker:v2from
milas:config-yaml-marshal
Aug 3, 2022
Merged

config: use correct YAML marshal func#9712
milas merged 1 commit intodocker:v2from
milas:config-yaml-marshal

Conversation

@milas
Copy link
Contributor

@milas milas commented Aug 3, 2022

What I did
When marshalling via CLI (compose convert / compose config), we
were using a different YAML lib, which was a fork of go-yaml,
which is what gopkg.in/yaml.v2 is based off of.

The compose-spec/compose-go lib is written with gopkg.in/yaml.v2
as a target, so I changed it to use that for marshalling the config.

The fork that was being used was sanathkr/go-yaml.
Looking through git log, this was originally introduced transitively by
old ECS/CloudFormation code (that now lives in compose-cli), so its
usage was likely the result of IDE auto-complete and not intentional.

The only change it added compared to the upstream lib was custom tag
support, which is not something we use (and regardless, since the unmarshal
is done with a different lib, it wouldn't work regardless). See go-yaml/yaml@ed9d249.

Related issue
I discovered this when working on compose-spec/compose-go#298.

(not mandatory) A picture of a cute animal, if possible in relation with what you did
a cat in a shark costume

@milas milas added kind/cleanup dependencies Pull requests that update a dependency file labels Aug 3, 2022
@milas milas requested a review from a team August 3, 2022 16:29
@milas milas self-assigned this Aug 3, 2022
@milas
Copy link
Contributor Author

milas commented Aug 3, 2022

As a bonus, this shrinks the executable size by ~100KB* 🥳

* Binary is ~27MB so nobody will notice 😛

Copy link
Member

@nicksieger nicksieger left a comment

Choose a reason for hiding this comment

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

Good find! 😎

@thaJeztah
Copy link
Member

Had a quick peek if there was a specific reason for using this library; I see this was added as part of 7f8bb03, which originally came from docker-archive/compose-cli@7f8bb03 (docker-archive/compose-cli#544), but review on that PR doesn't mention a specific reason

/cc @ndeloof @rumpl (just in case)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM (not a maintainer)

The `compose-spec/compose-go` lib is written with `gopkg.in/yaml.v2`
as a target.

When marshalling via CLI (`compose convert` / `compose config`), we
were using a _different_ YAML lib, which was a fork of `go-yaml`,
which is what `gopkg.in/yaml.v2` is based off of.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
@milas milas force-pushed the config-yaml-marshal branch from 8b279fa to c248e88 Compare August 3, 2022 20:29
@milas
Copy link
Contributor Author

milas commented Aug 3, 2022

Had a quick peek if there was a specific reason for using this library; I see this was added as part of 7f8bb03, which originally came from docker/compose-cli@7f8bb03 (docker/compose-cli#544), but review on that PR doesn't mention a specific reason

Yup, I'm fairly certain it got auto-imported because it was already available as an indirect dependency at the time!

And even if we had been attempting to utilize the custom YAML tag logic it added...it wouldn't work since we weren't ever using it for unmarshaling in the compose-go code

(Sidenote: I spent like 20 mins reading about YAML tags this morning and I still don't really understand them 😵)

@milas milas enabled auto-merge (squash) August 3, 2022 20:34
@milas milas merged commit 1ee44a0 into docker:v2 Aug 3, 2022
@milas milas deleted the config-yaml-marshal branch August 4, 2022 15:36
laurentsimon pushed a commit to laurentsimon/compose that referenced this pull request Aug 10, 2022
The `compose-spec/compose-go` lib is written with `gopkg.in/yaml.v2`
as a target.

When marshalling via CLI (`compose convert` / `compose config`), we
were using a _different_ YAML lib, which was a fork of `go-yaml`,
which is what `gopkg.in/yaml.v2` is based off of.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants