Skip to content

Commit 74b6ec9

Browse files
authored
Merge pull request #128 from devsapp/fix-code
fix: sls connectTimeout
2 parents b1a217f + bad550f commit 74b6ec9

File tree

12 files changed

+102
-22
lines changed

12 files changed

+102
-22
lines changed

__tests__/e2e/ci-mac-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sleep 10
4343
echo "test model s_file.yaml"
4444
# python -u test.py
4545
s model download -t s_file.yaml
46-
s deploy -y -t s_file.yaml
46+
s deploy -y -t s_file.yaml --skip-push
4747
s model remove -t s_file.yaml
4848
s remove -y -t s_file.yaml
4949
cd ..

__tests__/e2e/nodejs/s_auto.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}

__tests__/e2e/nodejs/s_custom_endpoint.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo1: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-endpoint

__tests__/e2e/nodejs/s_lock_auto.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ vars:
88
resources:
99
fcDemo1: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-f1
14-
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole
18+
role: acs:ram::${config('AccountID')}:role/aliyunfcdefaultrole
1519
runtime: ${env('fc_component_runtime', 'nodejs18')}
1620
code: ./test-auto-code
1721
handler: index.handler
@@ -23,6 +27,10 @@ resources:
2327

2428
fcDemo2: # 业务名称/模块名称
2529
component: ${env('fc_component_version', path('../../../'))}
30+
actions:
31+
pre-deploy:
32+
- run: npm install
33+
path: ./test-auto-code
2634
props: # 组件的属性值
2735
region: ${vars.region}
2836
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-f2
@@ -38,6 +46,10 @@ resources:
3846

3947
fcDemo3: # 业务名称/模块名称
4048
component: ${env('fc_component_version', path('../../../'))}
49+
actions:
50+
pre-deploy:
51+
- run: npm install
52+
path: ./test-auto-code
4153
props: # 组件的属性值
4254
region: ${vars.region}
4355
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole

__tests__/e2e/nodejs/s_oss_config_auto.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo:
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props:
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfig
@@ -21,6 +25,10 @@ resources:
2125

2226
fcDemo2: # 业务名称/模块名称
2327
component: ${env('fc_component_version', path('../../../'))}
28+
actions:
29+
pre-deploy:
30+
- run: npm install
31+
path: ./test-auto-code
2432
props: # 组件的属性值
2533
region: ${vars.region}
2634
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfigF2
@@ -30,4 +38,4 @@ resources:
3038
handler: index.handler
3139
memorySize: 128
3240
timeout: 60
33-
ossMountConfig: auto|readOnly=true|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]
41+
ossMountConfig: auto|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]

__tests__/e2e/nodejs/s_tags.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo1: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags

__tests__/e2e/nodejs/s_tags2.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo1: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags

__tests__/e2e/nodejs/s_tags3.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ vars:
88
resources:
99
fcDemo1: # 业务名称/模块名称
1010
component: ${env('fc_component_version', path('../../../'))}
11+
actions:
12+
pre-deploy:
13+
- run: npm install
14+
path: ./test-auto-code
1115
props: # 组件的属性值
1216
region: ${vars.region}
1317
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags
Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,67 @@
11
const fs = require('fs');
2+
const FC20230330 = require('@alicloud/fc20230330');
23

34
exports.initializer = (context, callback) => {
45
console.log('initializing');
56
callback(null, '');
67
};
78

8-
module.exports.handler = function (event, context, callback) {
9+
module.exports.handler = async function (event, context, callback) {
910
console.log(event.toString());
1011
console.log(JSON.stringify(context));
1112
const functionName = context.function.name;
1213
console.log(`functionName: ${functionName}`);
14+
const { ossConfig } = await getOssConfig(context, functionName);
1315
const nasDir = `/mnt/${functionName}`;
14-
const ossDir = `/mnt/${functionName}`;
16+
const ossDir = ossConfig && ossConfig?.mountPoints[0]?.mountDir;
1517
const nasFile = `${nasDir}/test.txt`;
1618
const ossFile = `${ossDir}/test.txt`;
17-
if (fs.existsSync(nasFile)) {
18-
const content = fs.readFileSync(nasFile, 'utf8');
19-
console.log(`nasFile content: ${content}`);
20-
} else {
21-
fs.writeFileSync(nasFile, 'hello world');
22-
console.log(`nasFile created: ${nasFile}`);
19+
if (fs.existsSync(nasDir)) {
20+
if (fs.existsSync(nasFile)) {
21+
const content = fs.readFileSync(nasFile, 'utf8');
22+
console.log(`nasFile content: ${content}`);
23+
} else {
24+
fs.writeFileSync(nasFile, 'hello world');
25+
console.log(`nasFile created: ${nasFile}`);
26+
}
2327
}
24-
if (fs.existsSync(ossFile)) {
25-
const content = fs.readFileSync(ossFile, 'utf8');
26-
console.log(`ossFile content: ${content}`);
27-
} else {
28-
fs.writeFileSync(ossFile, 'hello world');
29-
console.log(`ossFile created: ${ossFile}`);
28+
if (ossDir && fs.existsSync(ossDir)) {
29+
if (fs.existsSync(ossFile)) {
30+
const content = fs.readFileSync(ossFile, 'utf8');
31+
console.log(`ossFile content: ${content}`);
32+
} else {
33+
fs.writeFileSync(ossFile, 'hello world');
34+
console.log(`ossFile created: ${ossFile}`);
35+
}
3036
}
3137
callback(null, 'hello world');
3238
};
39+
40+
async function getOssConfig(context, functionName) {
41+
const {
42+
region,
43+
credentials: { accessKeyId, accessKeySecret, securityToken },
44+
accountId,
45+
} = context;
46+
const config = {
47+
accessKeyId,
48+
accessKeySecret,
49+
securityToken,
50+
endpoint: `${accountId}.${region}.fc.aliyuncs.com`,
51+
};
52+
const fcClient = new FC20230330.default(config);
53+
let getFunctionRequest = new FC20230330.GetFunctionRequest({});
54+
55+
try {
56+
const result = await fcClient.getFunction(functionName, getFunctionRequest);
57+
console.log(JSON.stringify(result, null, 2));
58+
59+
return {
60+
ossConfig: result?.body?.ossMountConfig,
61+
};
62+
} catch (e) {
63+
return {
64+
ossConfig: null,
65+
};
66+
}
67+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@alicloud/fc20230330": "^4.6.3"
4+
}
5+
}

0 commit comments

Comments
 (0)