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
fix(image): add logic to detect empty layers #2790
Conversation
pkg/fanal/image/daemon/image.go
Outdated
return true | ||
} | ||
// commands here: 'ADD', COPY, RUN and WORKDIR != "/" | ||
// Also RUN command may don't include 'RUN' prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it happen? I thought RUN
was required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Also RUN command may don't include 'RUN' prefix | |
// Also RUN command may not include 'RUN' prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Image created with docker build
command may not include command prefix.
Docker docs have this.
e.g.
Dockerfile:
FROM alpine
RUN mkdir test
RUN apk update
History:
➜ docker history 2780:test
IMAGE CREATED CREATED BY SIZE COMMENT
b06f8dfdd74d 6 seconds ago /bin/sh -c apk update 2.29MB
4d55786712ed 8 hours ago /bin/sh -c mkdir test 0B
0ac33e5f5afa 4 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 4 months ago /bin/sh -c #(nop) ADD file:5d673d25da3a14ce1… 5.57MB
Also layers created with buildkit
have command prefix:
➜ docker history 2780:test2
IMAGE CREATED CREATED BY SIZE COMMENT
8485e63ed150 5 seconds ago RUN /bin/sh -c apk update # buildkit 2.29MB buildkit.dockerfile.v0
<missing> 8 minutes ago RUN /bin/sh -c mkdir test # buildkit 0B buildkit.dockerfile.v0
<missing> 4 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 4 months ago /bin/sh -c #(nop) ADD file:5d673d25da3a14ce1… 5.57MB
{ | ||
name: "ENV", | ||
history: dimage.HistoryResponseItem{ | ||
CreatedBy: "/bin/sh -c #(nop) ENV TESTENV=TEST", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BuiltKit doesn't have /bin/sh -c #(nop)
prefix. I also want to add such a case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Description
Added logic to detect empty layers.
Logic is taken from buildkit.
Checklist