Skip to content

Commit

Permalink
feat: update docker images and add support for different architectures (
Browse files Browse the repository at this point in the history
#1755)

* fix:changed docker image source

* feat:support multiple architectures

* fix:reorder files

* fix:import

* fix: lint error

* fix: remove p-retry package

* fix: typo

* feat: activate tests

* fix: rename

* fix: typo arquitecture -> architecture

* ci: fix docker tests

* fix: package.json

* ci: fix go docker test - add buildInContainer

* feat: add support for python 3.12

---------

Co-authored-by: MazurDorian <mazur.dorian15@gmail.com>
Co-authored-by: Dorian <46839236+DorianMazur@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 23, 2024
1 parent 7db15df commit d6b155e
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 115 deletions.
4 changes: 4 additions & 0 deletions .mocharc.cjs
Expand Up @@ -16,6 +16,10 @@ if (env.TEST === "unit") {
spec = ["./src/**/*.test.js", "tests/old-unit/**/*.test.js"]
}

if (env.TEST === "docker") {
spec = ["tests/integration/docker/**/*.test.js"]
}

if (env.TEST === "node") {
spec = [
"./src/**/*.test.js",
Expand Down
41 changes: 0 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -22,7 +22,8 @@
"test:cov": "NODE_OPTIONS='--experimental-loader @istanbuljs/esm-loader-hook' nyc --reporter=html npm test",
"test:node": "TEST=node mocha --require ./tests/mochaHooks.cjs",
"test:unit": "TEST=unit mocha --require ./tests/mochaHooks.cjs",
"test:e2e": "TEST=e2e mocha --require ./tests/mochaHooks.cjs"
"test:e2e": "TEST=e2e mocha --require ./tests/mochaHooks.cjs",
"test:docker": "TEST=docker mocha --require ./tests/mochaHooks.cjs"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -96,7 +97,6 @@
"luxon": "^3.4.4",
"node-schedule": "^2.1.1",
"p-memoize": "^7.1.1",
"p-retry": "^6.2.0",
"velocityjs": "^2.0.6",
"ws": "^8.16.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/config/constants.js
Expand Up @@ -6,6 +6,8 @@ export const CUSTOM_OPTION = "serverless-offline"

export const DEFAULT_LAMBDA_RUNTIME = "nodejs14.x"

export const DEFAULT_LAMBDA_ARCHITECTURE = "arm64"

// https://docs.aws.amazon.com/lambda/latest/dg/limits.html
export const DEFAULT_LAMBDA_MEMORY_SIZE = 1024
// default function timeout in seconds
Expand Down
38 changes: 31 additions & 7 deletions src/config/supportedRuntimes.js
@@ -1,3 +1,4 @@
/* eslint-disable sort-keys */
// native runtime support for AWS
// https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Expand All @@ -6,6 +7,34 @@
// 'dotnet6',
// ])

const X86_64 = "x86_64"
const ARM64 = "arm64"

export const supportedRuntimesArchitecture = {
"nodejs12.x": [ARM64, X86_64],
"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],
"python3.10": [ARM64, X86_64],
"python3.11": [ARM64, X86_64],
"python3.12": [ARM64, X86_64],
"ruby2.7": [ARM64, X86_64],
"ruby3.2": [ARM64, X86_64],
java8: [X86_64],
"java8.al2": [ARM64, X86_64],
java11: [ARM64, X86_64],
java17: [ARM64, X86_64],
"go1.x": [X86_64],
"dotnetcore3.1": [ARM64, X86_64],
provided: [X86_64],
dotnet6: [ARM64, X86_64],
"provided.al2": [ARM64, X86_64],
}

// GO
export const supportedGo = new Set(["go1.x"])

Expand All @@ -30,6 +59,7 @@ export const supportedPython = new Set([
"python3.9",
"python3.10",
"python3.11",
"python3.12",
])

// RUBY
Expand All @@ -47,10 +77,4 @@ export const supportedRuntimes = new Set([
...supportedRuby,
])

export const unsupportedDockerRuntimes = new Set([
"nodejs14.x",
"nodejs16.x",
"nodejs18.x",
"nodejs20.x",
"python3.9",
])
export const unsupportedDockerRuntimes = new Set([])
8 changes: 8 additions & 0 deletions src/lambda/LambdaFunction.js
Expand Up @@ -10,6 +10,7 @@ import jszip from "jszip"
import HandlerRunner from "./handler-runner/index.js"
import LambdaContext from "./LambdaContext.js"
import {
DEFAULT_LAMBDA_ARCHITECTURE,
DEFAULT_LAMBDA_MEMORY_SIZE,
DEFAULT_LAMBDA_RUNTIME,
DEFAULT_LAMBDA_TIMEOUT,
Expand Down Expand Up @@ -57,6 +58,8 @@ export default class LambdaFunction {

#runtime = null

#architecture = null

#status = "IDLE" // can be 'BUSY' or 'IDLE'

#timeout = null
Expand Down Expand Up @@ -91,6 +94,10 @@ export default class LambdaFunction {

this.#runtime =
functionDefinition.runtime ?? provider.runtime ?? DEFAULT_LAMBDA_RUNTIME
this.#architecture =
functionDefinition.architecture ??
provider.architecture ??
DEFAULT_LAMBDA_ARCHITECTURE

this.#timeout =
(functionDefinition.timeout ??
Expand Down Expand Up @@ -136,6 +143,7 @@ export default class LambdaFunction {

// TEMP
const funOptions = {
architecture: this.#architecture,
codeDir: this.#codeDir,
functionKey,
functionName: name,
Expand Down
Expand Up @@ -16,6 +16,7 @@ export default class LambdaFunctionThatReturnsJSONObject {
},
service: {
provider: {
architecture: "arm64",
runtime: "nodejs18.x",
},
},
Expand Down
Expand Up @@ -16,6 +16,7 @@ export default class LambdaFunctionThatReturnsNativeString {
},
service: {
provider: {
architecture: "arm64",
runtime: "nodejs18.x",
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/handler-runner/HandlerRunner.js
Expand Up @@ -32,7 +32,7 @@ export default class HandlerRunner {
if (useDocker) {
if (unsupportedDockerRuntimes.has(runtime)) {
log.warning(
`"${runtime}" runtime is not supported with docker. See https://github.com/lambci/docker-lambda`,
`"${runtime}" runtime is not supported with docker. See https://github.com/aws/aws-lambda-base-images`,
)
throw new Error("Unsupported runtime")
}
Expand Down

0 comments on commit d6b155e

Please sign in to comment.