@@ -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,48 @@ logConfig:
364365 } ) ;
365366 }
366367
368+ if ( ossAuto ) {
369+ let ossEndpoint = `https://oss-${ region } .aliyuncs.com` ;
370+ if ( process . env . FC_REGION === region ) {
371+ ossEndpoint = `oss-${ region } -internal.aliyuncs.com` ;
372+ }
373+ if ( region === 'cn-shanghai-finance-1' ) {
374+ if ( process . env . FC_REGION === region ) {
375+ ossEndpoint = `oss-${ region } -pub-internal.aliyuncs.com` ;
376+ } else {
377+ ossEndpoint = `oss-${ region } -pub.aliyuncs.com` ;
378+ }
379+ }
380+ if ( region === 'cn-heyuan-acdr-1' ) {
381+ ossEndpoint = `oss-${ region } -internal.aliyuncs.com` ;
382+ }
383+ if ( process . env . FC_CODE_TEMP_OSS_ENDPOINT ) {
384+ ossEndpoint = process . env . FC_CODE_TEMP_OSS_ENDPOINT ;
385+ }
386+ const oss = new OSS ( region , credential as ICredentials , ossEndpoint ) ;
387+ const { ossBucket } = await oss . deploy ( ) ;
388+ logger . write (
389+ yellow ( `Created oss resource succeeded, please replace ossMountConfig: auto in yaml with:
390+ ossMountConfig:
391+ mountPoints:
392+ - mountDir: /mnt/oss/${ functionName }
393+ bucketName: ${ ossBucket } ,
394+ endpoint: ${ ossEndpoint } ,
395+ readOnly: false\n` ) ,
396+ ) ;
397+ this . createResource . oss = { ossBucket } ;
398+ _ . set ( this . local , 'ossMountConfig' , {
399+ mountPoints : [
400+ {
401+ mountDir : `/mnt/oss/${ functionName } ` ,
402+ bucketName : ossBucket ,
403+ endpoint : ossEndpoint ,
404+ readOnly : false ,
405+ } ,
406+ ] ,
407+ } ) ;
408+ }
409+
367410 if ( roleAuto ) {
368411 const client = new RamClient ( credential as ICredentials ) ;
369412 const arn = await client . initFcDefaultServiceRole ( ) ;
@@ -406,7 +449,7 @@ vpcConfig:
406449 if ( nasAuto ) {
407450 const modelConfig = supplement ?. modelConfig || annotations ?. modelConfig ;
408451 let serverAddr = `${ mountTargetDomain } :/${ functionName } ${
409- isEmpty ( modelConfig ) ? '' : `/${ modelConfig . id } `
452+ isEmpty ( modelConfig ) ? '' : `/${ modelConfig . id } `
410453 } `;
411454 if ( serverAddr . length > 128 ) {
412455 serverAddr = serverAddr . substring ( 0 , 128 ) ;
0 commit comments