Skip to content

Commit

Permalink
[Fix bug] nodejs12 runtime support (alibaba#931)
Browse files Browse the repository at this point in the history
* Add nodejs12 to templates

* Amend nodejs12 to error message

* Amend nodejs12 to docker runtime image map

* Amend nodejs12 to specification

* Amend nodejs12 to debug runtime case

* Amend nodejs12 to debug runtime test case

* Amend nodejs12 to sbox tips runtime case

* Amend nodejs12 to supported runtime

* Amend nodejs12 to ros runtime enum

* Amend nodejs12 to runtime ignore dependencies case

* Amend nodejs12 to validate runtime schemas
  • Loading branch information
DevDengChao authored Jun 22, 2020
1 parent 11900a1 commit 8a74d66
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 30 deletions.
4 changes: 2 additions & 2 deletions docs/specs/2018-04-03-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Description | `string` | 服务的描述。
属性名称 | 类型 | 描述
---|:---:|---
Handler | `string` | **必填。** 处理函数的调用入口。
Runtime | `string` | **必填。** 运行时环境。可选值为:nodejs6、nodejs8、nodejs10、python2.7、python3、java8、php7.2、dotnetcore2.1。
Runtime | `string` | **必填。** 运行时环境。可选值为:nodejs6、nodejs8、nodejs10、nodejs12、python2.7、python3、java8、php7.2、dotnetcore2.1。
CodeUri | `string` | **必填。** 代码位置。支持 file、dir、zip、oss-bucket 等形式,更多信息[参考](#codeuri)。
Initializer | `string` | 初始化函数的调用入口。
Description | `string` | 函数的描述。
Expand Down Expand Up @@ -798,4 +798,4 @@ Filter:
1. 因为生成 role 用户需要为子用户分配一个很大的权限,非必要场景下,我们尽可能不去生成这个默认 role,尽可能避免用户的子用户权限不够情况。
2. 一般这个 role 的使用场景是用来调用其他云服务的,即使生成了默认的 role,但是没有指定 policies 也是没有意义的,因为不会有相应的权限。
3. ram 有角色数量的限制。
3. ram 有角色数量的限制。
4 changes: 2 additions & 2 deletions docs/specs/2018-04-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Creates a FC function and event source mappings which trigger the function. Func
Property Name | Type | Description
---|:---:|---
Handler | `string` | **Required.** Function within your code that is called to begin execution.
Runtime | `string` | **Required.** The runtime environment. The optional values ​​are: nodejs6, nodejs8, nodejs10, python2.7, python3, java8, php7.2, dotnetcore2.1 .
Runtime | `string` | **Required.** The runtime environment. The optional values ​​are: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, php7.2, dotnetcore2.1 .
CodeUri | `string` | **Required.** Code location. Supports file, dir, zip, oss-bucket, etc. More information [Reference] (#codeuri).
Description | `string` | Description of the function.
MemorySize | `integer` | Size of the memory allocated per invocation of the function in MB. Defaults to 128.
Expand Down Expand Up @@ -802,4 +802,4 @@ Reasons for this design:
1. Because the generation of role needs a large permission. In unnecessary scenarios, we try not to generate the default role as much as possible to avoid the user's sub-user privilege is insufficient.
2. Generally, function use this role to invoke other cloud services. Even if default role is generated, it is meaningless not to specify policies, because there will be no corresponding permissions.
3. Ram Service has a limitation on the number of roles.
3. Ram Service has a limitation on the number of roles.
4 changes: 2 additions & 2 deletions src/lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function validateRegistry(runtime, options) {
}

if (options.registry && !(runtime.indexOf('node') > -1)) {
throw new Error(`'--registry' needs to be used with '--runtime' nodejs6/nodejs8/nodejs10, and you are currently using ${runtime}`);
throw new Error(`'--registry' needs to be used with '--runtime' nodejs6/nodejs8/nodejs10/nodejs12, and you are currently using ${runtime}`);
}
}

Expand Down Expand Up @@ -229,4 +229,4 @@ module.exports = {
init,
env,
sbox
};
};
8 changes: 5 additions & 3 deletions src/lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function generateVscodeDebugConfig(serviceName, functionName, runtime, cod
}
]
};
case 'nodejs12':
case 'nodejs10':
case 'nodejs8':
return {
Expand Down Expand Up @@ -192,6 +193,7 @@ function generateDebugEnv(runtime, debugPort, debugIde) {
const remoteIp = ip.address();

switch (runtime) {
case 'nodejs12':
case 'nodejs10':
case 'nodejs8':
return { 'DEBUG_OPTIONS': `--inspect-brk=0.0.0.0:${debugPort}` };
Expand All @@ -201,9 +203,9 @@ function generateDebugEnv(runtime, debugPort, debugIde) {
case 'python3':
if (debugIde === IDE_PYCHARM) {
return {};
}
}
return { 'DEBUG_OPTIONS': `-m ptvsd --host 0.0.0.0 --port ${debugPort} --wait` };

case 'java8':
return { 'DEBUG_OPTIONS': `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=${debugPort}` };
case 'php7.2':
Expand Down Expand Up @@ -249,4 +251,4 @@ function generateDockerDebugOpts(runtime, debugPort, debugIde) {
module.exports = {
generateVscodeDebugConfig, generateDebugEnv, generateDockerDebugOpts,
getDebugIde, getDebugPort
};
};
15 changes: 8 additions & 7 deletions src/lib/docker-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ let DOCKER_REGISTRY_CACHE;
const runtimeImageMap = {
'nodejs6': 'nodejs6',
'nodejs8': 'nodejs8',
'nodejs10': 'nodejs10',
'nodejs12': 'nodejs12',
'python2.7': 'python2.7',
'python3': 'python3.6',
'java8': 'java8',
'php7.2': 'php7.2',
'nodejs10': 'nodejs10',
'dotnetcore2.1': 'dotnetcore2.1',
'custom': 'custom'
};
Expand All @@ -45,7 +46,7 @@ async function doImageRegisterEventTag(el) {
visitor.event({
ec: 'imageRegistry',
ea: 'resolve',
el
el
}).send();
}

Expand Down Expand Up @@ -153,7 +154,7 @@ function transformMountsForToolbox(mounts) {

return transformSourcePathOfMount(m);
});
}
}
return transformSourcePathOfMount(mounts);
}

Expand Down Expand Up @@ -214,7 +215,7 @@ async function generateLocalInvokeOpts(runtime, containerName, mounts, cmd, debu
};

let debugOpts = {};

if (debugPort) {
debugOpts = generateDockerDebugOpts(runtime, debugPort, debugIde);
}
Expand Down Expand Up @@ -301,7 +302,7 @@ async function generateLocalStartOpts(runtime, name, mounts, cmd, debugPort, env
return opts;
}

// Not Run stage:
// Not Run stage:
// for linux platform, it will always use process.uid and process.gid
// for mac and windows platform, it will always use 0
// Run stage:
Expand Down Expand Up @@ -332,12 +333,12 @@ function resolveDockerUser({nasConfig, stage = 'run'}) {
}

module.exports = {
generateLocalInvokeOpts, resolveRuntimeToDockerImage,
generateLocalInvokeOpts, resolveRuntimeToDockerImage,
generateInstallOpts, generateSboxOpts,
generateLocalStartOpts,
resolveMockScript, resolveDockerEnv, transformPathForVirtualBox,
resolveDockerRegistry, transformMountsForToolbox, transformSourcePathOfMount,
DOCKER_REGISTRIES, generateContainerBuildOpts,
IMAGE_VERSION, resolveImageNameForPull, generateContainerName,
generateContainerNameFilter, resolveDockerUser
};
};
5 changes: 3 additions & 2 deletions src/lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ async function run(opts, event, outputStream, errorStream, context = {}) {

await container.start();

// dockerode bugs on windows. attach could not receive output and error
// dockerode bugs on windows. attach could not receive output and error
if (isWin) {
const logStream = await container.logs({
stdout: true,
Expand Down Expand Up @@ -801,6 +801,7 @@ function displaySboxTips(runtime) {
case 'nodejs6':
case 'nodejs8':
case 'nodejs10':
case 'nodejs12':
console.log(yellow(`You can install node modules like this:`));
console.log(yellow(`fun-install npm install puppeteer\n`));
break;
Expand Down Expand Up @@ -1032,4 +1033,4 @@ module.exports = {
resolveTmpDirToMount, showDebugIdeTipsForPycharm, resolveDebuggerPathToMount,
listContainers, getContainer, createAndRunContainer, execContainer,
renameContainer, detectDockerVersion, resolveNasYmlToMount, resolvePasswdMount
};
};
10 changes: 6 additions & 4 deletions src/lib/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const FUN_GENERATED_SERVICE = 'fun-generated-default-service';

const SYSTEM_DEPENDENCY_PATH = path.join('.fun', 'root');

const SUPPORT_RUNTIMES = ['nodejs6', 'nodejs8', 'nodejs10', 'python2.7', 'python3', 'java8', 'custom'];
const SUPPORT_RUNTIMES = ['nodejs6', 'nodejs8', 'nodejs10', 'nodejs12', 'python2.7', 'python3', 'java8', 'custom'];

const defaultVpcConfig = {
securityGroupId: '',
Expand Down Expand Up @@ -85,6 +85,7 @@ const runtimeTypeMapping = {
'nodejs6': ['node_modules', '.fun/root'],
'nodejs8': ['node_modules', '.fun/root'],
'nodejs10': ['node_modules', '.fun/root'],
'nodejs12': ['node_modules', '.fun/root'],
'python2.7': ['.fun/python', '.fun/root'],
'python3': ['.fun/python', '.fun/root'],
'php7.2': ['extension', 'vendor', '.fun/root']
Expand Down Expand Up @@ -184,6 +185,7 @@ const runtimeDependencyMappings = {
'nodejs6': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
'nodejs8': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
'nodejs10': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
'nodejs12': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
'python2.7': [PYTHON_RUNTIME_MAPPING, FONTS_MAPPING],
'python3': [PYTHON_RUNTIME_MAPPING, FONTS_MAPPING],
'java8': [JAVA_RUNTIME_MAPPING, FONTS_MAPPING],
Expand Down Expand Up @@ -707,7 +709,7 @@ async function processWar(absCodeUri, warfilePath) {

if (await fs.pathExists(targetAbsPath)) {
console.log('repackage war file ', absWarfilePath);
await repackPackage(tmpCodeDir,
await repackPackage(tmpCodeDir,
path.join('WEB-INF', 'lib'),
absWarfilePath, targetAbsPath);
} else {
Expand Down Expand Up @@ -938,7 +940,7 @@ async function checkAlreadyConfirmedForCustomSpringBoot(runtime, codeUri) {
if (stat.size < 102400) { // 10 KB
const content = await fs.readFile(bootstrapPath, 'utf8');
// 对于 custom runtime 的 spring boot,如果检测到超过 50M,会提示使用 NAS 向导
// 如果用户输入了 yes 确认,则会将 spring boot 打包的 jar 进行 repackage
// 如果用户输入了 yes 确认,则会将 spring boot 打包的 jar 进行 repackage
// 以及修改 bootstrap 的内容,即将 java -jar -Dserver.port=$PORT target/java-getting-started-1.0.jar 修改为 java org.springframework.boot.loader.PropertiesLauncher
// 这里通过检测 java org.springframework.boot.loader.PropertiesLauncher 判断用户是否输入 yes 确认过,避免多次确认
return _.includes(content, 'org.springframework.boot.loader.PropertiesLauncher');
Expand Down Expand Up @@ -1751,4 +1753,4 @@ module.exports = {
FUN_GENERATED_SERVICE, invokeFcUtilsFunction, getFcUtilsFunctionCode, deleteFunction,
processNasMappingsAndEnvs, processNasAutoConfiguration, nasAutoConfigurationIfNecessary,
makeFcUtilsFunctionNasDirChecker, makeFcUtilsFunctionTmpDomainToken
};
};
4 changes: 3 additions & 1 deletion src/lib/init/templates.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"event-nodejs12": "{{ templatePath }}/event-nodejs12",
"event-nodejs10": "{{ templatePath }}/event-nodejs10",
"event-nodejs8": "{{ templatePath }}/event-nodejs8",
"event-nodejs6": "{{ templatePath }}/event-nodejs6",
Expand All @@ -7,6 +8,7 @@
"event-java8": "{{ templatePath }}/event-java8",
"event-php7.2": "{{ templatePath }}/event-php7.2",
"event-dotnetcore2.1": "{{ templatePath }}/event-dotnetcore2.1",
"http-trigger-nodejs12": "{{ templatePath }}/http-trigger-nodejs12",
"http-trigger-nodejs10": "{{ templatePath }}/http-trigger-nodejs10",
"http-trigger-nodejs8": "{{ templatePath }}/http-trigger-nodejs8",
"http-trigger-nodejs6": "{{ templatePath }}/http-trigger-nodejs6",
Expand All @@ -18,4 +20,4 @@
"http-trigger-spring-boot": "{{ templatePath }}/http-trigger-spring-boot",
"custom-springboot": "{{ templatePath }}/custom-springboot",
"http-trigger-node-puppeteer": "{{ templatePath }}/http-trigger-node-puppeteer"
}
}
2 changes: 1 addition & 1 deletion src/lib/language-service/schema/rosSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const rosSchema = {
},
"Runtime": {
"type": "string",
"enum": ["nodejs6", "nodejs8", "nodejs10", "python2.7", "python3", "java8", "php7.2", "dotnetcore2.1", "custom"]
"enum": ["nodejs6", "nodejs8", "nodejs10", "nodejs12", "python2.7", "python3", "java8", "php7.2", "dotnetcore2.1", "custom"]
},
"CodeUri": {
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/package/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function selectIgnored(runtime) {
case 'nodejs6':
case 'nodejs8':
case 'nodejs10':
case 'nodejs12':

return ['.fun/python'];
case 'python2.7':
Expand Down Expand Up @@ -79,4 +80,4 @@ async function updateIgnore(baseDir, patterns) {
module.exports = {
isIgnored,
updateIgnore
};
};
2 changes: 1 addition & 1 deletion src/lib/validate/schema/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const functionSchema = {
},
'Runtime': {
'type': 'string',
'enum': ['nodejs6', 'nodejs8', 'nodejs10', 'python2.7', 'python3', 'java8', 'php7.2', 'dotnetcore2.1', 'custom']
'enum': ['nodejs6', 'nodejs8', 'nodejs10', 'nodejs12', 'python2.7', 'python3', 'java8', 'php7.2', 'dotnetcore2.1', 'custom']
},
'CodeUri': {
'type': 'string'
Expand Down
7 changes: 7 additions & 0 deletions templates/event-nodejs12/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "event-nodejs12",
"description": "Print hello world",
"vars": {
"service": "{{ projectName }}"
}
}
4 changes: 4 additions & 0 deletions templates/event-nodejs12/{{ projectName }}/.funignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
package-lock.json
template.yml
.funignore
12 changes: 12 additions & 0 deletions templates/event-nodejs12/{{ projectName }}/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
if you open the initializer feature, please implement the initializer function, as below:
module.exports.initializer = function(context, callback) {
console.log('initializing');
callback(null, '');
};
*/

module.exports.handler = function(event, context, callback) {
console.log('hello world');
callback(null, 'hello world');
};
13 changes: 13 additions & 0 deletions templates/event-nodejs12/{{ projectName }}/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
{{ service }}:
Type: 'Aliyun::Serverless::Service'
Properties:
Description: 'helloworld'
{{ projectName }}:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs12
CodeUri: './'
7 changes: 7 additions & 0 deletions templates/http-trigger-nodejs12/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "http-trigger-nodejs12",
"description": "Print hello world",
"vars": {
"service": "{{ projectName }}"
}
}
4 changes: 4 additions & 0 deletions templates/http-trigger-nodejs12/{{ projectName }}/.funignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
package-lock.json
template.yml
.funignore
48 changes: 48 additions & 0 deletions templates/http-trigger-nodejs12/{{ projectName }}/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var getRawBody = require('raw-body');
var getFormBody = require('body/form');
var body = require('body');


/*
if you open the initializer feature, please implement the initializer function, as below:
module.exports.initializer = function(context, callback) {
console.log('initializing');
callback(null, '');
};
*/

module.exports.handler = function(req, resp, context) {
console.log('hello world');

var params = {
path: req.path,
queries: req.queries,
headers: req.headers,
method : req.method,
requestURI : req.url,
clientIP : req.clientIP,
}

getRawBody(req, function(err, body) {
resp.setHeader('content-type', 'text/plain');

for (var key in req.queries) {
var value = req.queries[key];
resp.setHeader(key, value);
}
params.body = body.toString();
resp.send(JSON.stringify(params, null, ' '));
});

/*
getFormBody(req, function(err, formBody) {
for (var key in req.queries) {
var value = req.queries[key];
resp.setHeader(key, value);
}
params.body = formBody;
console.log(formBody);
resp.send(JSON.stringify(params));
});
*/
}
Loading

0 comments on commit 8a74d66

Please sign in to comment.