-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate discovery with composer (#6042)
* Added runtime command discovery * Resolved comments * Added error case to analyse codebase method * Updated install command * Reorganized tests and removed unwated promise.resolve stmt * Added review changes on install command and node version string array * Changes to node.ts to include additional condions on run script * Added code comments to types * Integrate discovery with composer * Minor modification * Minor changes * Minor changes * Resolved code commits * Added undefied to return if no cmd * Added undefied to return if no cmd * Added frameworkhook interface * code comments * format error msg * format error msg * format error msg * format error msg * Code comments * Fixed imports and compose command * Fix bugs. * Update base image for node runtime. * bug fix * bug fix * Remove hooks --------- Co-authored-by: Daniel Young Lee <danielylee@google.com>
- Loading branch information
Showing
11 changed files
with
113 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import { AppSpec } from "../interfaces"; | ||
import { Runtime, FileSystem, FrameworkSpec, RuntimeSpec } from "./types"; | ||
import { NodejsRuntime } from "./runtime/node"; | ||
import { FirebaseError } from "../../../error"; | ||
|
||
const supportedRuntimes: Runtime[] = [new NodejsRuntime()]; | ||
|
||
/** | ||
* Discover framework in the given project directory | ||
* Discover the best matching runtime specs for the application. | ||
*/ | ||
export function discover(): AppSpec { | ||
return { | ||
baseImage: "us-docker.pkg.dev/firestack-build/test/run:latest", | ||
environmentVariables: { | ||
NODE_ENV: "PRODUCTION", | ||
}, | ||
installCommand: "npm install", | ||
buildCommand: "npm run build", | ||
startCommand: "npm run start", | ||
export async function discover( | ||
fs: FileSystem, | ||
allFrameworkSpecs: FrameworkSpec[] | ||
): Promise<RuntimeSpec> { | ||
try { | ||
let discoveredRuntime = undefined; | ||
for (const runtime of supportedRuntimes) { | ||
if (await runtime.match(fs)) { | ||
if (!discoveredRuntime) { | ||
discoveredRuntime = runtime; | ||
} else { | ||
throw new FirebaseError( | ||
`Conflit occurred as multiple runtimes ${discoveredRuntime.getRuntimeName()}, ${runtime.getRuntimeName()} are discovered in the application.` | ||
); | ||
} | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
afterInstall: (b) => { | ||
console.log("HOOK: AFTER INSTALL"); | ||
return { ...b, version: "v1alpha", notes: "afterInstall" }; | ||
}, | ||
if (!discoveredRuntime) { | ||
throw new FirebaseError( | ||
`Unable to determine the specific runtime for the application. The supported runtime options include ${supportedRuntimes | ||
.map((x) => x.getRuntimeName()) | ||
.join(" , ")}.` | ||
); | ||
} | ||
const runtimeSpec = await discoveredRuntime.analyseCodebase(fs, allFrameworkSpecs); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
afterBuild(b) { | ||
console.log("HOOK: AFTER BUILD"); | ||
return { ...b, version: "v1alpha", notes: "afterBuild" }; | ||
}, | ||
}; | ||
return runtimeSpec; | ||
} catch (error: any) { | ||
throw new FirebaseError( | ||
`Failed to identify required specifications to execute the application: ${error}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters