Skip to content

Commit 1701bc8

Browse files
authored
feat: enable fc container runtime (#51)
feat: enable fc container runtime Refs: #40 --------- Signed-off-by: seven <[email protected]>
1 parent 513f409 commit 1701bc8

File tree

8 files changed

+87
-26
lines changed

8 files changed

+87
-26
lines changed

samples/aliyun-poc-domain.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 0.0.1
2+
3+
provider:
4+
name: aliyun
5+
region: cn-hongkong
6+
7+
8+
service: insight-poc-domain
9+
10+
tags:
11+
owner: geek-fun
12+
13+
buckets:
14+
insight_poc_bucket:
15+
name: insight-poc-domain
16+
website:
17+
code: dist
18+
domain: meke-ui.serverlessinsight.com
19+
index: index.html
20+
error_page: 404.html
21+
error_code: 404

samples/aliyun-poc-fc-gpu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stages:
1313
dev:
1414
node_env: development
1515
prod:
16-
region: cn-shanghai
16+
region: cn-hangzhou
1717

1818
service: insight-poc-gpu
1919

src/commands/deploy.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { deployStack } from '../stack';
2-
import { constructActionContext, logger } from '../common';
2+
import { constructActionContext, getIacLocation, logger } from '../common';
33
import { parseYaml } from '../parser';
44

55
export const deploy = async (
66
stackName: string,
7-
options: { location: string; parameters: { [key: string]: string }; stage: string | undefined },
7+
options: {
8+
location: string;
9+
parameters?: { [key: string]: string };
10+
stage?: string;
11+
region?: string;
12+
provider?: string;
13+
accessKeyId?: string;
14+
accessKeySecret?: string;
15+
securityToken?: string;
16+
},
817
) => {
9-
const context = constructActionContext({ ...options, stackName });
1018
logger.info('Validating yaml...');
11-
const iac = parseYaml(context.iacLocation);
19+
const iac = parseYaml(getIacLocation(options.location));
1220
logger.info('Yaml is valid! 🎉');
1321

22+
const context = constructActionContext({ ...options, stackName, iacProvider: iac.provider });
23+
1424
logger.info('Deploying stack...');
1525
await deployStack(stackName, iac, context);
1626

src/commands/index.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ program
2828
.option('-s, --stage <stage>', 'specify the stage')
2929
.action((stackName, { file, stage }) => {
3030
logger.debug('log command info');
31-
validate(file, stage);
31+
validate(stackName, { stage, location: file });
3232
});
3333

3434
program
3535
.command('deploy <stackName>')
3636
.description('deploy serverless Iac yaml')
3737
.option('-f, --file <path>', 'specify the yaml file')
3838
.option('-s, --stage <stage>', 'specify the stage')
39+
.option('-r, --region <region>', 'specify the region')
40+
.option('-pr, --provider <provider>', 'specify the provider')
41+
.option('-ak, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
42+
.option('-as, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
43+
.option('-at, --securityToken <securityToken>', 'specify the SecurityToken')
3944
.option(
4045
'-p, --parameter <key=value>',
4146
'override parameters',
@@ -46,9 +51,23 @@ program
4651
},
4752
{},
4853
)
49-
.action(async (stackName, { file, parameter, stage }) => {
50-
await deploy(stackName, { location: file, parameters: parameter, stage });
51-
});
54+
.action(
55+
async (
56+
stackName,
57+
{ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken },
58+
) => {
59+
await deploy(stackName, {
60+
stage,
61+
parameters: parameter,
62+
location: file,
63+
region,
64+
provider,
65+
accessKeyId,
66+
accessKeySecret,
67+
securityToken,
68+
});
69+
},
70+
);
5271

5372
program
5473
.command('template <stackName>')

src/commands/validate.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { constructActionContext, logger } from '../common';
22
import { parseYaml } from '../parser';
33

4-
export const validate = (location: string | undefined, stage: string | undefined) => {
5-
const context = constructActionContext({ location, stage });
4+
export const validate = (
5+
stackName: string,
6+
options: { location: string | undefined; stage: string | undefined },
7+
) => {
8+
const context = constructActionContext({ stackName, ...options });
69
parseYaml(context.iacLocation);
710
logger.info('Yaml is valid! 🎉');
811
};

src/common/actionContext.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActionContext } from '../types';
1+
import { ActionContext, ServerlessIac } from '../types';
22
import path from 'node:path';
33
import { ProviderEnum } from './providerEnum';
44

@@ -12,28 +12,32 @@ export const getIacLocation = (location?: string): string => {
1212
path.resolve(projectRoot, 'serverless-insight.yml');
1313
};
1414

15-
export const constructActionContext = (config?: {
15+
export const constructActionContext = (config: {
16+
stage?: string;
17+
stackName?: string;
1618
region?: string;
1719
provider?: string;
18-
account?: string;
1920
accessKeyId?: string;
2021
accessKeySecret?: string;
2122
securityToken?: string;
2223
location?: string;
2324
parameters?: { [key: string]: string };
24-
stage?: string;
25-
stackName?: string;
25+
iacProvider?: ServerlessIac['provider'];
2626
}): ActionContext => {
2727
return {
28-
stage: config?.stage ?? 'default',
29-
stackName: config?.stackName ?? '',
28+
stage: config.stage ?? 'default',
29+
stackName: config.stackName ?? '',
30+
provider: (config.provider ?? config.iacProvider?.name ?? ProviderEnum.ALIYUN) as ProviderEnum,
3031
region:
31-
config?.region ?? process.env.ROS_REGION_ID ?? process.env.ALIYUN_REGION ?? 'cn-hangzhou',
32-
accessKeyId: config?.accessKeyId ?? (process.env.ALIYUN_ACCESS_KEY_ID as string),
33-
accessKeySecret: config?.accessKeySecret ?? (process.env.ALIYUN_ACCESS_KEY_SECRET as string),
34-
securityToken: config?.securityToken ?? process.env.ALIYUN_SECURITY_TOKEN,
35-
iacLocation: getIacLocation(config?.location),
36-
parameters: Object.entries(config?.parameters ?? {}).map(([key, value]) => ({ key, value })),
37-
provider: config?.provider as ProviderEnum,
32+
config.region ??
33+
config.iacProvider?.region ??
34+
process.env.ROS_REGION_ID ??
35+
process.env.ALIYUN_REGION ??
36+
'cn-hangzhou',
37+
accessKeyId: config.accessKeyId ?? (process.env.ALIYUN_ACCESS_KEY_ID as string),
38+
accessKeySecret: config.accessKeySecret ?? (process.env.ALIYUN_ACCESS_KEY_SECRET as string),
39+
securityToken: config.securityToken ?? process.env.ALIYUN_SECURITY_TOKEN,
40+
iacLocation: getIacLocation(config.location),
41+
parameters: Object.entries(config.parameters ?? {}).map(([key, value]) => ({ key, value })),
3842
};
3943
};

tests/commands/deploy.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ describe('unit test for deploy command', () => {
1818
});
1919

2020
expect(mockedDeployStack).toHaveBeenCalledTimes(1);
21-
expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), defaultContext);
21+
expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), {
22+
...defaultContext,
23+
region: 'cn-chengdu',
24+
});
2225
});
2326
});

tests/fixtures/deployFixture.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ export const defaultContext = {
14071407
iacLocation: expect.stringContaining('tests/fixtures/serverless-insight.yml'),
14081408
parameters: [],
14091409
region: 'cn-hangzhou',
1410+
provider: 'aliyun',
14101411
securityToken: 'account id',
14111412
stackName: 'my-demo-stack',
14121413
stage: 'default',

0 commit comments

Comments
 (0)