@@ -8,16 +8,17 @@ import deployDeleteController from './controller/delete';
8
8
import uploadController from './controller/upload' ;
9
9
10
10
import {
11
- CurrentUploadedFile ,
11
+ DeleteBody ,
12
+ DeployBody ,
13
+ Deployment ,
14
+ FetchBranchListBody ,
15
+ FetchFilesFromRepoBody ,
12
16
ProtocolMessageType ,
13
17
WorkerMessage ,
14
18
WorkerMessageUnknown ,
15
19
allApplications ,
16
20
childProcesses ,
17
- deleteBody ,
18
- deployBody ,
19
- fetchBranchListBody ,
20
- fetchFilesFromRepoBody
21
+ deploymentMap
21
22
} from './constants' ;
22
23
23
24
import AppError from './utils/appError' ;
@@ -132,7 +133,7 @@ export const fetchFiles = (
132
133
133
134
export const fetchFilesFromRepo = catchAsync (
134
135
async (
135
- req : Omit < Request , 'body' > & { body : fetchFilesFromRepoBody } ,
136
+ req : Omit < Request , 'body' > & { body : FetchFilesFromRepoBody } ,
136
137
res : Response ,
137
138
next : NextFunction
138
139
) => {
@@ -158,16 +159,16 @@ export const fetchFilesFromRepo = catchAsync(
158
159
const id = dirName ( req . body . url ) ;
159
160
160
161
// TODO: This method is wrong
161
- // currentFile['id'] = id;
162
- // currentFile .path = `${appsDir}/${id}`;
162
+ // deployment.id = id;
163
+ // deployment .path = `${appsDir}/${id}`;
163
164
164
165
return res . status ( 201 ) . send ( { id } ) ;
165
166
}
166
167
) ;
167
168
168
169
export const fetchBranchList = catchAsync (
169
170
async (
170
- req : Omit < Request , 'body' > & { body : fetchBranchListBody } ,
171
+ req : Omit < Request , 'body' > & { body : FetchBranchListBody } ,
171
172
res : Response
172
173
) => {
173
174
const { stdout } = await execPromise (
@@ -190,7 +191,7 @@ export const fetchBranchList = catchAsync(
190
191
191
192
export const fetchFileList = catchAsync (
192
193
async (
193
- req : Omit < Request , 'body' > & { body : fetchFilesFromRepoBody } ,
194
+ req : Omit < Request , 'body' > & { body : FetchFilesFromRepoBody } ,
194
195
res : Response ,
195
196
next : NextFunction
196
197
) => {
@@ -224,44 +225,45 @@ export const fetchFileList = catchAsync(
224
225
225
226
export const deploy = catchAsync (
226
227
async (
227
- req : Omit < Request , 'body' > & { body : deployBody } ,
228
+ req : Omit < Request , 'body' > & { body : DeployBody } ,
228
229
res : Response ,
229
230
next : NextFunction
230
231
) => {
231
232
try {
232
- // TODO Currently Deploy function will only work for workdir, we will add the addRepo
233
+ // TODO: Implement repository
233
234
// req.body.resourceType == 'Repository' &&
234
235
// (await calculatePackages(next));
235
236
236
- console . log ( req . body ) ;
237
+ const deployment = deploymentMap [ req . body . suffix ] ;
237
238
238
- const currentFile : CurrentUploadedFile = {
239
- id : '' ,
240
- type : '' ,
241
- path : '' ,
242
- jsons : [ ]
243
- } ;
239
+ if ( deployment === undefined ) {
240
+ return next (
241
+ new AppError (
242
+ `Invalid deployment id: ${ req . body . suffix } ` ,
243
+ 400
244
+ )
245
+ ) ;
246
+ }
244
247
245
- await installDependencies ( currentFile ) ;
248
+ await installDependencies ( deployment ) ;
246
249
247
- const desiredPath = path . join ( __dirname , '/ worker/ index.js' ) ;
250
+ const desiredPath = path . join ( __dirname , 'worker' , ' index.js') ;
248
251
249
252
const proc = spawn ( 'metacall' , [ desiredPath ] , {
250
253
stdio : [ 'pipe' , 'pipe' , 'pipe' , 'ipc' ]
251
254
} ) ;
252
255
253
256
proc . send ( {
254
257
type : ProtocolMessageType . Load ,
255
- data : currentFile
258
+ data : deployment
256
259
} ) ;
257
260
258
- logProcessOutput ( proc . stdout , proc . pid , currentFile . id ) ;
259
- logProcessOutput ( proc . stderr , proc . pid , currentFile . id ) ;
261
+ logProcessOutput ( proc . stdout , proc . pid , deployment . id ) ;
262
+ logProcessOutput ( proc . stderr , proc . pid , deployment . id ) ;
260
263
261
264
proc . on ( 'message' , ( payload : WorkerMessageUnknown ) => {
262
265
if ( payload . type === ProtocolMessageType . MetaData ) {
263
- const message =
264
- payload as WorkerMessage < CurrentUploadedFile > ;
266
+ const message = payload as WorkerMessage < Deployment > ;
265
267
if ( isIAllApps ( message . data ) ) {
266
268
const appName = Object . keys ( message . data ) [ 0 ] ;
267
269
childProcesses [ appName ] = proc ;
@@ -272,7 +274,7 @@ export const deploy = catchAsync(
272
274
273
275
return res . status ( 200 ) . json ( {
274
276
suffix : hostname ( ) ,
275
- prefix : currentFile . id ,
277
+ prefix : deployment . id ,
276
278
version : 'v1'
277
279
} ) ;
278
280
} catch ( err ) {
@@ -290,7 +292,7 @@ export const showLogs = (req: Request, res: Response): Response => {
290
292
} ;
291
293
292
294
export const deployDelete = (
293
- req : Omit < Request , 'body' > & { body : deleteBody } ,
295
+ req : Omit < Request , 'body' > & { body : DeleteBody } ,
294
296
res : Response ,
295
297
next : NextFunction
296
298
) : void => deployDeleteController ( req , res , next ) ;
@@ -303,18 +305,3 @@ export const validateAndDeployEnabled = (
303
305
status : 'success' ,
304
306
data : true
305
307
} ) ;
306
-
307
- /**
308
- * deploy
309
- * Provide a mesage that repo has been deployed, use --inspect to know more about deployment
310
- * We can add the type of url in the --inspect
311
- * If there is already metacall.json present then, log found metacall.json and reading it, reading done
312
- * We must an option to go back in the fileselection wizard so that, user dont have to close the connection
313
- * At the end of deployment through deploy cli, we should run the --inspect command so that current deployed file is shown and show only the current deployed app
314
- *
315
- *
316
- * FAAS
317
- * the apps are not getting detected once the server closes, do we need to again deploy them
318
- * find a way to detect metacall.json in the files and dont deploy if there is not because json ke through we are uploading
319
- *
320
- */
0 commit comments