Skip to content

Commit a2ac984

Browse files
committed
fix: ossConfig auto
1 parent 1fc974a commit a2ac984

7 files changed

Lines changed: 51 additions & 6 deletions

File tree

__tests__/e2e/ci-mac-linux.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ s invoke -e '{"hello":"fc nodejs with auto"}' -t s_auto.yaml
8585
s info -y -t s_auto.yaml
8686
s remove -y -t s_auto.yaml
8787

88+
echo "test nodejs runtime with oss config auto ..."
89+
export fc_component_function_name=nodejs18-$(uname)-$(uname -m)-$RANDSTR
90+
s deploy -y -t ./s_oss_config_auto.yaml
91+
s invoke -e '{"hello":"fc nodejs with oss config auto"}' -t ./s_oss_config_auto.yaml
92+
s info -y -t ./s_oss_config_auto.yaml
93+
s remove -y -t ./s_oss_config_auto.yaml
94+
8895
echo "test nodejs runtime with more vpc and nas auto ..."
8996
export fc_component_function_name=nodejs16-$(uname)-$(uname -m)-$RANDSTR
9097
s deploy -y -t ./s_lock_auto.yaml
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
edition: 3.0.0
2+
name: test-node-app
3+
access: quanxi
4+
5+
vars:
6+
region: ${env('REGION', 'cn-hongkong')}
7+
8+
resources:
9+
fcDemo:
10+
component: ${env('fc_component_version', path('../../../'))}
11+
props:
12+
region: ${vars.region}
13+
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfig
14+
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole
15+
runtime: ${env('fc_component_runtime', 'nodejs18')}
16+
code: './test-auto-code'
17+
handler: index.handler
18+
memorySize: 128
19+
timeout: 60
20+
ossMountConfig: auto
21+
22+
fcDemo2: # 业务名称/模块名称
23+
component: ${env('fc_component_version', path('../../../'))}
24+
props: # 组件的属性值
25+
region: ${vars.region}
26+
functionName: fc3-event-${env('fc_component_function_name', 'nodejs18')}-ossConfigF2
27+
role: acs:ram::${config('AccountID')}:role/aliyunaliyunfcdefaultrole
28+
runtime: ${env('fc_component_runtime', 'nodejs18')}
29+
code: ./test-auto-code
30+
handler: index.handler
31+
memorySize: 128
32+
timeout: 60
33+
ossMountConfig: auto|rules=[{"allowedOrigin":"*","allowedMethod":"GET","allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",
3030
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
3131
"@serverless-cd/srm-aliyun-sls20201230": "0.0.5-beta.3",
32-
"@serverless-cd/srm-aliyun-oss": "^0.0.1-beta.4",
32+
"@serverless-cd/srm-aliyun-oss": "^0.0.1-beta.6",
3333
"@serverless-devs/diff": "^0.0.3-beta.6",
3434
"@serverless-devs/downloads": "^0.0.7",
3535
"@serverless-devs/load-component": "^0.0.9",

src/interface/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export interface IFunction {
140140

141141
logConfig?: 'auto' | ILogConfig;
142142
nasConfig?: 'auto' | INasConfig;
143-
ossMountConfig?: IOssMountConfig;
143+
ossMountConfig?: 'auto' | IOssMountConfig;
144144
role?: 'auto' | string;
145145
vpcConfig?: 'auto' | IVpcConfig;
146146
vpcBinding?: {

src/resources/oss/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export default class OSS {
2222
this.client = new Oss();
2323
}
2424

25-
async deploy(): Promise<{ ossBucket: string }> {
25+
async deploy(ossMountConfig = ''): Promise<{ ossBucket: string }> {
2626
logger.debug(`init oss: ${JSON.stringify(this.config)}`);
27-
const result = await this.client.initOss(this.config);
27+
const result = await this.client.initOss(this.config, ossMountConfig);
2828
const ossBucket = result?.ossBucket || '';
2929
if (isAppCenter()) {
3030
logger.info(`created oss region: ${this.region};`);

src/subCommands/deploy/impl/function.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ logConfig:
373373
}
374374
logger.info(`ossAuto code to ${ossEndpoint}`);
375375
const oss = new OSS(region, credential as ICredentials, ossEndpoint);
376-
const { ossBucket } = await oss.deploy();
376+
const { ossBucket } = await oss.deploy(this.inputs.props.ossMountConfig as string);
377+
377378
logger.write(
378379
yellow(`Created oss resource succeeded, please replace ossMountConfig: auto in yaml with:
379380
ossMountConfig:

src/utils/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export const isAuto = (config: unknown): boolean => {
4242
return false;
4343
}
4444

45-
return _.toUpper(config) === 'AUTO';
45+
if (_.toUpper(config) === 'AUTO') {
46+
return true;
47+
}
48+
const autoConfig = config.split('|')[0];
49+
return _.toUpper(autoConfig) === 'AUTO';
4650
};
4751

4852
export const isAutoVpcConfig = (config: unknown): boolean => {

0 commit comments

Comments
 (0)