@@ -14,7 +14,7 @@ import * as ros from '@alicloud/ros-cdk-core';
1414import * as sls from '@alicloud/ros-cdk-sls' ;
1515import * as nas from '@alicloud/ros-cdk-nas' ;
1616import * as ecs from '@alicloud/ros-cdk-ecs' ;
17- import { RosFunction } from '@alicloud/ros-cdk-fc3/lib/fc3.generated' ;
17+ import { RosFunction , RosFunctionProps } from '@alicloud/ros-cdk-fc3/lib/fc3.generated' ;
1818
1919const storageClassMap = {
2020 [ NasStorageClassEnum . STANDARD_CAPACITY ] : { fileSystemType : 'standard' , storageType : 'Capacity' } ,
@@ -99,11 +99,11 @@ export const resolveFunctions = (
9999 }
100100
101101 const fileSources = functions
102- ?. filter ( ( { code } ) => readCodeSize ( code ) > CODE_ZIP_SIZE_LIMIT )
102+ ?. filter ( ( { code } ) => code ?. path && readCodeSize ( code . path ) > CODE_ZIP_SIZE_LIMIT )
103103 . map ( ( { code, name } ) => {
104104 const fcName = replaceReference ( name , context ) ;
105105
106- return { fcName, ...getFileSource ( fcName , code ) } ;
106+ return { fcName, ...getFileSource ( fcName , code ! . path ) } ;
107107 } ) ;
108108
109109 const destinationBucketName = ros . Fn . sub (
@@ -125,17 +125,48 @@ export const resolveFunctions = (
125125 true ,
126126 ) ;
127127 }
128+
128129 functions ?. forEach ( ( fnc ) => {
129- const storeInBucket = readCodeSize ( fnc . code ) > CODE_ZIP_SIZE_LIMIT ;
130- let code : fc . RosFunction . CodeProperty = {
131- zipFile : resolveCode ( fnc . code ) ,
132- } ;
133- if ( storeInBucket ) {
134- code = {
135- ossBucketName : destinationBucketName ,
136- ossObjectName : fileSources ?. find (
137- ( { fcName } ) => fcName === replaceReference ( fnc . name , context ) ,
138- ) ?. objectKey ,
130+ let runtimeConfig :
131+ | {
132+ customContainerConfig : RosFunctionProps [ 'customContainerConfig' ] ;
133+ runtime : RosFunctionProps [ 'runtime' ] ;
134+ handler : RosFunctionProps [ 'handler' ] ;
135+ }
136+ | {
137+ code : RosFunctionProps [ 'code' ] ;
138+ runtime : RosFunctionProps [ 'runtime' ] ;
139+ handler : RosFunctionProps [ 'handler' ] ;
140+ } ;
141+
142+ const storeInBucket = ! ! fnc . code ?. path && readCodeSize ( fnc . code . path ) > CODE_ZIP_SIZE_LIMIT ;
143+
144+ if ( fnc . container ) {
145+ runtimeConfig = {
146+ runtime : 'custom-container' ,
147+ handler : 'index.handler' ,
148+ customContainerConfig : {
149+ image : fnc . container . image ,
150+ command : fnc . container . cmd ?. split ( ' ' ) ,
151+ port : fnc . container . port ,
152+ } ,
153+ } ;
154+ } else {
155+ let code : fc . RosFunction . CodeProperty = {
156+ zipFile : resolveCode ( fnc . code ! . path ) ,
157+ } ;
158+ if ( storeInBucket ) {
159+ code = {
160+ ossBucketName : destinationBucketName ,
161+ ossObjectName : fileSources ?. find (
162+ ( { fcName } ) => fcName === replaceReference ( fnc . name , context ) ,
163+ ) ?. objectKey ,
164+ } ;
165+ }
166+ runtimeConfig = {
167+ code,
168+ handler : replaceReference ( fnc . code ! . handler , context ) ,
169+ runtime : replaceReference ( fnc . code ! . runtime , context ) ,
139170 } ;
140171 }
141172
@@ -216,15 +247,13 @@ export const resolveFunctions = (
216247 fnc . key ,
217248 {
218249 functionName : replaceReference ( fnc . name , context ) ,
219- handler : replaceReference ( fnc . handler , context ) ,
220- runtime : replaceReference ( fnc . runtime , context ) ,
221250 memorySize : replaceReference ( fnc . memory , context ) ,
222251 timeout : replaceReference ( fnc . timeout , context ) ,
223252 diskSize : fnc . storage ?. disk ,
224253 environmentVariables : replaceReference ( fnc . environment , context ) ,
225- code,
226254 logConfig,
227255 vpcConfig,
256+ ...runtimeConfig ,
228257 nasConfig : fcNas ?. length
229258 ? {
230259 mountPoints : fcNas ?. map ( ( { nasMount, mountDir } ) => ( {
0 commit comments