diff --git a/__tests__/e2e/ci-mac-linux.sh b/__tests__/e2e/ci-mac-linux.sh index e4cea486..a76be2b0 100755 --- a/__tests__/e2e/ci-mac-linux.sh +++ b/__tests__/e2e/ci-mac-linux.sh @@ -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 .. diff --git a/__tests__/e2e/nodejs/s_auto.yaml b/__tests__/e2e/nodejs/s_auto.yaml index 250d44ec..14466e35 100644 --- a/__tests__/e2e/nodejs/s_auto.yaml +++ b/__tests__/e2e/nodejs/s_auto.yaml @@ -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')} diff --git a/__tests__/e2e/nodejs/s_custom_endpoint.yaml b/__tests__/e2e/nodejs/s_custom_endpoint.yaml index 7a188004..47e5d2f8 100644 --- a/__tests__/e2e/nodejs/s_custom_endpoint.yaml +++ b/__tests__/e2e/nodejs/s_custom_endpoint.yaml @@ -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 diff --git a/__tests__/e2e/nodejs/s_lock_auto.yaml b/__tests__/e2e/nodejs/s_lock_auto.yaml index 489d20b5..c9cf64e1 100644 --- a/__tests__/e2e/nodejs/s_lock_auto.yaml +++ b/__tests__/e2e/nodejs/s_lock_auto.yaml @@ -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 @@ -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 @@ -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 diff --git a/__tests__/e2e/nodejs/s_oss_config_auto.yaml b/__tests__/e2e/nodejs/s_oss_config_auto.yaml index 30f58f90..aaac4fce 100644 --- a/__tests__/e2e/nodejs/s_oss_config_auto.yaml +++ b/__tests__/e2e/nodejs/s_oss_config_auto.yaml @@ -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 @@ -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 @@ -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}] \ No newline at end of file + ossMountConfig: auto|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}] \ No newline at end of file diff --git a/__tests__/e2e/nodejs/s_tags.yaml b/__tests__/e2e/nodejs/s_tags.yaml index 79565257..6aa6b929 100644 --- a/__tests__/e2e/nodejs/s_tags.yaml +++ b/__tests__/e2e/nodejs/s_tags.yaml @@ -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 diff --git a/__tests__/e2e/nodejs/s_tags2.yaml b/__tests__/e2e/nodejs/s_tags2.yaml index f855fda9..5d380768 100644 --- a/__tests__/e2e/nodejs/s_tags2.yaml +++ b/__tests__/e2e/nodejs/s_tags2.yaml @@ -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 diff --git a/__tests__/e2e/nodejs/s_tags3.yaml b/__tests__/e2e/nodejs/s_tags3.yaml index f9a33dd0..ef22a3a0 100644 --- a/__tests__/e2e/nodejs/s_tags3.yaml +++ b/__tests__/e2e/nodejs/s_tags3.yaml @@ -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 diff --git a/__tests__/e2e/nodejs/test-auto-code/index.js b/__tests__/e2e/nodejs/test-auto-code/index.js index 61436cdf..18ff36c8 100644 --- a/__tests__/e2e/nodejs/test-auto-code/index.js +++ b/__tests__/e2e/nodejs/test-auto-code/index.js @@ -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, + }; + } +} diff --git a/__tests__/e2e/nodejs/test-auto-code/package.json b/__tests__/e2e/nodejs/test-auto-code/package.json new file mode 100644 index 00000000..06a419ac --- /dev/null +++ b/__tests__/e2e/nodejs/test-auto-code/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@alicloud/fc20230330": "^4.6.3" + } +} \ No newline at end of file diff --git a/src/resources/sls/index.ts b/src/resources/sls/index.ts index 1417a705..b9f3cdf4 100644 --- a/src/resources/sls/index.ts +++ b/src/resources/sls/index.ts @@ -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; diff --git a/src/subCommands/model/index.ts b/src/subCommands/model/index.ts index 65fec9fe..a824d054 100644 --- a/src/subCommands/model/index.ts +++ b/src/subCommands/model/index.ts @@ -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; @@ -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; @@ -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};`); @@ -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)}`, );