diff --git a/Dockerfile b/Dockerfile index 8756068..4cd9fe9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,5 +52,5 @@ CMD ["node", "dist/index.js"] FROM base AS test RUN apt-get update \ - && apt-get install curl ca-certificates jq git -y --no-install-recommends \ + && apt-get install curl ca-certificates jq git expect -y --no-install-recommends \ && npm install -g @metacall/deploy diff --git a/package-lock.json b/package-lock.json index fdde7e9..ab2763c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@metacall/faas", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@metacall/faas", - "version": "0.1.0", + "version": "0.1.2", "license": "Apache-2.0", "dependencies": { "@metacall/protocol": "^0.1.26", diff --git a/package.json b/package.json index 48353a9..a7c94ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@metacall/faas", - "version": "0.1.1", + "version": "0.1.2", "description": "Reimplementation of MetaCall FaaS platform written in TypeScript.", "main": "dist/index.js", "bin": { diff --git a/src/controller/repository.ts b/src/controller/repository.ts index fb6d65d..5afeb8e 100644 --- a/src/controller/repository.ts +++ b/src/controller/repository.ts @@ -1,6 +1,6 @@ import { NextFunction, Request, Response } from 'express'; import { promises as fs } from 'fs'; -import { join } from 'path'; +import path, { join } from 'path'; import { Application, Applications, Resource } from '../app'; import AppError from '../utils/appError'; import { appsDirectory } from '../utils/config'; @@ -31,6 +31,25 @@ const deleteRepoFolderIfExist = async ( await fs.rm(repoFilePath, { recursive: true, force: true }); }; +const handleRunners = async (repoPath: string): Promise => { + const runners: string[] = []; + const files = await fs.readdir(repoPath); + + for (const file of files) { + const fullPath = path.join(repoPath, file); + const stat = await fs.stat(fullPath); + + if (file === 'requirements.txt') runners.push('python'); + + if (file === 'package.json') runners.push('nodejs'); + + if (stat.isDirectory()) { + await handleRunners(fullPath); + } + } + return runners; +}; + export const fetchFilesFromRepo = catchAsync( async ( req: Omit & { body: FetchFilesFromRepoBody }, @@ -41,13 +60,14 @@ export const fetchFilesFromRepo = catchAsync( const resource: Resource = { id: '', path: '', - jsons: [] + jsons: [], + runners: [] }; try { await deleteRepoFolderIfExist(appsDirectory, url); } catch (err) { - next( + return next( new AppError( 'error occurred in deleting repository directory', 500 @@ -74,6 +94,13 @@ export const fetchFilesFromRepo = catchAsync( resource.id = id; resource.path = join(appsDirectory, id); + const detectedRunners = await handleRunners(resource.path); + if (detectedRunners.length > 0) { + resource.runners = detectedRunners; + } else { + console.warn('No runners detected'); + } + // Create a new Application instance and assign the resource to it const application = new Application(); application.resource = Promise.resolve(resource); diff --git a/test/test.sh b/test/test.sh index 481a3dd..30cc959 100755 --- a/test/test.sh +++ b/test/test.sh @@ -191,4 +191,137 @@ run_tests "python-base-app" test_python_base_app run_tests "python-dependency-app" test_python_dependency_app run_tests "nodejs-dependency-app" test_nodejs_dependency_app -echo "Integration tests passed without errors." +echo "Integration tests for package deployment passed without errors." + +echo "Integration tests for deploy with repo url starts" +function test_deploy_from_repo() { + local repo_url=$1 + local app_name=$2 + local test_func=$3 + + echo "Testing Deployment from repository: $repo_url" + + # Deploy the repository using expect to handle the interactive prompts + expect <