@@ -19,6 +19,7 @@ import VPC_NAS from '../../../resources/vpc-nas';
1919import Base from './base' ;
2020import { ICredentials } from '@serverless-devs/component-interface' ;
2121import { calculateCRC64 , getFileSize } from '../../../utils' ;
22+ import OSS from '../../../resources/oss' ;
2223
2324type IType = 'code' | 'config' | boolean ;
2425interface IOpts {
@@ -337,9 +338,9 @@ export default class Service extends Base {
337338 const { credential } = this . inputs ;
338339 const { functionName } = this . local ;
339340
340- const { nasAuto, vpcAuto, slsAuto, roleAuto } = FC . computeLocalAuto ( this . local ) ;
341+ const { nasAuto, vpcAuto, slsAuto, roleAuto, ossAuto } = FC . computeLocalAuto ( this . local ) ;
341342 logger . debug (
342- `Deploy auto compute local auto, nasAuto: ${ nasAuto } ; vpcAuto: ${ vpcAuto } ; slsAuto: ${ slsAuto } ; roleAuto: ${ roleAuto } ` ,
343+ `Deploy auto compute local auto, nasAuto: ${ nasAuto } ; vpcAuto: ${ vpcAuto } ; slsAuto: ${ slsAuto } ; roleAuto: ${ roleAuto } ; ossAuto: ${ ossAuto } ` ,
343344 ) ;
344345
345346 if ( slsAuto ) {
@@ -364,6 +365,34 @@ logConfig:
364365 } ) ;
365366 }
366367
368+ if ( ossAuto ) {
369+ const ossEndpoint = `https://oss-${ region } .aliyuncs.com` ;
370+ const oss = new OSS ( region , credential as ICredentials , ossEndpoint ) ;
371+ const { ossBucket } = await oss . deploy ( ) ;
372+ logger . write (
373+ yellow ( `Created oss resource succeeded, please replace ossMountConfig: auto in yaml with:
374+ ossMountConfig:
375+ mountPoints:
376+ - mountDir: /mnt/oss_${ functionName }
377+ bucketName: ${ ossBucket }
378+ endpoint: ${ ossEndpoint }
379+ bucketPath: /${ functionName }
380+ readOnly: false\n` ) ,
381+ ) ;
382+ this . createResource . oss = { ossBucket } ;
383+ _ . set ( this . local , 'ossMountConfig' , {
384+ mountPoints : [
385+ {
386+ mountDir : `/mnt/oss_${ functionName } ` ,
387+ bucketName : ossBucket ,
388+ endpoint : ossEndpoint ,
389+ bucketPath : `/${ functionName } ` ,
390+ readOnly : false ,
391+ } ,
392+ ] ,
393+ } ) ;
394+ }
395+
367396 if ( roleAuto ) {
368397 const client = new RamClient ( credential as ICredentials ) ;
369398 const arn = await client . initFcDefaultServiceRole ( ) ;
@@ -406,7 +435,7 @@ vpcConfig:
406435 if ( nasAuto ) {
407436 const modelConfig = supplement ?. modelConfig || annotations ?. modelConfig ;
408437 let serverAddr = `${ mountTargetDomain } :/${ functionName } ${
409- isEmpty ( modelConfig ) ? '' : `/${ modelConfig . id } `
438+ isEmpty ( modelConfig ) ? '' : `/${ modelConfig . id } `
410439 } `;
411440 if ( serverAddr . length > 128 ) {
412441 serverAddr = serverAddr . substring ( 0 , 128 ) ;
0 commit comments