Skip to content

Commit

Permalink
chore: Node function default (#12058)
Browse files Browse the repository at this point in the history
* fix: Node function default

* chore: Updated docker expectations

* chore: Adjusted before all hook

* chore: Revert fixture tests
  • Loading branch information
Danwakeem committed Jul 10, 2023
1 parent 668a0ce commit 47e299e
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/cli/interactive-setup/dashboard-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {

const sdk = new ServerlessSDK();
const { supportedRegions, supportedRuntimes } = await sdk.metadata.get();
if (!supportedRuntimes.includes(_.get(configuration.provider, 'runtime') || 'nodejs12.x')) {
if (!supportedRuntimes.includes(_.get(configuration.provider, 'runtime') || 'nodejs16.x')) {
context.inapplicabilityReasonCode = 'UNSUPPORTED_RUNTIME';
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/interactive-setup/dashboard-set-org.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ module.exports = {
}
const sdk = new ServerlessSDK();
const { supportedRegions, supportedRuntimes } = await sdk.metadata.get();
if (!supportedRuntimes.includes(_.get(configuration.provider, 'runtime') || 'nodejs12.x')) {
if (!supportedRuntimes.includes(_.get(configuration.provider, 'runtime') || 'nodejs16.x')) {
context.inapplicabilityReasonCode = 'UNSUPPORTED_RUNTIME';
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ class AwsProvider {
'nodejs10.x',
'nodejs12.x',
'nodejs14.x',
'nodejs16.x',
'nodejs18.x',
'provided',
'provided.al2',
'python2.7',
Expand Down Expand Up @@ -1589,7 +1591,7 @@ class AwsProvider {
}

getRuntime(runtime) {
const defaultRuntime = 'nodejs12.x';
const defaultRuntime = 'nodejs16.x';
const runtimeSourceValue = this.getRuntimeSourceValue();
return runtime || runtimeSourceValue.value || defaultRuntime;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/package/lib/packageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
},

getRuntime(runtime) {
const defaultRuntime = 'nodejs12.x';
const defaultRuntime = 'nodejs14.x';
return runtime || this.serverless.service.provider.runtime || defaultRuntime;
},

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/telemetry/generatePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getServiceConfig = ({ configuration, options, variableSources }) => {
const isAwsProvider = providerName === 'aws';

const defaultRuntime = isAwsProvider
? configuration.provider.runtime || 'nodejs12.x'
? configuration.provider.runtime || 'nodejs16.x'
: _.get(configuration, 'provider.runtime');

const functions = (() => {
Expand Down
19 changes: 14 additions & 5 deletions test/unit/lib/cli/interactive-setup/dashboard-login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ const ServerlessSDKMock = class ServerlessSDK {
get: async () => {
return {
awsAccountId: '377024778620',
supportedRuntimes: ['nodejs10.x', 'nodejs12.x', 'python2.7', 'python3.6', 'python3.7'],
supportedRuntimes: [
'nodejs10.x',
'nodejs12.x',
'nodejs14.x',
'nodejs16.x',
'nodejs18.x',
'python2.7',
'python3.6',
'python3.7',
],
supportedRegions: [
'us-east-1',
'us-east-2',
Expand Down Expand Up @@ -116,7 +125,7 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-login.test.js', function
});
const context = {
serviceDir: process.cwd(),
configuration: { provider: { name: 'aws', runtime: 'nodejs12.x' } },
configuration: { provider: { name: 'aws', runtime: 'nodejs16.x' } },
configurationFilename: 'serverless.yml',
options: {},
initial: {},
Expand Down Expand Up @@ -148,7 +157,7 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-login.test.js', function
});
const context = {
serviceDir: process.cwd(),
configuration: { provider: { name: 'aws', runtime: 'nodejs12.x' } },
configuration: { provider: { name: 'aws', runtime: 'nodejs16.x' } },
configurationFilename: 'serverless.yml',
options: { org: 'someorg' },
initial: {},
Expand All @@ -168,7 +177,7 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-login.test.js', function
});
const context = {
serviceDir: process.cwd(),
configuration: { org: 'someorg', provider: { name: 'aws', runtime: 'nodejs12.x' } },
configuration: { org: 'someorg', provider: { name: 'aws', runtime: 'nodejs16.x' } },
configurationFilename: 'serverless.yml',
options: {},
initial: {},
Expand All @@ -191,7 +200,7 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-login.test.js', function
});
const context = {
serviceDir: process.cwd(),
configuration: { provider: { name: 'aws', runtime: 'nodejs12.x' } },
configuration: { provider: { name: 'aws', runtime: 'nodejs16.x' } },
configurationFilename: 'serverless.yml',
options: {},
initial: {},
Expand Down
13 changes: 11 additions & 2 deletions test/unit/lib/cli/interactive-setup/dashboard-set-org.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-set-org.test.js', functi
supportedRuntimes: [
'nodejs10.x',
'nodejs12.x',
'nodejs14.x',
'nodejs16.x',
'nodejs18.x',
'python2.7',
'python3.6',
'python3.7',
Expand Down Expand Up @@ -154,7 +157,7 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-set-org.test.js', functi
serviceDir: process.cwd(),
configuration: {
service: 'some-aws-service',
provider: { name: 'aws', runtime: 'nodejs12.x' },
provider: { name: 'aws', runtime: 'nodejs16.x' },
},
configurationFilename: 'serverless.yml',
options: {},
Expand All @@ -174,7 +177,13 @@ describe('test/unit/lib/cli/interactive-setup/dashboard-set-org.test.js', functi
get: async () => {
return {
awsAccountId: '377024778620',
supportedRuntimes: ['nodejs10.x', 'nodejs12.x'],
supportedRuntimes: [
'nodejs10.x',
'nodejs12.x',
'nodejs14.x',
'nodejs16.x',
'nodejs18.x',
],
supportedRegions: ['us-east-1'],
};
},
Expand Down
8 changes: 4 additions & 4 deletions test/unit/lib/plugins/aws/invokeLocal/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ describe('AwsInvokeLocal', () => {
it(`should call invokeLocalNodeJs for any node.js runtime version for ${item.path}`, async () => {
awsInvokeLocal.options.functionObj.handler = item.path;

awsInvokeLocal.options.functionObj.runtime = 'nodejs12.x';
awsInvokeLocal.options.functionObj.runtime = 'nodejs16.x';
await awsInvokeLocal.invokeLocal();
expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);
expect(
Expand Down Expand Up @@ -628,7 +628,7 @@ describe('AwsInvokeLocal', () => {
handler: 'handler.hello',
name: 'hello',
timeout: 4,
runtime: 'nodejs12.x',
runtime: 'nodejs16.x',
environment: {
functionVar: 'functionValue',
},
Expand Down Expand Up @@ -656,7 +656,7 @@ describe('AwsInvokeLocal', () => {
expect(spawnExtStub.getCall(0).args).to.deep.equal(['docker', ['version']]);
expect(spawnExtStub.getCall(1).args).to.deep.equal([
'docker',
['images', '-q', 'lambci/lambda:nodejs12.x'],
['images', '-q', 'lambci/lambda:nodejs16.x'],
]);
expect(spawnExtStub.getCall(3).args).to.deep.equal([
'docker',
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('AwsInvokeLocal', () => {
'commandLineEnvVar=commandLineEnvVarValue',
'-p',
'9292:9292',
'sls-docker-nodejs12.x',
'sls-docker-nodejs16.x',
'handler.hello',
'{}',
],
Expand Down
44 changes: 22 additions & 22 deletions test/unit/lib/plugins/aws/package/compile/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
Tags: [
{ Key: 'foo', Value: 'bar' },
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: 'arn:aws:sns:region:accountid:foo',
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -532,7 +532,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -574,7 +574,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: 'arn:aws:sns:region:accountid:foo',
Expand Down Expand Up @@ -667,7 +667,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
KmsKeyArn: { 'Fn::GetAtt': ['MyKms', 'Arn'] },
},
Expand Down Expand Up @@ -704,7 +704,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
KmsKeyArn: { Ref: 'foobar' },
},
Expand Down Expand Up @@ -741,7 +741,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
KmsKeyArn: { 'Fn::ImportValue': 'KmsKey' },
},
Expand Down Expand Up @@ -794,7 +794,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
KmsKeyArn: 'arn:aws:kms:region:accountid:foo/bar',
},
Expand Down Expand Up @@ -869,7 +869,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
TracingConfig: {
Mode: 'Active',
Expand Down Expand Up @@ -926,7 +926,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
Environment: {
Variables: {
Expand Down Expand Up @@ -993,7 +993,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 128,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 10,
},
};
Expand All @@ -1006,7 +1006,7 @@ describe('AwsCompileFunctions', () => {
});
});

it('should default to the nodejs12.x runtime when no provider runtime is given', () => {
it('should default to the nodejs16.x runtime when no provider runtime is given', () => {
const s3Folder = awsCompileFunctions.serverless.service.package.artifactDirectoryName;
const s3FileName = awsCompileFunctions.serverless.service.package.artifact
.split(path.sep)
Expand All @@ -1030,7 +1030,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1164,7 +1164,7 @@ describe('AwsCompileFunctions', () => {
MemorySize: 1024,
ReservedConcurrentExecutions: 5,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1220,7 +1220,7 @@ describe('AwsCompileFunctions', () => {
MemorySize: 1024,
ReservedConcurrentExecutions: 0,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1259,7 +1259,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1297,7 +1297,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs16.x',
Timeout: 6,
Layers: ['arn:aws:xxx:*:*'],
},
Expand Down Expand Up @@ -1409,7 +1409,7 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
sharedEnvVar: 'valueFromFunction',
},
memorySize: 2048,
runtime: 'nodejs12.x',
runtime: 'nodejs16.x',
versionFunction: true,
},
fnFileSystemConfig: {
Expand Down Expand Up @@ -1932,7 +1932,7 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
ExternalLambdaLayer: {
Type: 'AWS::Lambda::LayerVersion',
Properties: {
CompatibleRuntimes: ['nodejs12.x'],
CompatibleRuntimes: ['nodejs16.x'],
Content: {
S3Bucket: 'bucket',
S3Key: 'key',
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/plugins/aws/package/compile/layers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('lib/plugins/aws/package/compile/layers/index.test.js', () => {
layerTwo: {
description: 'Layer two example',
path: 'layer',
compatibleRuntimes: ['nodejs12.x'],
compatibleRuntimes: ['nodejs16.x'],
compatibleArchitectures: ['arm64'],
licenseInfo: 'GPL',
allowedAccounts: ['123456789012', '123456789013'],
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('lib/plugins/aws/package/compile/layers/index.test.js', () => {
const layerOne = cfResources[layerResourceName];

expect(layerOne.Type).to.equals('AWS::Lambda::LayerVersion');
expect(layerOne.Properties.CompatibleRuntimes).to.deep.equals(['nodejs12.x']);
expect(layerOne.Properties.CompatibleRuntimes).to.deep.equals(['nodejs16.x']);
});

it('should support `layers[].compatibleArchitectures`', () => {
Expand Down

0 comments on commit 47e299e

Please sign in to comment.