Skip to content

Commit

Permalink
feat: add ruby3.3 support (#6878)
Browse files Browse the repository at this point in the history
* feat: add ruby3.3 support

* update schema

* install Ruby3.3 in appveyor

* support preview OCI

* install ruby3.3 in appveyor

* update testdata

* Add ruby version files

* Add ruby version files

* update ruby version in GHA
  • Loading branch information
hawflau authored Apr 3, 2024
1 parent f5b2037 commit a18a729
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
go-version: '1.19'
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
ruby-version: "3.3"
- uses: actions/setup-node@v4
with:
node-version: 20
Expand Down
5 changes: 3 additions & 2 deletions appveyor-linux-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ install:
- sh: "mvn --version"

- sh: "source ${HOME}/venv${PYTHON_VERSION}/bin/activate"
- sh: "rvm reinstall ruby-3.2.2 --with-openssl-dir=/usr/lib/x86_64-linux-gnu" # reinstall ruby3.2 to fix OpenSSL issue
- sh: "rvm use 3.2.2"
- sh: "rbenv install 3.3.0"
- sh: "rbenv global 3.3.0"
- sh: "ruby --version"
- sh: "docker info"
- sh: "docker version"
- sh: "nvm install ${NODE_VERSION}"
Expand Down
3 changes: 2 additions & 1 deletion appveyor-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ install:
- sh: "mvn --version"

- sh: "source ${HOME}/venv${PYTHON_VERSION}/bin/activate"
- sh: "rbenv global 3.2.3"
- sh: "rbenv install 3.3.0"
- sh: "rbenv global 3.3.0"
- sh: "ruby --version"
- sh: "docker info"
- sh: "docker version"
Expand Down
1 change: 1 addition & 0 deletions appveyor-windows-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ install:
- choco upgrade gradle --version=8.4.0
- "gradle -v"
- "mvn --version"
- choco install ruby --version=3.3.0.1

# Make sure the temp directory exists for Python to use.
- ps: "mkdir -Force C:\\tmp"
Expand Down
1 change: 1 addition & 0 deletions appveyor-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ install:
- choco upgrade gradle --version=8.4.0
- "gradle -v"
- "mvn --version"
- choco install ruby --version=3.3.0.1

# Make sure the temp directory exists for Python to use.
- ps: "mkdir -Force C:\\tmp"
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 @@ -56,7 +56,7 @@
------------------
1. Python 3.8, 3.9, 3.10, 3.11, 3.12 using PIP\n
2. Nodejs 20.x, 18.x, 16.x, 14.x, 12.x using NPM\n
3. Ruby 3.2 using Bundler\n
3. Ruby 3.2, 3.3 using Bundler\n
4. Java 8, Java 11, Java 17, Java 21 using Gradle and Maven\n
5. Dotnet8, Dotnet6 using Dotnet CLI\n
6. Go 1.x using Go Modules (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:
"nodejs18.x": "nodejs",
"nodejs20.x": "nodejs",
"ruby3.2": "ruby/lib",
"ruby3.3": "ruby/lib",
"java11": "java",
"java8.al2": "java",
"java17": "java",
Expand Down Expand Up @@ -160,6 +161,7 @@ def get_workflow_config(
"nodejs18.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs20.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"ruby3.2": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"ruby3.3": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"dotnet6": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"dotnet8": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"go1.x": BasicWorkflowSelector(GO_MOD_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 @@ -24,6 +24,7 @@
"python3.11": [ARM64, X86_64],
"python3.12": [ARM64, X86_64],
"ruby3.2": [ARM64, X86_64],
"ruby3.3": [ARM64, X86_64],
"java8.al2": [ARM64, X86_64],
"java11": [ARM64, X86_64],
"java17": [ARM64, X86_64],
Expand Down
4 changes: 3 additions & 1 deletion samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"ruby": [
{
"runtimes": ["ruby3.2"],
"runtimes": ["ruby3.3", "ruby3.2"],
"dependency_manager": "bundler",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-ruby"),
"build": True,
Expand Down Expand Up @@ -123,6 +123,7 @@ def get_local_lambda_images_location(mapping, runtime):
"python3.9",
"python3.8",
# ruby runtimes in descending order
"ruby3.3",
"ruby3.2",
]

Expand All @@ -145,6 +146,7 @@ def get_local_lambda_images_location(mapping, runtime):
"python3.10": "amazon/python3.10-base",
"python3.9": "amazon/python3.9-base",
"python3.8": "amazon/python3.8-base",
"ruby3.3": "amazon/ruby3.3-base",
"ruby3.2": "amazon/ruby3.2-base",
}

Expand Down
13 changes: 11 additions & 2 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

RAPID_IMAGE_TAG_PREFIX = "rapid"

TEST_RUNTIMES = ["ruby3.3"]


class Runtime(Enum):
nodejs16x = "nodejs16.x"
Expand All @@ -42,6 +44,7 @@ class Runtime(Enum):
python311 = "python3.11"
python312 = "python3.12"
ruby32 = "ruby3.2"
ruby33 = "ruby3.3"
java8al2 = "java8.al2"
java11 = "java11"
java17 = "java17"
Expand All @@ -64,7 +67,7 @@ def has_value(cls, value):
return any(value == item.value for item in cls)

@classmethod
def get_image_name_tag(cls, runtime: str, architecture: str) -> str:
def get_image_name_tag(cls, runtime: str, architecture: str, is_preview: bool = False) -> str:
"""
Returns the image name and tag for a particular runtime
Expand All @@ -74,6 +77,8 @@ def get_image_name_tag(cls, runtime: str, architecture: str) -> str:
AWS Lambda runtime
architecture : str
Architecture for the runtime
is_preview : bool
Flag to use preview tag
Returns
-------
Expand All @@ -96,6 +101,9 @@ def get_image_name_tag(cls, runtime: str, architecture: str) -> str:
# nodejs20.x, go1.x, etc don't have the `.x` part.
runtime_image_tag = runtime_image_tag.replace(".x", "")

if is_preview:
runtime_image_tag = f"{runtime_image_tag}-preview"

# Runtime image tags contain the architecture only if more than one is supported for that runtime
if has_runtime_multi_arch_image(runtime):
runtime_image_tag = f"{runtime_image_tag}-{architecture}"
Expand Down Expand Up @@ -161,7 +169,8 @@ def build(self, runtime, packagetype, image, layers, architecture, stream=None,
if packagetype == IMAGE:
base_image = image
elif packagetype == ZIP:
runtime_image_tag = Runtime.get_image_name_tag(runtime, architecture)
is_preview = runtime in TEST_RUNTIMES
runtime_image_tag = Runtime.get_image_name_tag(runtime, architecture, is_preview=is_preview)
if self.invoke_images:
base_image = self.invoke_images.get(function_name, self.invoke_images.get(None))
if not base_image:
Expand Down
12 changes: 7 additions & 5 deletions schema/samcli.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"properties": {
"parameters": {
"title": "Parameters for the init command",
"description": "Available parameters for the init command:\n* no_interactive:\nDisable interactive prompting for init parameters. (fail if any required values are missing)\n* architecture:\nArchitectures for Lambda functions.\n\nArchitectures: ['arm64', 'x86_64']\n* location:\nTemplate location (git, mercurial, http(s), zip, path).\n* runtime:\nLambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2\n* package_type:\nLambda deployment package type.\n\nPackage Types: Zip, Image\n* base_image:\nLambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base\n* dependency_manager:\nDependency manager for Lambda runtime.\n\nDependency managers: bundler, cli-package, gradle, maven, mod, npm, pip\n* output_dir:\nDirectory to initialize AWS SAM application.\n* name:\nName of AWS SAM Application.\n* app_template:\nIdentifier of the managed application template to be used. Alternatively, run '$sam init' without options for an interactive workflow.\n* no_input:\nDisable Cookiecutter prompting and accept default values defined in the cookiecutter config.\n* extra_context:\nOverride custom parameters in the template's cookiecutter.json configuration e.g. {\"customParam1\": \"customValue1\", \"customParam2\":\"customValue2\"}\n* tracing:\nEnable AWS X-Ray tracing for application.\n* application_insights:\nEnable CloudWatch Application Insights monitoring for application.\n* structured_logging:\nEnable Structured Logging for application.\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"description": "Available parameters for the init command:\n* no_interactive:\nDisable interactive prompting for init parameters. (fail if any required values are missing)\n* architecture:\nArchitectures for Lambda functions.\n\nArchitectures: ['arm64', 'x86_64']\n* location:\nTemplate location (git, mercurial, http(s), zip, path).\n* runtime:\nLambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.3, ruby3.2\n* package_type:\nLambda deployment package type.\n\nPackage Types: Zip, Image\n* base_image:\nLambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base, amazon/ruby3.3-base\n* dependency_manager:\nDependency manager for Lambda runtime.\n\nDependency managers: bundler, cli-package, gradle, maven, mod, npm, pip\n* output_dir:\nDirectory to initialize AWS SAM application.\n* name:\nName of AWS SAM Application.\n* app_template:\nIdentifier of the managed application template to be used. Alternatively, run '$sam init' without options for an interactive workflow.\n* no_input:\nDisable Cookiecutter prompting and accept default values defined in the cookiecutter config.\n* extra_context:\nOverride custom parameters in the template's cookiecutter.json configuration e.g. {\"customParam1\": \"customValue1\", \"customParam2\":\"customValue2\"}\n* tracing:\nEnable AWS X-Ray tracing for application.\n* application_insights:\nEnable CloudWatch Application Insights monitoring for application.\n* structured_logging:\nEnable Structured Logging for application.\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"type": "object",
"properties": {
"no_interactive": {
Expand All @@ -48,7 +48,7 @@
"runtime": {
"title": "runtime",
"type": "string",
"description": "Lambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2",
"description": "Lambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.3, ruby3.2",
"enum": [
"dotnet6",
"dotnet8",
Expand All @@ -68,7 +68,8 @@
"python3.12",
"python3.8",
"python3.9",
"ruby3.2"
"ruby3.2",
"ruby3.3"
]
},
"package_type": {
Expand All @@ -83,7 +84,7 @@
"base_image": {
"title": "base_image",
"type": "string",
"description": "Lambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base",
"description": "Lambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base, amazon/ruby3.3-base",
"enum": [
"amazon/dotnet6-base",
"amazon/dotnet8-base",
Expand All @@ -102,7 +103,8 @@
"amazon/python3.12-base",
"amazon/python3.8-base",
"amazon/python3.9-base",
"amazon/ruby3.2-base"
"amazon/ruby3.2-base",
"amazon/ruby3.3-base"
]
},
"dependency_manager": {
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def test_building_default_package_json(self, runtime, use_container, architectur


class TestBuildCommand_RubyFunctions(BuildIntegRubyBase):
@parameterized.expand(["ruby3.2"])
@parameterized.expand(["ruby3.2", "ruby3.3"])
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
def test_building_ruby_in_container(self, runtime):
self._test_with_default_gemfile(runtime, "use_container", "Ruby", self.test_data_path)
Expand All @@ -826,12 +826,12 @@ def test_building_ruby_in_process(self, runtime):
class TestBuildCommand_RubyFunctions_With_Architecture(BuildIntegRubyBase):
template = "template_with_architecture.yaml"

@parameterized.expand([("ruby3.2", "Ruby32")])
@parameterized.expand([("ruby3.2", "Ruby32"), ("ruby3.3", "Ruby33")])
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
def test_building_ruby_in_container_with_specified_architecture(self, runtime, codeuri):
self._test_with_default_gemfile(runtime, "use_container", codeuri, self.test_data_path, "x86_64")

@parameterized.expand([("ruby3.2", "Ruby32")])
@parameterized.expand([("ruby3.2", "Ruby32"), ("ruby3.3", "Ruby33")])
def test_building_ruby_in_process_with_specified_architecture(self, runtime, codeuri):
self._test_with_default_gemfile(runtime, False, codeuri, self.test_data_path, "x86_64")

Expand All @@ -842,7 +842,7 @@ class TestBuildCommand_RubyFunctionsWithGemfileInTheRoot(BuildIntegRubyBase):
This doesn't apply to containerized build, since it copies only the function folder to the container
"""

@parameterized.expand([("ruby3.2")])
@parameterized.expand([("ruby3.2"), ("ruby3.3")])
def test_building_ruby_in_process_with_root_gemfile(self, runtime):
self._prepare_application_environment()
self._test_with_default_gemfile(runtime, False, "RubyWithRootGemfile", self.working_dir)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/testdata/buildcmd/Ruby32/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.3
2 changes: 1 addition & 1 deletion tests/integration/testdata/buildcmd/Ruby32/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source "https://rubygems.org"

gem "aws-eventstream"

ruby '~> 3.2.0'
ruby '~> 3.2'
1 change: 1 addition & 0 deletions tests/integration/testdata/buildcmd/Ruby33/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
5 changes: 5 additions & 0 deletions tests/integration/testdata/buildcmd/Ruby33/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "aws-eventstream"

ruby '~> 3.3'
9 changes: 9 additions & 0 deletions tests/integration/testdata/buildcmd/Ruby33/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'json'

def lambda_handler(event:, context:)
"Hello World"
end

def second_lambda_handler(event:, context:)
"Hello Mars"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.3
3 changes: 3 additions & 0 deletions tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def test_lint_supported_runtimes(self):
"python3.8",
"python3.9",
"python3.10",
"python3.11",
"python3.12",
"ruby3.2",
"ruby3.3",
]
i = 0
for runtime in supported_runtimes:
Expand Down
1 change: 1 addition & 0 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def runtime_supported_by_docker(runtime: str) -> bool:
"java21",
"python3.12",
"dotnet8",
"ruby3.3",
}
min_docker_version = "20.10.10"
return runtime not in al2023_based_runtimes or (
Expand Down

0 comments on commit a18a729

Please sign in to comment.