1
1
import * as ros from '@alicloud/ros-cdk-core' ;
2
2
import fs from 'node:fs' ;
3
3
4
- import { ActionContext , ServerlessIac } from '../types' ;
4
+ import { ServerlessIac } from '../types' ;
5
5
import {
6
6
cleanupAssets ,
7
7
constructAssets ,
8
+ getContext ,
8
9
logger ,
9
10
ProviderEnum ,
10
11
publishAssets ,
@@ -14,11 +15,8 @@ import { prepareBootstrapStack, RosStack } from './rosStack';
14
15
import { RfsStack } from './rfsStack' ;
15
16
import { get } from 'lodash' ;
16
17
17
- export const generateRosStackTemplate = (
18
- stackName : string ,
19
- iac : ServerlessIac ,
20
- context : ActionContext ,
21
- ) => {
18
+ export const generateRosStackTemplate = ( stackName : string , iac : ServerlessIac ) => {
19
+ const context = getContext ( ) ;
22
20
const app = new ros . App ( ) ;
23
21
new RosStack ( app , iac , context ) ;
24
22
@@ -36,39 +34,31 @@ export const generateRosStackTemplate = (
36
34
return { template, assets } ;
37
35
} ;
38
36
39
- export const generateRfsStackTemplate = (
40
- stackName : string ,
41
- iac : ServerlessIac ,
42
- context : ActionContext ,
43
- ) => {
44
- const stack = new RfsStack ( iac , context ) ;
37
+ export const generateRfsStackTemplate = ( stackName : string , iac : ServerlessIac ) => {
38
+ const stack = new RfsStack ( iac ) ;
45
39
46
40
const hcl = stack . toHclTerraform ( ) ;
47
41
console . log ( 'HCL:' , hcl ) ;
48
42
49
43
return { template : hcl } ;
50
44
} ;
51
45
52
- export const deployStack = async (
53
- stackName : string ,
54
- iac : ServerlessIac ,
55
- context : ActionContext ,
56
- ) => {
57
- const { template, assets } = generateRosStackTemplate ( stackName , iac , context ) ;
58
- await prepareBootstrapStack ( context ) ;
46
+ export const deployStack = async ( stackName : string , iac : ServerlessIac ) => {
47
+ const { template, assets } = generateRosStackTemplate ( stackName , iac ) ;
48
+ await prepareBootstrapStack ( ) ;
59
49
logger . info ( `Deploying stack, publishing assets...` ) ;
60
- const constructedAssets = await constructAssets ( assets , context . region ) ;
50
+ const constructedAssets = await constructAssets ( assets ) ;
61
51
try {
62
- await publishAssets ( constructedAssets , context ) ;
52
+ await publishAssets ( constructedAssets ) ;
63
53
logger . info ( `Assets published! 🎉` ) ;
64
- await rosStackDeploy ( stackName , template , context ) ;
54
+ await rosStackDeploy ( stackName , template ) ;
65
55
} catch ( e ) {
66
56
logger . error ( `Failed to deploy stack: ${ e } ` ) ;
67
57
throw e ;
68
58
} finally {
69
59
try {
70
60
logger . info ( `Cleaning up temporary Assets...` ) ;
71
- await cleanupAssets ( constructedAssets , context ) ;
61
+ await cleanupAssets ( constructedAssets ) ;
72
62
logger . info ( `Assets cleaned up!♻️` ) ;
73
63
} catch ( e ) {
74
64
logger . error (
@@ -81,12 +71,11 @@ export const deployStack = async (
81
71
export const generateStackTemplate = (
82
72
stackName : string ,
83
73
iac : ServerlessIac ,
84
- context : ActionContext ,
85
74
) : { template : unknown } => {
86
75
if ( iac . provider . name === ProviderEnum . ALIYUN ) {
87
- return generateRosStackTemplate ( stackName , iac , context ) ;
76
+ return generateRosStackTemplate ( stackName , iac ) ;
88
77
} else if ( iac . provider . name === ProviderEnum . HUAWEI ) {
89
- return generateRfsStackTemplate ( stackName , iac , context ) ;
78
+ return generateRfsStackTemplate ( stackName , iac ) ;
90
79
}
91
80
return { template : '' } ;
92
81
} ;
0 commit comments