Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.go: initialize CustomLabels map if nil #9579

Merged
merged 1 commit into from
Jul 12, 2022
Merged

Conversation

paroque28
Copy link
Contributor

@paroque28 paroque28 commented Jun 21, 2022

This change fixes the panic: assignment to entry in nil map error.
I also accessed the map directly instead of the copy value, otherwise the label doesn't get set.

What I did

Related issue

Error that got me here:

panic: assignment to entry in nil map

goroutine 16 [running]:
github.com/docker/compose/v2/pkg/compose.(*composeService).getLocalImagesDigests(0x1c0006d4318?, {0x1579128?, 0xc00069f710?}, 0xc000419220)
        /home/prodrigu/go/pkg/mod/github.com/docker/compose/v2@v2.6.0/pkg/compose/build.go:195 +0x305
github.com/docker/compose/v2/pkg/compose.(*composeService).ensureImagesExists(0x0?, {0x1579128, 0xc00069f710}, 0xc000419220, 0x0)
        /home/prodrigu/go/pkg/mod/github.com/docker/compose/v2@v2.6.0/pkg/compose/build.go:105 +0x7b
github.com/docker/compose/v2/pkg/compose.(*composeService).create(0xc0003efc30?, {0x1579128, 0xc00069f710}, 0xc000419220, {{0xc0004284e0, 0x2, 0x2}, 0x1, 0x0, {0x0, ...}, ...})
        /home/prodrigu/go/pkg/mod/github.com/docker/compose/v2@v2.6.0/pkg/compose/create.go:66 +0x173
github.com/docker/compose/v2/pkg/compose.(*composeService).Up.func1({0x1579128, 0xc00069f710})
        /home/prodrigu/go/pkg/mod/github.com/docker/compose/v2@v2.6.0/pkg/compose/up.go:36 +0x8e
github.com/docker/compose/v2/pkg/progress.Run.func1({0x1579128?, 0xc00069f710?})

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

@paroque28
Copy link
Contributor Author

It's my first PR so any feedback is welcome

Copy link
Contributor

@milas milas left a comment

Choose a reason for hiding this comment

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

Good catch, and thanks for the PR!

CI failed because your commit didn't include a "sign off", you can read the details including how to fix it in the DCO action log - once you've done that and re-pushed, I'll get this merged 🙂

pkg/compose/build.go Outdated Show resolved Hide resolved
@paroque28
Copy link
Contributor Author

Done, thank you @milas :)

@paroque28 paroque28 requested a review from milas June 24, 2022 20:45
@glours
Copy link
Contributor

glours commented Jun 24, 2022

Hey @paroque28
Thanks for your contribution.
Is this PR link to an existing issue? Is it possible to have more context on why this fix? Just want to be sure we address the root cause and not an symptom of the issue

@paroque28
Copy link
Contributor Author

@glours
There is no linked issue, but I can create one if you need it.

The error was this:

panic: assignment to entry in nil map

I think it's a symptom since I am loading my project using the loader.Load() and the result contains an uninitialized CustomLabels map

I also notices that "com.docker.compose.project" was not set, and this is required for doing docker compose up

Here is my code: https://github.com/paroque28/container-chief/blob/master/pkg/manager/compose.go#L128
It's a small function

@glours
Copy link
Contributor

glours commented Jul 4, 2022

@paroque28
We think that this issue should be fix directly in compose-go, so if that's fine for you we'll close this PR

@paroque28
Copy link
Contributor Author

What do you mean in compose-go?

In my opinion people that import your library (like me) are going to hit this error and will have to do the reverse engineering as well . So, I would rather merge this PR but also add the custom labels to the loader.

Idk, there are a couple ways of fixing this...

Adding the labels, asserting ,etc... What do you think?

@glours
Copy link
Contributor

glours commented Jul 4, 2022

@paroque28 when you load the project with loader.Load, you're using a function imported from "github.com/compose-spec/compose-go/loader", the project returned by this function should take care of initializing slices and maps of the internal structure

@paroque28
Copy link
Contributor Author

@glours yes, that's what I did in my code but it's not enough. The loader doesn't initialize the custom labels. That's why I created this PR

@glours
Copy link
Contributor

glours commented Jul 4, 2022

@paroque28 that's exactly my point, we should fix the behavior of loader.Load, I'll open a PR in compose-go

@paroque28
Copy link
Contributor Author

Oh yeah go it!

Sure, let's close this one

@glours glours closed this Jul 4, 2022
@glours
Copy link
Contributor

glours commented Jul 7, 2022

Hey @paroque28
I was starting working on compose-go and reading the code I figured out that the existing code isn't using the safer way to add a custom label
So if you want to make your first contribution to Docker Compose, we can re-open your PR and I'll let you know how to fix properly the issue directly inside Compose code base!
WDYT?

@paroque28
Copy link
Contributor Author

Yes! That sounds perfect :)
How can I help you solve this issue?

@glours glours reopened this Jul 7, 2022
pkg/compose/build.go Outdated Show resolved Hide resolved
pkg/compose/build.go Outdated Show resolved Hide resolved
@paroque28
Copy link
Contributor Author

@glours done, sorry for the delay.

@glours
Copy link
Contributor

glours commented Jul 11, 2022

@paroque28 you need to "sign off" your latest commit to make the CI pass

Copy link
Contributor

@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

Accesing the map directly instead of the copy value, otherwise the label doesn't get set.

Signed-off-by: Pablo Rodriguez <pablo.aarch64@gmail.com>
Copy link

@hmb hmb left a comment

Choose a reason for hiding this comment

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

If the commit message is correct, this might not work. If CustomLabels is nil the code has no effect.

@hmb
Copy link

hmb commented Jun 8, 2024

If the commit message is correct, this might not work. If CustomLabels is nil the code has no effect.

My bad, should have looked into the current code, it's already fixed

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.

4 participants