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

Remove headers to reduce image size #42

Open
artemklevtsov opened this issue Mar 18, 2022 · 2 comments
Open

Remove headers to reduce image size #42

artemklevtsov opened this issue Mar 18, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@artemklevtsov
Copy link
Contributor

artemklevtsov commented Mar 18, 2022

We can reduce image size if remove all C/C++ headers from the include directories. For example, BH size is 126 Mb.
Note, only the final image can be optimized this way because headers no needs anymore.
My suggestion is to add the following command to the end of the examples (and FAQ):

    rm -rf ~/.cache/* && \
    rm -rf /var/cache/apk/* && \
    find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.h' -delete && \
    find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.hpp' -delete

Also consider to clean up doc and html, localization files directories in the /usr/local/lib/R/library.

Results.

Example 1:

FROM rhub/r-minimal:4.1
RUN installr -d RcppUUID
❯ docker build --no-cache -t test1 .
❯ docker image ls | grep test1
test1                             latest            2de64ed9d50c   29 seconds ago   174MB

Example 2

FROM rhub/r-minimal:4.1

RUN installr -d RcppUUID && \
    find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.h' -delete && \
    find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.hpp' -delete
❯ docker build --no-cache -t test2 .
❯ docker image ls | grep test2
test2                             latest            100b444eb7ec   3 seconds ago   44.3MB

Update:
Also *.mo, *.pdf files can be removed:

find /usr/local/lib/R/library/ -type f -path '*/po/*' -name '*.mo' -delete
find /usr/local/lib/R/library/ -type f -path '*/doc/*' -name '*.pdf' -delete
@gaborcsardi
Copy link
Collaborator

Yeah, we could have one or more switches in installr to do this.

The main downside of course is that you might not be able to use these Dockerfiles to build other Dockerfiles, if you cannot install packages that depend on (say) BH.

@gaborcsardi gaborcsardi added the enhancement New feature or request label Mar 18, 2022
@gaborcsardi
Copy link
Collaborator

gaborcsardi commented Dec 12, 2023

Maybe a good way to achieve this would be to have an installr option that goes over your library and cleans it up, after installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants