Within my monorepo, I have a folder containing Typescript cloud functions that I want to deploy using GCP cloud build. Unfortunately, it appears that cloud build is unable to locate the package.json file within this specific folder. It seems to be expecting it to be in the root directory instead. What would be the most effective approach to successfully deploy these cloud functions?
Directory Structure:
repo
- app2
- functions
- cloudbuild.yaml
- src
- index.ts
- onNewPostComment
- index.ts
- function2...
- package.json
- package-lock.json
- tsconfig.json
Contents of my cloudbuild.yaml:
steps:
- name: 'gcr.io/cloud-builders/npm'
args: [ 'install']
- name: 'gcr.io/cloud-builders/npm'
args: [ 'run','build']
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: 'deploy-onNewPostComment'
args:
- gcloud
- functions
- deploy
- onNewPostComment
- --region=europe-west2
- --source=.
- --entry-point=onNewPostComment
- --trigger-http
- --runtime=nodejs16
package.json structure:
{
"name": "functions",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "npm run build && firebase deploy --only functions",
...,
"engines": {
"node": "16"
},
"main": "lib/index.js",
...
"private": true
}
GCP cloud build output for npm install:
Already have image (with digest): gcr.io/cloud-builders/npm
npm WARN saveError ENOENT: no such file or directory, open '/workspace/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/workspace/package.json'
npm WARN workspace No description
npm WARN workspace No repository field.
npm WARN workspace No README data
npm WARN workspace No license field.
up to date in 0.293s
found 0 vulnerabilities
Error encountered during npm build:
Already have image (with digest): gcr.io/cloud-builders/npm
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /workspace/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/workspace/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /builder/home/.npm/_logs/2022-07-27T09_05_46_164Z-debug.log