Skip to content

Commit 8a74d66

Browse files
authored
[Fix bug] nodejs12 runtime support (#931)
* 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
1 parent 11900a1 commit 8a74d66

21 files changed

Lines changed: 180 additions & 30 deletions

File tree

docs/specs/2018-04-03-zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Description | `string` | 服务的描述。
9595
属性名称 | 类型 | 描述
9696
---|:---:|---
9797
Handler | `string` | **必填。** 处理函数的调用入口。
98-
Runtime | `string` | **必填。** 运行时环境。可选值为:nodejs6、nodejs8、nodejs10、python2.7、python3、java8、php7.2、dotnetcore2.1。
98+
Runtime | `string` | **必填。** 运行时环境。可选值为:nodejs6、nodejs8、nodejs10、nodejs12、python2.7、python3、java8、php7.2、dotnetcore2.1。
9999
CodeUri | `string` | **必填。** 代码位置。支持 file、dir、zip、oss-bucket 等形式,更多信息[参考](#codeuri)。
100100
Initializer | `string` | 初始化函数的调用入口。
101101
Description | `string` | 函数的描述。
@@ -798,4 +798,4 @@ Filter:
798798
799799
1. 因为生成 role 用户需要为子用户分配一个很大的权限,非必要场景下,我们尽可能不去生成这个默认 role,尽可能避免用户的子用户权限不够情况。
800800
2. 一般这个 role 的使用场景是用来调用其他云服务的,即使生成了默认的 role,但是没有指定 policies 也是没有意义的,因为不会有相应的权限。
801-
3. ram 有角色数量的限制。
801+
3. ram 有角色数量的限制。

docs/specs/2018-04-03.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Creates a FC function and event source mappings which trigger the function. Func
9494
Property Name | Type | Description
9595
---|:---:|---
9696
Handler | `string` | **Required.** Function within your code that is called to begin execution.
97-
Runtime | `string` | **Required.** The runtime environment. The optional values ​​are: nodejs6, nodejs8, nodejs10, python2.7, python3, java8, php7.2, dotnetcore2.1 .
97+
Runtime | `string` | **Required.** The runtime environment. The optional values ​​are: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, php7.2, dotnetcore2.1 .
9898
CodeUri | `string` | **Required.** Code location. Supports file, dir, zip, oss-bucket, etc. More information [Reference] (#codeuri).
9999
Description | `string` | Description of the function.
100100
MemorySize | `integer` | Size of the memory allocated per invocation of the function in MB. Defaults to 128.
@@ -802,4 +802,4 @@ Reasons for this design:
802802
803803
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.
804804
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.
805-
3. Ram Service has a limitation on the number of roles.
805+
3. Ram Service has a limitation on the number of roles.

src/lib/commands/install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function validateRegistry(runtime, options) {
151151
}
152152

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

@@ -229,4 +229,4 @@ module.exports = {
229229
init,
230230
env,
231231
sbox
232-
};
232+
};

src/lib/debug.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async function generateVscodeDebugConfig(serviceName, functionName, runtime, cod
7575
}
7676
]
7777
};
78+
case 'nodejs12':
7879
case 'nodejs10':
7980
case 'nodejs8':
8081
return {
@@ -192,6 +193,7 @@ function generateDebugEnv(runtime, debugPort, debugIde) {
192193
const remoteIp = ip.address();
193194

194195
switch (runtime) {
196+
case 'nodejs12':
195197
case 'nodejs10':
196198
case 'nodejs8':
197199
return { 'DEBUG_OPTIONS': `--inspect-brk=0.0.0.0:${debugPort}` };
@@ -201,9 +203,9 @@ function generateDebugEnv(runtime, debugPort, debugIde) {
201203
case 'python3':
202204
if (debugIde === IDE_PYCHARM) {
203205
return {};
204-
}
206+
}
205207
return { 'DEBUG_OPTIONS': `-m ptvsd --host 0.0.0.0 --port ${debugPort} --wait` };
206-
208+
207209
case 'java8':
208210
return { 'DEBUG_OPTIONS': `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=${debugPort}` };
209211
case 'php7.2':
@@ -249,4 +251,4 @@ function generateDockerDebugOpts(runtime, debugPort, debugIde) {
249251
module.exports = {
250252
generateVscodeDebugConfig, generateDebugEnv, generateDockerDebugOpts,
251253
getDebugIde, getDebugPort
252-
};
254+
};

src/lib/docker-opts.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ let DOCKER_REGISTRY_CACHE;
2727
const runtimeImageMap = {
2828
'nodejs6': 'nodejs6',
2929
'nodejs8': 'nodejs8',
30+
'nodejs10': 'nodejs10',
31+
'nodejs12': 'nodejs12',
3032
'python2.7': 'python2.7',
3133
'python3': 'python3.6',
3234
'java8': 'java8',
3335
'php7.2': 'php7.2',
34-
'nodejs10': 'nodejs10',
3536
'dotnetcore2.1': 'dotnetcore2.1',
3637
'custom': 'custom'
3738
};
@@ -45,7 +46,7 @@ async function doImageRegisterEventTag(el) {
4546
visitor.event({
4647
ec: 'imageRegistry',
4748
ea: 'resolve',
48-
el
49+
el
4950
}).send();
5051
}
5152

@@ -153,7 +154,7 @@ function transformMountsForToolbox(mounts) {
153154

154155
return transformSourcePathOfMount(m);
155156
});
156-
}
157+
}
157158
return transformSourcePathOfMount(mounts);
158159
}
159160

@@ -214,7 +215,7 @@ async function generateLocalInvokeOpts(runtime, containerName, mounts, cmd, debu
214215
};
215216

216217
let debugOpts = {};
217-
218+
218219
if (debugPort) {
219220
debugOpts = generateDockerDebugOpts(runtime, debugPort, debugIde);
220221
}
@@ -301,7 +302,7 @@ async function generateLocalStartOpts(runtime, name, mounts, cmd, debugPort, env
301302
return opts;
302303
}
303304

304-
// Not Run stage:
305+
// Not Run stage:
305306
// for linux platform, it will always use process.uid and process.gid
306307
// for mac and windows platform, it will always use 0
307308
// Run stage:
@@ -332,12 +333,12 @@ function resolveDockerUser({nasConfig, stage = 'run'}) {
332333
}
333334

334335
module.exports = {
335-
generateLocalInvokeOpts, resolveRuntimeToDockerImage,
336+
generateLocalInvokeOpts, resolveRuntimeToDockerImage,
336337
generateInstallOpts, generateSboxOpts,
337338
generateLocalStartOpts,
338339
resolveMockScript, resolveDockerEnv, transformPathForVirtualBox,
339340
resolveDockerRegistry, transformMountsForToolbox, transformSourcePathOfMount,
340341
DOCKER_REGISTRIES, generateContainerBuildOpts,
341342
IMAGE_VERSION, resolveImageNameForPull, generateContainerName,
342343
generateContainerNameFilter, resolveDockerUser
343-
};
344+
};

src/lib/docker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ async function run(opts, event, outputStream, errorStream, context = {}) {
567567

568568
await container.start();
569569

570-
// dockerode bugs on windows. attach could not receive output and error
570+
// dockerode bugs on windows. attach could not receive output and error
571571
if (isWin) {
572572
const logStream = await container.logs({
573573
stdout: true,
@@ -801,6 +801,7 @@ function displaySboxTips(runtime) {
801801
case 'nodejs6':
802802
case 'nodejs8':
803803
case 'nodejs10':
804+
case 'nodejs12':
804805
console.log(yellow(`You can install node modules like this:`));
805806
console.log(yellow(`fun-install npm install puppeteer\n`));
806807
break;
@@ -1032,4 +1033,4 @@ module.exports = {
10321033
resolveTmpDirToMount, showDebugIdeTipsForPycharm, resolveDebuggerPathToMount,
10331034
listContainers, getContainer, createAndRunContainer, execContainer,
10341035
renameContainer, detectDockerVersion, resolveNasYmlToMount, resolvePasswdMount
1035-
};
1036+
};

src/lib/fc.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const FUN_GENERATED_SERVICE = 'fun-generated-default-service';
4949

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

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

5454
const defaultVpcConfig = {
5555
securityGroupId: '',
@@ -85,6 +85,7 @@ const runtimeTypeMapping = {
8585
'nodejs6': ['node_modules', '.fun/root'],
8686
'nodejs8': ['node_modules', '.fun/root'],
8787
'nodejs10': ['node_modules', '.fun/root'],
88+
'nodejs12': ['node_modules', '.fun/root'],
8889
'python2.7': ['.fun/python', '.fun/root'],
8990
'python3': ['.fun/python', '.fun/root'],
9091
'php7.2': ['extension', 'vendor', '.fun/root']
@@ -184,6 +185,7 @@ const runtimeDependencyMappings = {
184185
'nodejs6': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
185186
'nodejs8': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
186187
'nodejs10': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
188+
'nodejs12': [NODE_RUNTIME_MAPPING, FONTS_MAPPING],
187189
'python2.7': [PYTHON_RUNTIME_MAPPING, FONTS_MAPPING],
188190
'python3': [PYTHON_RUNTIME_MAPPING, FONTS_MAPPING],
189191
'java8': [JAVA_RUNTIME_MAPPING, FONTS_MAPPING],
@@ -707,7 +709,7 @@ async function processWar(absCodeUri, warfilePath) {
707709

708710
if (await fs.pathExists(targetAbsPath)) {
709711
console.log('repackage war file ', absWarfilePath);
710-
await repackPackage(tmpCodeDir,
712+
await repackPackage(tmpCodeDir,
711713
path.join('WEB-INF', 'lib'),
712714
absWarfilePath, targetAbsPath);
713715
} else {
@@ -938,7 +940,7 @@ async function checkAlreadyConfirmedForCustomSpringBoot(runtime, codeUri) {
938940
if (stat.size < 102400) { // 10 KB
939941
const content = await fs.readFile(bootstrapPath, 'utf8');
940942
// 对于 custom runtime 的 spring boot,如果检测到超过 50M,会提示使用 NAS 向导
941-
// 如果用户输入了 yes 确认,则会将 spring boot 打包的 jar 进行 repackage
943+
// 如果用户输入了 yes 确认,则会将 spring boot 打包的 jar 进行 repackage
942944
// 以及修改 bootstrap 的内容,即将 java -jar -Dserver.port=$PORT target/java-getting-started-1.0.jar 修改为 java org.springframework.boot.loader.PropertiesLauncher
943945
// 这里通过检测 java org.springframework.boot.loader.PropertiesLauncher 判断用户是否输入 yes 确认过,避免多次确认
944946
return _.includes(content, 'org.springframework.boot.loader.PropertiesLauncher');
@@ -1751,4 +1753,4 @@ module.exports = {
17511753
FUN_GENERATED_SERVICE, invokeFcUtilsFunction, getFcUtilsFunctionCode, deleteFunction,
17521754
processNasMappingsAndEnvs, processNasAutoConfiguration, nasAutoConfigurationIfNecessary,
17531755
makeFcUtilsFunctionNasDirChecker, makeFcUtilsFunctionTmpDomainToken
1754-
};
1756+
};

src/lib/init/templates.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"event-nodejs12": "{{ templatePath }}/event-nodejs12",
23
"event-nodejs10": "{{ templatePath }}/event-nodejs10",
34
"event-nodejs8": "{{ templatePath }}/event-nodejs8",
45
"event-nodejs6": "{{ templatePath }}/event-nodejs6",
@@ -7,6 +8,7 @@
78
"event-java8": "{{ templatePath }}/event-java8",
89
"event-php7.2": "{{ templatePath }}/event-php7.2",
910
"event-dotnetcore2.1": "{{ templatePath }}/event-dotnetcore2.1",
11+
"http-trigger-nodejs12": "{{ templatePath }}/http-trigger-nodejs12",
1012
"http-trigger-nodejs10": "{{ templatePath }}/http-trigger-nodejs10",
1113
"http-trigger-nodejs8": "{{ templatePath }}/http-trigger-nodejs8",
1214
"http-trigger-nodejs6": "{{ templatePath }}/http-trigger-nodejs6",
@@ -18,4 +20,4 @@
1820
"http-trigger-spring-boot": "{{ templatePath }}/http-trigger-spring-boot",
1921
"custom-springboot": "{{ templatePath }}/custom-springboot",
2022
"http-trigger-node-puppeteer": "{{ templatePath }}/http-trigger-node-puppeteer"
21-
}
23+
}

src/lib/language-service/schema/rosSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const rosSchema = {
154154
},
155155
"Runtime": {
156156
"type": "string",
157-
"enum": ["nodejs6", "nodejs8", "nodejs10", "python2.7", "python3", "java8", "php7.2", "dotnetcore2.1", "custom"]
157+
"enum": ["nodejs6", "nodejs8", "nodejs10", "nodejs12", "python2.7", "python3", "java8", "php7.2", "dotnetcore2.1", "custom"]
158158
},
159159
"CodeUri": {
160160
"type": "string"

src/lib/package/ignore.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function selectIgnored(runtime) {
1515
case 'nodejs6':
1616
case 'nodejs8':
1717
case 'nodejs10':
18+
case 'nodejs12':
1819

1920
return ['.fun/python'];
2021
case 'python2.7':
@@ -79,4 +80,4 @@ async function updateIgnore(baseDir, patterns) {
7980
module.exports = {
8081
isIgnored,
8182
updateIgnore
82-
};
83+
};

0 commit comments

Comments
 (0)