Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sleep 10
echo "test model s_file.yaml"
# python -u test.py
s model download -t s_file.yaml
s deploy -y -t s_file.yaml
s deploy -y -t s_file.yaml --skip-push
s model remove -t s_file.yaml
s remove -y -t s_file.yaml
cd ..
Expand Down
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/s_auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}
Expand Down
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/s_custom_endpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo1: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-endpoint
Expand Down
14 changes: 13 additions & 1 deletion __tests__/e2e/nodejs/s_lock_auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ vars:
resources:
fcDemo1: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-f1
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole
role: acs:ram::${config('AccountID')}:role/aliyunfcdefaultrole
runtime: ${env('fc_component_runtime', 'nodejs18')}
code: ./test-auto-code
handler: index.handler
Expand All @@ -23,6 +27,10 @@ resources:

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

fcDemo3: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole
Expand Down
10 changes: 9 additions & 1 deletion __tests__/e2e/nodejs/s_oss_config_auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo:
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props:
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfig
Expand All @@ -21,6 +25,10 @@ resources:

fcDemo2: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfigF2
Expand All @@ -30,4 +38,4 @@ resources:
handler: index.handler
memorySize: 128
timeout: 60
ossMountConfig: auto|readOnly=true|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]
ossMountConfig: auto|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/s_tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo1: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags
Expand Down
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/s_tags2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo1: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags
Expand Down
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/s_tags3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ vars:
resources:
fcDemo1: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
actions:
pre-deploy:
- run: npm install
path: ./test-auto-code
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-tags
Expand Down
63 changes: 49 additions & 14 deletions __tests__/e2e/nodejs/test-auto-code/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
const fs = require('fs');
const FC20230330 = require('@alicloud/fc20230330');

exports.initializer = (context, callback) => {
console.log('initializing');
callback(null, '');
};

module.exports.handler = function (event, context, callback) {
module.exports.handler = async function (event, context, callback) {
console.log(event.toString());
console.log(JSON.stringify(context));
const functionName = context.function.name;
console.log(`functionName: ${functionName}`);
const { ossConfig } = await getOssConfig(context, functionName);
const nasDir = `/mnt/${functionName}`;
const ossDir = `/mnt/${functionName}`;
const ossDir = ossConfig && ossConfig?.mountPoints[0]?.mountDir;
const nasFile = `${nasDir}/test.txt`;
const ossFile = `${ossDir}/test.txt`;
if (fs.existsSync(nasFile)) {
const content = fs.readFileSync(nasFile, 'utf8');
console.log(`nasFile content: ${content}`);
} else {
fs.writeFileSync(nasFile, 'hello world');
console.log(`nasFile created: ${nasFile}`);
if (fs.existsSync(nasDir)) {
if (fs.existsSync(nasFile)) {
const content = fs.readFileSync(nasFile, 'utf8');
console.log(`nasFile content: ${content}`);
} else {
fs.writeFileSync(nasFile, 'hello world');
console.log(`nasFile created: ${nasFile}`);
}
}
if (fs.existsSync(ossFile)) {
const content = fs.readFileSync(ossFile, 'utf8');
console.log(`ossFile content: ${content}`);
} else {
fs.writeFileSync(ossFile, 'hello world');
console.log(`ossFile created: ${ossFile}`);
if (ossDir && fs.existsSync(ossDir)) {
if (fs.existsSync(ossFile)) {
const content = fs.readFileSync(ossFile, 'utf8');
console.log(`ossFile content: ${content}`);
} else {
fs.writeFileSync(ossFile, 'hello world');
console.log(`ossFile created: ${ossFile}`);
}
}
callback(null, 'hello world');
};

async function getOssConfig(context, functionName) {
const {
region,
credentials: { accessKeyId, accessKeySecret, securityToken },
accountId,
} = context;
const config = {
accessKeyId,
accessKeySecret,
securityToken,
endpoint: `${accountId}.${region}.fc.aliyuncs.com`,
};
const fcClient = new FC20230330.default(config);
let getFunctionRequest = new FC20230330.GetFunctionRequest({});

try {
const result = await fcClient.getFunction(functionName, getFunctionRequest);
console.log(JSON.stringify(result, null, 2));

return {
ossConfig: result?.body?.ossMountConfig,
};
} catch (e) {
return {
ossConfig: null,
};
}
}
5 changes: 5 additions & 0 deletions __tests__/e2e/nodejs/test-auto-code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@alicloud/fc20230330": "^4.6.3"
}
}
2 changes: 1 addition & 1 deletion src/resources/sls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Sls {
userAgent: 'serverless-devs',
regionId: region,
readTimeout: 60000,
connectTimeout: 5000,
connectTimeout: 60000,
});
this.client = new Sls20201230(config);
this.accountID = credentials.AccountID;
Expand Down
8 changes: 4 additions & 4 deletions src/subCommands/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Model {

async remove() {
logger.info('[Remove-model] remove model ...');
const params = await this.getParams();
const params = await this.getParams('Remove-model');
const { annotations } = this.inputs.props;
const modelConfig = annotations?.modelConfig;

Expand Down Expand Up @@ -110,7 +110,7 @@ export class Model {
);
}

private async getParams() {
private async getParams(command = 'Download-model') {
const { AccountID: accountID } = await this.inputs.getCredential();
const { credential } = this.inputs;
const { region, supplement, annotations } = this.inputs.props;
Expand All @@ -119,7 +119,7 @@ export class Model {

this._validateModelConfig(modelConfig);

logger.info(`[Download-model] Download model start.`);
logger.info(`[${command}] Start...`);
const { nasAuto, vpcAuto, ossAuto } = FC.computeLocalAuto(this.local);
logger.debug(`[auto] Auto compute local auto, nasAuto: ${nasAuto} ossAuto: ${ossAuto};`);

Expand All @@ -133,7 +133,7 @@ export class Model {

const { nasConfig, vpcConfig, ossMountConfig } = this.local;
logger.info(
`[Download-model] nasConfig: ${JSON.stringify(nasConfig)} vpcConfig: ${JSON.stringify(
`[${command}] nasConfig: ${JSON.stringify(nasConfig)} vpcConfig: ${JSON.stringify(
vpcConfig,
)} ossMountConfig: ${JSON.stringify(ossMountConfig)}`,
);
Expand Down
Loading