Skip to content

Commit

Permalink
Add nodejs20.x support for samcli (aws#508)
Browse files Browse the repository at this point in the history
* Add nodejs20.x support for samcli

* Add nodejs20.x as preview runtime

* change github action to install nodejs 20.x

---------

Co-authored-by: Mohamed Elasmar <[email protected]>
  • Loading branch information
andclt and moelasmar authored Oct 11, 2023
1 parent 79511e5 commit 2126bc9
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
ruby-version: "3.2"
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
Supported Runtimes
------------------
1. Python 3.7, 3.8, 3.9, 3.10, 3.11 using PIP\n
2. Nodejs 18.x, 16.x, 14.x, 12.x using NPM\n
2. Nodejs 20.x, 18.x, 16.x, 14.x, 12.x using NPM\n
3. Ruby 2.7, 3.2 using Bundler\n
4. Java 8, Java 11, Java 17 using Gradle and Maven\n
5. Dotnet6 using Dotnet CLI (without --use-container)\n
Expand Down
2 changes: 2 additions & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def get_layer_subfolder(build_workflow: str) -> str:
"nodejs14.x": "nodejs",
"nodejs16.x": "nodejs",
"nodejs18.x": "nodejs",
"nodejs20.x": "nodejs",
"ruby2.7": "ruby/lib",
"ruby3.2": "ruby/lib",
"java8": "java",
Expand Down Expand Up @@ -161,6 +162,7 @@ def get_workflow_config(
"nodejs14.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs16.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs18.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs20.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"ruby2.7": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"ruby3.2": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"dotnet6": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/utils/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"nodejs14.x": [ARM64, X86_64],
"nodejs16.x": [ARM64, X86_64],
"nodejs18.x": [ARM64, X86_64],
"nodejs20.x": [ARM64, X86_64],
"python3.7": [X86_64],
"python3.8": [ARM64, X86_64],
"python3.9": [ARM64, X86_64],
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/utils/preview_runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"""
from typing import Set

PREVIEW_RUNTIMES: Set[str] = set()
PREVIEW_RUNTIMES: Set[str] = {"nodejs20.x"}
4 changes: 3 additions & 1 deletion samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"nodejs": [
{
"runtimes": ["nodejs18.x", "nodejs16.x", "nodejs14.x", "nodejs12.x"],
"runtimes": ["nodejs20.x", "nodejs18.x", "nodejs16.x", "nodejs14.x", "nodejs12.x"],
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"),
"build": True,
Expand Down Expand Up @@ -107,6 +107,7 @@ def get_local_lambda_images_location(mapping, runtime):
"java8.al2",
"java8",
# nodejs runtimes in descending order
"nodejs20.x",
"nodejs18.x",
"nodejs16.x",
"nodejs14.x",
Expand Down Expand Up @@ -134,6 +135,7 @@ def get_local_lambda_images_location(mapping, runtime):
"java11": "amazon/java11-base",
"java8.al2": "amazon/java8.al2-base",
"java8": "amazon/java8-base",
"nodejs20.x": "amazon/nodejs20.x-base",
"nodejs18.x": "amazon/nodejs18.x-base",
"nodejs16.x": "amazon/nodejs16.x-base",
"nodejs14.x": "amazon/nodejs14.x-base",
Expand Down
14 changes: 14 additions & 0 deletions samcli/local/docker/lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ def get_debug_settings(debug_port, debug_args_list, _container_env_vars, runtime
**_container_env_vars,
},
),
Runtime.nodejs20x.value: lambda: DebugSettings(
entry
+ ["/var/lang/bin/node"]
+ debug_args_list
+ ["--no-lazy", "--expose-gc"]
+ ["/var/runtime/index.mjs"],
container_env_vars={
"NODE_PATH": "/opt/nodejs/node_modules:/opt/nodejs/node20/node_modules:/var/runtime/node_modules:"
"/var/runtime:/var/task",
"NODE_OPTIONS": f"--inspect-brk=0.0.0.0:{str(debug_port)} --max-http-header-size 81920",
"AWS_EXECUTION_ENV": "AWS_Lambda_nodejs20.x",
**_container_env_vars,
},
),
Runtime.python37.value: lambda: DebugSettings(
entry + ["/var/lang/bin/python3.7"] + debug_args_list + ["/var/runtime/bootstrap"],
container_env_vars=_container_env_vars,
Expand Down
1 change: 1 addition & 0 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Runtime(Enum):
nodejs14x = "nodejs14.x"
nodejs16x = "nodejs16.x"
nodejs18x = "nodejs18.x"
nodejs20x = "nodejs20.x"
python37 = "python3.7"
python38 = "python3.8"
python39 = "python3.9"
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,12 @@ class TestBuildCommand_NodeFunctions(BuildIntegNodeBase):
("nodejs14.x", False),
("nodejs16.x", False),
("nodejs18.x", False),
("nodejs20.x", False),
("nodejs12.x", "use_container"),
("nodejs14.x", "use_container"),
("nodejs16.x", "use_container"),
("nodejs18.x", "use_container"),
("nodejs20.x", "use_container"),
]
)
@pytest.mark.flaky(reruns=3)
Expand All @@ -691,6 +693,7 @@ class TestBuildCommand_NodeFunctions_With_External_Manifest(BuildIntegNodeBase):
("nodejs14.x",),
("nodejs16.x",),
("nodejs18.x",),
("nodejs20.x",),
]
)
@pytest.mark.flaky(reruns=3)
Expand Down Expand Up @@ -766,6 +769,14 @@ class TestBuildCommand_EsbuildFunctions_With_External_Manifest(BuildIntegEsbuild
False,
"arm64",
),
(
"nodejs20.x",
"Esbuild/Node_without_manifest",
{"main.js", "main.js.map"},
"main.lambdaHandler",
False,
"arm64",
),
(
"nodejs14.x",
"Esbuild/TypeScript_without_manifest",
Expand All @@ -790,6 +801,14 @@ class TestBuildCommand_EsbuildFunctions_With_External_Manifest(BuildIntegEsbuild
False,
"arm64",
),
(
"nodejs20.x",
"Esbuild/TypeScript_without_manifest",
{"app.js", "app.js.map"},
"app.lambdaHandler",
False,
"arm64",
),
]
)
@pytest.mark.flaky(reruns=3)
Expand Down Expand Up @@ -817,8 +836,10 @@ class TestBuildCommand_EsbuildFunctionProperties(BuildIntegEsbuildBase):
[
("nodejs16.x", "../Esbuild/TypeScript", "app.lambdaHandler", "x86_64"),
("nodejs18.x", "../Esbuild/TypeScript", "app.lambdaHandler", "x86_64"),
("nodejs20.x", "../Esbuild/TypeScript", "app.lambdaHandler", "x86_64"),
("nodejs16.x", "../Esbuild/TypeScript", "nested/function/app.lambdaHandler", "x86_64"),
("nodejs18.x", "../Esbuild/TypeScript", "nested/function/app.lambdaHandler", "x86_64"),
("nodejs20.x", "../Esbuild/TypeScript", "nested/function/app.lambdaHandler", "x86_64"),
]
)
@pytest.mark.flaky(reruns=3)
Expand All @@ -841,18 +862,22 @@ class TestBuildCommand_NodeFunctions_With_Specified_Architecture(BuildIntegNodeB
("nodejs14.x", False, "x86_64"),
("nodejs16.x", False, "x86_64"),
("nodejs18.x", False, "x86_64"),
("nodejs20.x", False, "x86_64"),
("nodejs12.x", "use_container", "x86_64"),
("nodejs14.x", "use_container", "x86_64"),
("nodejs16.x", "use_container", "x86_64"),
("nodejs18.x", "use_container", "x86_64"),
("nodejs20.x", "use_container", "x86_64"),
("nodejs12.x", False, "arm64"),
("nodejs14.x", False, "arm64"),
("nodejs16.x", False, "arm64"),
("nodejs18.x", False, "arm64"),
("nodejs20.x", False, "arm64"),
("nodejs12.x", "use_container", "arm64"),
("nodejs14.x", "use_container", "arm64"),
("nodejs16.x", "use_container", "arm64"),
("nodejs18.x", "use_container", "arm64"),
("nodejs20.x", "use_container", "arm64"),
]
)
@pytest.mark.flaky(reruns=3)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_lint_supported_runtimes(self):
"nodejs14.x",
"nodejs16.x",
"nodejs18.x",
"nodejs20.x",
"provided",
"provided.al2",
"python3.7",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/commands/init/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_init_cli_node(self, generate_project_patch, git_repo_clone_mock):
location=self.location,
pt_explicit=self.pt_explicit,
package_type=self.package_type,
runtime="nodejs18.x",
runtime="nodejs20.x",
architecture=X86_64,
base_image=self.base_image,
dependency_manager="npm",
Expand All @@ -165,12 +165,12 @@ def test_init_cli_node(self, generate_project_patch, git_repo_clone_mock):
# need to change the location validation check
ANY,
ZIP,
"nodejs18.x",
"nodejs20.x",
"npm",
self.output_dir,
self.name,
True,
{"runtime": "nodejs18.x", "project_name": "testing project", "architectures": {"value": ["x86_64"]}},
{"runtime": "nodejs20.x", "project_name": "testing project", "architectures": {"value": ["x86_64"]}},
False,
False,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/build_module/test_workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_must_work_for_python(self, runtime):
self.assertIn(Event("BuildWorkflowUsed", "python-pip"), EventTracker.get_tracked_events())
self.assertFalse(result.must_mount_with_write_in_container)

@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",), ("nodejs18.x",)])
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",), ("nodejs18.x",), ("nodejs20.x",)])
def test_must_work_for_nodejs(self, runtime):
result = get_workflow_config(runtime, self.code_dir, self.project_dir)
self.assertEqual(result.language, "nodejs")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Runtime.nodejs14x.value,
Runtime.nodejs16x.value,
Runtime.nodejs18x.value,
Runtime.nodejs20x.value,
Runtime.python37.value,
Runtime.python38.value,
Runtime.python39.value,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Runtime.nodejs14x,
Runtime.nodejs16x,
Runtime.nodejs18x,
Runtime.nodejs20x,
Runtime.python37,
Runtime.python38,
Runtime.python39,
Expand Down

0 comments on commit 2126bc9

Please sign in to comment.