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

[WIP] White-list nodejs for aws-lambda-builders #845

Merged
merged 10 commits into from
Dec 12, 2018
Merged

Conversation

gojko
Copy link
Contributor

@gojko gojko commented Dec 8, 2018

Issue #, if available: #798

Description of changes: White-list nodejs for aws-lambda-builders, required to use the nodejs_npm builder from SAM CLI. This should be merged only after aws/aws-lambda-builders#44 is merged

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

@jfuss
Copy link
Contributor

jfuss commented Dec 10, 2018

@gojko Thanks for submitting this. I have just merged the NPM building into aws-lambda-builders. We still need to test this end-to-end from sam cli and publish a new version of the aws-lambda-builders. We will need to include that version into this PR otherwise, building node will not work.

I am doing some testing locally and using the --use-container flag. I can submit the integ tests and version bump here if you would like?

@jfuss
Copy link
Contributor

jfuss commented Dec 10, 2018

Tested with nodejs8.10:

sam init --runtime nodejs8.10 --name node-builder-testing
cd node-builder-testing
sam build
# remove cache created by previous sam build
rm -rf .aws-sam/

sam build --use-container

The sam build on my machine (without --use-container) worked as expected. I don't have node 8.10 locally though but not sure if that is expected to fail.

node -v
v8.9.1

When running sam build --use-container, I get this error:

Build Failed
'nodejs' runtime has not been validated!

This is due to the cli that is within the aws-lambda-builders doing validation. Looks like we missed this during the implementation for the node builder.

I am looking at how to address this now.

@gojko
Copy link
Contributor Author

gojko commented Dec 10, 2018

any version of node is OK for this (it's executing the npm binary). I think even ancient versions such as 0.10 will still pack the files correctly. There might be problems executing custom scripts, but in that case NPM would explode with a reasonable error message and users would know how to fix it.

I've not tried the --use-container option when testing locally, I guess that's a good note for future builder implementations to remember.

@jfuss
Copy link
Contributor

jfuss commented Dec 10, 2018

Testing locally with a dev build of the container is not trivial right now. :(

@gojko How should we go about validating? The build for python checks for explicit versions. By the sounds of it, we only care about npm? I am not super familiar with the nodejs world and how to go about this right now.

@gojko
Copy link
Contributor Author

gojko commented Dec 10, 2018

@jfuss I think the python validation problem is specific because SAM is a python app building other python apps potentially needing different virtualenvs. My best guess is that for node we only care about npm existing.

Until someone complains and actually has a problem that we could test against I suggest we don't do any additional validation apart from checking for NPM.

@jfuss
Copy link
Contributor

jfuss commented Dec 11, 2018

@gojko I updated the nodejs init examples and updated the aws-lambda-builders to 0.0.4 but can't push this to your remote so it shows up in this PR. Then the only thing left would be to write integ tests for building node.

@jfuss
Copy link
Contributor

jfuss commented Dec 12, 2018

@thesriram When you get some time, can you please review.

@gojko If you could look at the changes to the nodejs example I made, I would really appreciate it. I want to make sure the example aligns with what the community would expect. My one concern is that the package.json file in the function folder makes it hard to test the application through unit, functional, or integration tests. You have to cd into that directory in order to run npm run test and not sure if there is a practice to get around this.

@sriram-mv sriram-mv self-requested a review December 12, 2018 18:01
@@ -51,6 +51,12 @@ def _get_workflow_config(runtime):
dependency_manager="pip",
application_framework=None,
manifest_name="requirements.txt")
elif runtime.startswith("nodejs"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Noo, lets not do if else's again, this might become like our entrypoint file. Given that there may be more runtimes that we support building.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is your suggestion then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion is to be encapsulate in a dictionary, and invoke corresponding actions based on a match. But I will not block on this. we can address this separately, I'll create an issue.

@@ -16,7 +16,7 @@ Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
CodeUri: hello-world/
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious: any reason for the change in the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Conversations with people familiar with Node.js said dashes are used not underscores. So I changed this to make it match what the community is doing/the Node.js style


FUNCTION_LOGICAL_ID = "Function"

@parameterized.expand([
Copy link
Contributor

Choose a reason for hiding this comment

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

Brilliant! thanks for adding all cases!

self._verify_resource_property(str(self.built_template),
"OtherRelativePathResource",
"BodyS3Location",
os.path.relpath(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thats a lotta path heh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Mostly stolen from the python above.

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

Approved. 👍

@jfuss jfuss merged commit bd7b669 into aws:develop Dec 12, 2018
@gojko
Copy link
Contributor Author

gojko commented Dec 13, 2018

@gojko If you could look at the changes to the nodejs example I made, I would really appreciate it. I want to make sure the example aligns with what the community would expect. My one concern is that the package.json file in the function folder makes it hard to test the application through unit, functional, or integration tests. You have to cd into that directory in order to run npm run test and not sure if there is a practice to get around this.

It looks fine to me. My workflow is usually to whitelist files/directories by including them into package.json files section, so instead of excluding tests via .npmignore, I'd create something like

files: ['app.js']

but both approaches are equally valid. Regarding test execution, I think this is OK. There are tools like lerna that help manage multi-directory projects, but there isn't anything that could be called standard, at least not that I know of it. I usually just script it using a makefile.

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.

3 participants