Code Monkey home page Code Monkey logo

Comments (5)

lance avatar lance commented on August 16, 2024

Our image extends the base image openshift/base-centos7, which itself is 139MB compressed. We add 27MB to it to create a 166MB image. Which is essentially the size of node+npm and that's about it.

So you are right to say that stripping down the image would be good, but that means it will either need to happen as an upstream pull request on https://github.com/sclorg/s2i-base-container which is the repository that creates these base images, or we need to look elsewhere for a base image.

I poked around a little and found the Dockerfile for openshift/base-centos7 here. As you can see, it adds a lot of stuff, but as I dig through it, and think about the work that any s2i image does, it seems there's not much that could be eliminated. Remember, Node.js apps may have native dependencies, and these need to get built by the s2i image during npm install on creation of the output image. So we have to have things like gcc-c++ in these builder images.

This image, as you can see, extends centos7/s2i-core-centos7, which is only about 80MB. So the stuff being installed by openshift/base-centos7 is about 50MB or so compressed.

I'm not sure how much space each of the installed packages require, and I'm not sure which ones are definitively needed for Node.js native modules. But as a quick back of the napkin sketch, here are a couple of things that might be removed:

https://github.com/sclorg/s2i-base-container/blob/aea49ecd81acdc3efdbc0149e461bdeea900817e/base/Dockerfile#L36-L37

https://github.com/sclorg/s2i-base-container/blob/aea49ecd81acdc3efdbc0149e461bdeea900817e/base/Dockerfile#L40-L42

And yes, using dnf instead of yum will probably reduce the image size as well.

We could potentially make our s2i image FROM centos7/s2i-core-centos7, then use dnf instead of yum, duplicates most of what's in openshift/base-centos7, but eliminates some of these seemingly unnecessary packages. I'm not sure how much that would reduce the size. At the moment, this is a bit of a low priority for me, but if you would like to submit a pull request, I'd be happy to take a look.

from centos7-s2i-nodejs.

cesarvr avatar cesarvr commented on August 16, 2024

Awesome, I will take a look to see if the size can be reduced.

from centos7-s2i-nodejs.

lance avatar lance commented on August 16, 2024

@cesarvr I also found information about "chained builds" in the openshift documentation. Using this would allow us to have both a builder image (our current centos7-s2i-nodejs image), and a runtime image that is considerably smaller.

The s2i image would be responsible for creating the runtime artifact - essentially the application source after npm install has been run. And the second, chained builder image would be a stripped down image with only runtime essentials and the application itself installed.

Both paths of effort are useful, but this could be a better long-term strategy, perhaps.

from centos7-s2i-nodejs.

cesarvr avatar cesarvr commented on August 16, 2024

Hi @lance , I was having some fun and try to do my own image from scratch so I create this one cvaldezr/fedora-example (Fedora26).
If you want to give it a try just clone the current project and change the base image to point to cvaldezr/fedora-example and execute docker build --build-arg NODE_VERSION=6.11.2 -t sti-node-light ., so you can test, for now Clang is not included for now.

final container:
centos/sti => 470 MB
cvaldezr/fedora-example => 197MB

I think there are still room for improvement :)

the "chained builds" in OSE is something I didn't hear before, but seems as the way to go achieve very thin final containers, but also, maybe it can take away the simplicity of S2i, not sure.

from centos7-s2i-nodejs.

lance avatar lance commented on August 16, 2024

With the move towards using our own base image, this task has become somewhat irrelevant

from centos7-s2i-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.