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

[Question] Docker multi-stage builds with Bazel #139

Closed
corradio opened this issue Nov 28, 2017 · 9 comments
Closed

[Question] Docker multi-stage builds with Bazel #139

corradio opened this issue Nov 28, 2017 · 9 comments

Comments

@corradio
Copy link

Hi,

I'm looking for best practices to build a nodejs Docker container using Bazel.
Ideally I would use a two-stage docker build (first to build node modules + compile, second to add the compiled assets). However, I can't find how to do that using Bazel.
Is this possible?

Best,

Olivier

@corradio corradio changed the title [Question] Multi-stage builds with Bazel [Question] Docker multi-stage builds with Bazel Nov 28, 2017
@mattmoor
Copy link
Contributor

@dlorenc @alexeagle FYI

tl;dr There isn't a good story today, but I'd like one.

Today rules_nodejs requires you to npm install (or equivalent) to create the node_modules directory in-tree, and it isn't clear to me that the way node_binary is set up is suitable for use by rules_docker as a lang_image rule (I need to poke around the runfiles and see; I don't believe Node.js has a mono-archive form like PAR we can use as a stand-in).

In my idealized world, containerizing a Node.js application with Bazel would be as simple as rewriting node_binary with node_image, but that isn't where we're at for (at least) Node.js today.

@corradio
Copy link
Author

Thanks for your fast answer. I was indeed looking at a similar solution.
My only worry is that by creating node_modules outside of the containerised environment, the native version of the modules would not be used if the blaze platform (e.g. Mac OS) is different from the container platform (e.g. Linux Ubuntu).
I wasn't able to find more documentation about the way native modules are compiled through npm in node.

Happy to contribute if we see a clear way forward.

@mattmoor
Copy link
Contributor

@corradio Yes, although it is not clear to me that there is any good "cross-installation" story for any of the common package managers (e.g. npm, pip, ...), which is what we'd need to achieve this in Bazel without remote execution (where you'd actually run it on the target environment).

I think that there are two tiers of this:

  1. Get this working for node_binary to node_image.
  2. Get node_binary working for cross-compilation (a la cross-installation).

If there is a story for cross-installation in npm I think it makes a strong argument for moving package installation into a repository_rule that is sensitive to the target Platform.

@mattmoor
Copy link
Contributor

I tried out the Dropbox rules_node, but hit a few issues (1, 2).

Trying out bazelbuild/rules_nodejs it took me a while to make sense of their samples, but I was able to get something super trivial working (as I could with Dropbox), but not with node_modules (see here).

@mattmoor
Copy link
Contributor

mattmoor commented Dec 3, 2017

So I have a basic npm_install rule working here with bazelbuild/rules_nodejs and on top of these I was able to get a nodejs_image rule working on top of bazelbuild/rules_docker, but only with gcr.io/google-appengine/nodejs and not gcr.io/distroless/nodejs.

The reason for this is that the entrypoint that bazelbuild/rules_nodejs creates is a bash script, so it doesn't even seem to work on gcr.io/distroless/nodejs:debug.

I'll keep looking at this, but that seems like good progress :)

@corradio
Copy link
Author

corradio commented Dec 3, 2017

Great! I'm quite busy in the next days but will try to help out as soon as I have a bit of time.

@mattmoor
Copy link
Contributor

mattmoor commented Dec 3, 2017

If you have a chance to check it out here's the PR: bazelbuild/rules_docker#254

It is based on a couple PRs that need to land elsewhere (thus WiP), but I'd appreciate a second opinion on its readiness :)

thanks.

@dlorenc
Copy link
Contributor

dlorenc commented Jul 2, 2018

Is this still relevant?

@chanseokoh
Copy link
Member

Closing as the question seems obsolete now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants