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

This adds a simple / functional nodejs_image rule. #254

Merged
merged 3 commits into from
Dec 11, 2017

Conversation

mattmoor
Copy link
Contributor

@mattmoor mattmoor commented Dec 3, 2017

For now these images are based on gcr.io/google-appengine/base instead of gcr.io/distroless/nodejs for two reasons:

  1. The nodejs_binary runfiles includes the node binary, so we need not use a Node.JS base runtime.
  2. The generated nodejs_binary entrypoint is currently a bash script, so if/until we can move this logic into our own entrypoint we need a more substantial base runtime.

@mattmoor mattmoor requested a review from dlorenc December 3, 2017 22:59
@mattmoor
Copy link
Contributor Author

mattmoor commented Dec 3, 2017

@dlorenc mostly opening this to see if testing passes. This still depends on this, so until it's upstreamed this should be considered WiP.

@mattmoor
Copy link
Contributor Author

mattmoor commented Dec 3, 2017

@alexeagle FYI

Right now this will create an image with 3 additional layers:

  1. Node binary
  2. node_modules
  3. The remaining runfiles

Copy link
Contributor

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

/cc @gregmagolan we should try this out when we get to protractor testing


**It is notable that unlike the other image rules, `nodejs_image` is not
currently using the `gcr.io/distroless/nodejs` image for a handful of reasons.**
This is a switch we plan to make, when we can manage it. We are currently
Copy link
Contributor

Choose a reason for hiding this comment

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

I need to remove bash dependencies for a lighter windows install anyway, so we should follow up on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to make the entrypoint itself Node.js?

If we can reduce the entrypoint logic to the point where I can just invoke Node directly (possibly bypassing a script that does that same) I'm happy to do that (I do that with Java).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is the plan


# Install your declared Node.js dependencies
npm_install(
name = "npm_deps",
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the canonical name users should always pick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily, I'm just not very creative I guess :)

README.md Outdated

# Download base images, etc.
load(
"//nodejs:image.bzl",
Copy link
Contributor

Choose a reason for hiding this comment

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

looks wrong, should have an external workspace reference if this is for a users WORKSPACE`?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

# other repositories.
def _external_dir(ctx):
# For @foo//bar/baz:blah this would translate to
# /app/bar/baz/blah.runfiles/foo/external
Copy link
Contributor

Choose a reason for hiding this comment

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

foo/external -> external/foo right?

by the way did you see bazelbuild/bazel#1262

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends if @foo is ourself or not, which I'll admit wasn't super clear to me when I first lifted this from one of these other functions (_reference_dir IIRC). From @foo a @bar reference would be: ...runfiles/foo/external/bar == ...runfiles/bar.

nodejs/image.bzl Outdated
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A rule for creating a Rust container image.
Copy link
Contributor

Choose a reason for hiding this comment

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

update comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LOL whoops


# !!!! THIS IS A GENERATED FILE TO NOT EDIT IT BY HAND !!!!
#
# To regenerate this file, run ./update_deps.sh from the root of the
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting / gross

implementation = _dep_layer_impl,
)

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
Copy link
Contributor

Choose a reason for hiding this comment

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

note, that is a macro (mostly to attach the ibazel tag for fast dev roundtrip)
so it's possible you want to reach into //internal:node.bzl instead

# Put the Node binary into its own layer.
"@nodejs//:bin/node",
# node_modules can get large, it should be in its own layer.
node_modules,
Copy link
Contributor

Choose a reason for hiding this comment

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

if you're concerned about size, you could try filtering out stuff.
This isn't the right spot to do it - but where the node_modules filegroup was declared, it's nice to drop things like test data that npm authors lazily published along with their package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think we want this in rules_nodejs :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I filter /test/* now, hopefully that helps and doesn't break things

@mattmoor mattmoor force-pushed the node_image branch 2 times, most recently from 1a1debf to aa7a0b5 Compare December 5, 2017 04:31
@mattmoor
Copy link
Contributor Author

mattmoor commented Dec 5, 2017

Twiddling for CI

@mattmoor mattmoor closed this Dec 5, 2017
@mattmoor mattmoor reopened this Dec 5, 2017
@mattmoor mattmoor changed the title [WiP] This adds a simple / functional nodejs_image rule. This adds a simple / functional nodejs_image rule. Dec 5, 2017
@mattmoor
Copy link
Contributor Author

mattmoor commented Dec 5, 2017

@dlorenc this should be RFAL (assuming CI is happy).

For now these images are based on gcr.io/google-appengine/base instead of gcr.io/distroless/nodejs for two reasons:
1. The nodejs_binary runfiles includes the node binary, so we need not use a Node.JS base runtime.
1. The generated nodejs_binary entrypoint is currently a bash script, so if/until we can move this logic into our own entrypoint we need a more substantial base runtime.
@mattmoor mattmoor merged commit 1813f65 into bazelbuild:master Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants