Skip to content

crane: Mutate does not always preserve order of env variables #1542

@yoks

Description

@yoks

Describe the bug

crane mutate does not always preserve order of the env variables in the json manifest. This leads to inconsistent digest of the final image.

To Reproduce

From the main branch

go run cmd/crane/main.go mutate ubuntu --platform=linux/amd64 --env=A=A --env=B=B --env=C=C --env=D=D --output=image.tar

Most the the time order is perserved but there is rare cases than:

{"architecture":"amd64","container":"8bf713004e88c9bc4d60fe0527a509636598e73e3ad1e71a9c9123c863c17c31","created":"2022-12-09T01:20:31.321639501Z","docker_version":"20.10.12","history":[{"created":"2022-12-09T01:20:30.834419054Z","created_by":"/bin/sh -c #(nop) ADD file:481dd2da6de71525248eba186feeeafcc73cc956ade0a196a4e8b0c2424e74b9 in / "},{"created":"2022-12-09T01:20:31.321639501Z","created_by":"/bin/sh -c #(nop)  CMD [\"bash\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:6515074984c6f8bb1b8a9962c8fb5f310fc85e70b04c88442a3939c026dbfad3"]},"config":{"Cmd":["bash"],"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","D=D","A=A","B=B","C=C"],"Image":"sha256:070606cf58d59117ddc1c48c0af233d6761addbcd4bf9e8e39fd10eef13c1bb7"}}
{"architecture":"amd64","container":"8bf713004e88c9bc4d60fe0527a509636598e73e3ad1e71a9c9123c863c17c31","created":"2022-12-09T01:20:31.321639501Z","docker_version":"20.10.12","history":[{"created":"2022-12-09T01:20:30.834419054Z","created_by":"/bin/sh -c #(nop) ADD file:481dd2da6de71525248eba186feeeafcc73cc956ade0a196a4e8b0c2424e74b9 in / "},{"created":"2022-12-09T01:20:31.321639501Z","created_by":"/bin/sh -c #(nop)  CMD [\"bash\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:6515074984c6f8bb1b8a9962c8fb5f310fc85e70b04c88442a3939c026dbfad3"]},"config":{"Cmd":["bash"],"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","A=A","B=B","C=C","D=D"],"Image":"sha256:070606cf58d59117ddc1c48c0af233d6761addbcd4bf9e8e39fd10eef13c1bb7"}}

Manifests have different order of env variables

Expected behavior

Mutate should always preserve order of the env variables.

Additional context

It does not work on the current main as well as 0.12.0 version.
go version go1.19.5 linux/amd64

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions