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

Make the container image smaller #753

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

thockin
Copy link
Member

@thockin thockin commented Jun 9, 2023

For each package and binary we need, this pulls in all the files and deps (shared libs, mostly). The build is slower but the final image is 85 MB (versus 157 MB before). e2e passes.

This is based on scripts used in kubernetes and KinD.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 9, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 9, 2023
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

one nit :-)

dpkg -s "${package}" > "${staging}/var/lib/dpkg/status.d/${package}"
}

# helper because bash sometimes barfs on embedded comments
Copy link
Member

Choose a reason for hiding this comment

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

nit: I can't really tell from this comment and the usage context why this is needed. At the call site it's also not obvious what's happening without going back and reading this.

Copy link
Member Author

Choose a reason for hiding this comment

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

grep treats "no match" as an error, which trips up pipefail and errexit

$ echo foo | grep bar; echo $?
1

So we want to do:

$ echo foo | { grep bar || true; }; echo $?
0

Adding back the comments in the style of binary_to_libraries():

$ echo foo \
    `# comment1` \
    | { grep "bar" || true; } \
    `# comment2`; echo $?
bash: syntax error near unexpected token ``# comment2`'

Parens fails the same way.

It works without the braces and || true, but returns error status

$ echo foo     `# comment1`     | grep "bar"     `# comment2`; echo $?
1

Once bash parses {} or () it can't handle subsequent #comment blocks. happy() hides that. I could rename it :)

Copy link
Member

Choose a reason for hiding this comment

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

grep treats "no match" as an error, which trips up pipefail and errexit

instead of swallowing all errors, you can actually detect the no-match case and ignore that

https://github.com/kubernetes-sigs/kind/blob/2e6414694724a44803caff801eeee2b62a5b6765/images/base/files/usr/local/bin/entrypoint#L41-L44

Copy link
Member

Choose a reason for hiding this comment

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

grep_allow_nomatch() {
  # grep exits 0 on match, 1 on no match, 2 on error
  grep "$@" || [ $? = 1 ]
}

Copy link
Member Author

Choose a reason for hiding this comment

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

cute, I guess I should actually read the man page :)

Copy link
Member Author

Choose a reason for hiding this comment

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

PTAL. I want to run a scanner against it to be sure it works, when I get a moment

@BenTheElder
Copy link
Member

For each package and binary we need, this pulls in all the files and deps (shared libs, mostly). The build is slower but the final image is 85 MB (versus 157 MB before). e2e passes.

And hopefully less CVEs.

For each package and binary we need, this pulls in all the files and
deps (shared libs, mostly).  The build is slower but the final image is
85 MB (versus 157 MB before).  e2e passes.  Hopefully less CVE surface.

This is based on scripts used in kubernetes and KinD.
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 12, 2023
@k8s-ci-robot k8s-ci-robot merged commit b60eef6 into kubernetes:master Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants