Skip to content

[WIP] support for building nodejs_npm functions #44

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

Merged
merged 35 commits into from
Dec 10, 2018
Merged

[WIP] support for building nodejs_npm functions #44

merged 35 commits into from
Dec 10, 2018

Conversation

gojko
Copy link
Contributor

@gojko gojko commented Dec 1, 2018

Description of changes: Initial support for building nodejs_npm, for early code review. This does not yet support building projects with local dependencies.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

Thank you so much for contributing. Really appreciate all the hardwork you have put in here.

It might look like there are a lot of comments. But most of my comments are in general about Python or the conventions used in this project. So feel free to ignore or let me know if you disagree. I am happy to hear your thoughts. I believe we can get to a better design by collaborating this way.


LOG.debug("NODEJS packaging %s to %s", package_path, self.scratch_dir)

tarfile_name = self.subprocess_npm.main(['pack', '-q', package_path], cwd=self.scratch_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is tarball the only option? We need to tar and untar again unnecessarily.

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, as far as I know. npm pack produces a tarball (https://docs.npmjs.com/cli/pack)

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, cool. Let's stick with this then.

One downside of this is, when we implement hot-reloading we have to modify this implementation. But that's for later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, should I leave some kind of todo note there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, in theory, we can do hot reloading to check if package.json got modified. if yes, then rerun the whole tar thing. if only a file within the project got modified, and not package.json, then it's pretty safe to assume that packaging didn't change and dependencies did not change as well, so it's OK to just safe-reload that file.

@sanathkr
Copy link
Contributor

sanathkr commented Dec 3, 2018

Copying conversation from slack on difference between claudia pack and this implementation for sake of tracking:

claudia pack vs node_npm workflow from @gojko

There are features in claudia pack that are not in the code yet, but 90% of the common cases will be covered by what I submitted in the PR

  1. There is a lot of complexity to handle local file dependencies, which I find very useful for my work as I like to keep multiple projects in the same repository and just refer locally to them as dependencies. Once I know that the overall code design is OK, I’ll port that over.

  2. Another thing very useful in claudia pack that’s not here is the ability to exclude optional dependencies (we discussed that earlier, I will add an flag that depends on an environment variable to activate/deactivate that).

  3. The third thing I also think is worth porting over from claudia pack is an option to run a post-package script for any kind of project specific build. NPM has the ability to put build phase scripts (similar to Maven) into the manifest, not just dependencies... so this would be a way for developers to customise the stuff sent up to lambda in an automated way

gojko added 2 commits December 3, 2018 19:30
- restored old osutils into python_pip to avoid unnecessary changes
- removed the guard for manifest not existing (as per
#44 (comment))
Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

Couple of other minor comments..

This is starting to shape up really well :)

self.osutils = osutils

if npm_exe is None:
npm_exe = 'npm'
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future if there are multiple paths of npm on your system, how would you imagine passing them in? or maybe thats not a big concern.

I started a PR here: #35 that would help with that. But I'm going to take a step back and maybe write a mini design doc to get started on it. I was curious to know if you had any comments on that?

#44 (comment))
- using ValueError for argument type error (as per
#44 (comment))
@sanathkr
Copy link
Contributor

sanathkr commented Dec 3, 2018

@gojko we also need to setup Travis & AppVeyor to run tests with a node environment. This is going to be interesting. I am happy to punt this work to a separate PR because it requires more wrangling..

@gojko
Copy link
Contributor Author

gojko commented Dec 3, 2018

It looks like the overall design of the code is OK? I'll then add unit tests and we can start closing off the first release of this.

Regarding NPM, we could somehow split out integration tests that require NPM from the rest, so you can run them on two different integration test environments. Let me know if that's an option.

@sanathkr
Copy link
Contributor

sanathkr commented Dec 3, 2018

Everything looks good, except for the unique_dir comment. Do start writing unit tests. I will create a separate Travis/Appveyor PR to run integ tests

@sanathkr
Copy link
Contributor

sanathkr commented Dec 3, 2018

Also, is there a min version of Nodejs & NPM that this implementation assumes?

@gojko
Copy link
Contributor Author

gojko commented Dec 3, 2018

Also, is there a min version of Nodejs & NPM that this implementation assumes?

this just runs the NPM executable, so as long as there is one on the path, it will work. NPM tends to ignore parameters that it does not understand, so --no-audit and --no-save will have no effect on earlier versions where they are not supported.

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

We are in the homestretch here. Logic all looks great! One minor comment about exceptions, and everything else is docstrings.

Can you add docstrings to the classes & methods? Following a reStructuredText doc format (like this: https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflow.py#L84-L117)

I will also keep the PR open for unit tests

@sanathkr
Copy link
Contributor

sanathkr commented Dec 4, 2018

@gojko I just pushed a commit to your branch fixing appveyor & travis - 7eaad47

Also, can you update the PR to send against develop branch instead of master?

The code looks good to me! I think we are good to merge once the integ tests pass

@gojko gojko changed the base branch from master to develop December 4, 2018 18:57
@gojko
Copy link
Contributor Author

gojko commented Dec 4, 2018

Also, can you update the PR to send against develop branch instead of master?

I've updated the base to merge into develop using the github UI, not sure if that will do the trick or not. if this looks wrong to you, i'll create a completely clean PR

@sanathkr
Copy link
Contributor

sanathkr commented Dec 4, 2018

Yup, that's good enough :)

Looks like the integ tests are failing on Windows because its not able to find node/npm :(

@gojko
Copy link
Contributor Author

gojko commented Dec 4, 2018

I wonder if npm is a separate package you need to install there? it looks like node is installed, but it's not finding NPM.

@sanathkr
Copy link
Contributor

sanathkr commented Dec 4, 2018

that's surprising. I tested the appveyor config here - sanathkr@713d5b2. It did print npm version - https://ci.appveyor.com/project/sanathkr/aws-lambda-builders/builds/20767787/job/5k44u8p3pujh7kg3

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

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

Overall this looks really good @gojko Nothing super critical in my feedback.


if npm_exe is None:
if osutils.is_windows():
npm_exe = 'npm.cmd'
Copy link
Contributor

Choose a reason for hiding this comment

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

Does npm have a npm.exe at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

no it doesn't unfortunately. I verified on a windows box


from aws_lambda_builders.workflows.nodejs_npm.actions import NodejsNpmPackAction, NodejsNpmInstallAction

from aws_lambda_builders.actions import CopySourceAction
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP 8 imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi, I'm not actively working with python do I don't know what you mean by this. What would you like me to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved in 6863067

@sanathkr
Copy link
Contributor

sanathkr commented Dec 5, 2018

Just realized, we never wrote a design document for this. This is just a simple markdown file that explains what the workflow does, like this - https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/python_pip/DESIGN.md.

Goal is to let other implementors understand why certain decisions were made. It helps us set context for future design changes.

If you got time, can you add a short design document? If you feel the PR is already big, we can do it in a separate PR later

@gojko
Copy link
Contributor Author

gojko commented Dec 5, 2018

If you got time, can you add a short design document? If you feel the PR is already big, we can do it in a separate PR later

I added this here 09d4190

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

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

Two small comments on the design doc. This looks really good!

:param osutils: An instance of OS Utilities for file manipulation

:type npm_exe: str
:param npm_exe: Path to the NPM binary. If not set,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with keeping this here for the PR, but eventually we need the workflow to start with absolute paths to dependency managers, language etc to ensure a correct build?

I have started a PR here with design notes: https://github.com/awslabs/aws-lambda-builders

Let me know on your thoughts!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thesriram I guess as long as you pass an executable into the workflow as a standard parameter, we can easily pass it to the NPM wrapper there, so it should be a single line of code change once it is ready.

@sriram-mv
Copy link
Contributor

The PR looks good to me. My only concern was to be able plugin path resolvers and path validators appropriately without much effort after this gets merged, which is what I have commented.

@sanathkr
Copy link
Contributor

sanathkr commented Dec 6, 2018

@gojko Please confirm this contribution is under the terms of the Apache 2.0 license. Thanks.

@gojko
Copy link
Contributor Author

gojko commented Dec 6, 2018

@sanathkr I confirm that my contribution is made under the terms of the Apache 2.0 license.

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

Successfully merging this pull request may close these issues.

4 participants