( firebaseTools: FirebaseTools, context: BuilderContext, workspaceRoot: string, staticBuildTarget: BuildTarget, serverBuildTarget: BuildTarget, options: DeployBuilderOptions, firebaseToken?: string, fsHost: FSHost = defaultFsHost )
| 274 | |
| 275 | |
| 276 | export const deployToCloudRun = async ( |
| 277 | firebaseTools: FirebaseTools, |
| 278 | context: BuilderContext, |
| 279 | workspaceRoot: string, |
| 280 | staticBuildTarget: BuildTarget, |
| 281 | serverBuildTarget: BuildTarget, |
| 282 | options: DeployBuilderOptions, |
| 283 | firebaseToken?: string, |
| 284 | fsHost: FSHost = defaultFsHost |
| 285 | ) => { |
| 286 | |
| 287 | const staticBuildOptions = await context.getTargetOptions(targetFromTargetString(staticBuildTarget.name)); |
| 288 | if (!staticBuildOptions.outputPath || typeof staticBuildOptions.outputPath !== 'string') { |
| 289 | throw new Error( |
| 290 | `Cannot read the output path option of the Angular project '${staticBuildTarget.name}' in angular.json` |
| 291 | ); |
| 292 | } |
| 293 | |
| 294 | const serverBuildOptions = await context.getTargetOptions(targetFromTargetString(serverBuildTarget.name)); |
| 295 | if (!serverBuildOptions.outputPath || typeof serverBuildOptions.outputPath !== 'string') { |
| 296 | throw new Error( |
| 297 | `Cannot read the output path option of the Angular project '${serverBuildTarget.name}' in angular.json` |
| 298 | ); |
| 299 | } |
| 300 | |
| 301 | const staticOut = join(workspaceRoot, staticBuildOptions.outputPath); |
| 302 | const serverOut = join(workspaceRoot, serverBuildOptions.outputPath); |
| 303 | |
| 304 | const cloudRunOut = options.outputPath ? join(workspaceRoot, options.outputPath) : join(dirname(serverOut), 'run'); |
| 305 | const serviceId = options.functionName || DEFAULT_FUNCTION_NAME; |
| 306 | |
| 307 | const newStaticOut = join(cloudRunOut, staticBuildOptions.outputPath); |
| 308 | const newServerOut = join(cloudRunOut, serverBuildOptions.outputPath); |
| 309 | |
| 310 | // This is needed because in the server output there's a hardcoded dependency on $cwd/dist/browser, |
| 311 | // This assumes that we've deployed our application dist directory and we're running the server |
| 312 | // in the parent directory. To have this precondition, we move dist/browser to dist/dist/browser |
| 313 | // since the firebase function runs the server from dist. |
| 314 | fsHost.removeSync(cloudRunOut); |
| 315 | fsHost.copySync(staticOut, newStaticOut); |
| 316 | fsHost.copySync(serverOut, newServerOut); |
| 317 | |
| 318 | const packageJson = getPackageJson(context, workspaceRoot, options, join(serverBuildOptions.outputPath, 'main.js')); |
| 319 | const nodeVersion = packageJson.engines.node; |
| 320 | |
| 321 | if (!satisfies(process.versions.node, nodeVersion.toString())) { |
| 322 | context.logger.warn( |
| 323 | `⚠️ Your Node.js version (${process.versions.node}) does not match the Cloud Run runtime (${nodeVersion}).` |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | fsHost.writeFileSync( |
| 328 | join(cloudRunOut, 'package.json'), |
| 329 | JSON.stringify(packageJson, null, 2), |
| 330 | ); |
| 331 | |
| 332 | fsHost.writeFileSync( |
| 333 | join(cloudRunOut, 'Dockerfile'), |
no test coverage detected