Yusuke Izumi
Yusuke Izumi

Reputation: 41

Problem deploying Firebase Functions from AWS Code Build

I'm having a difficulty deploying Firebase functions from CI (namely AWS CodeBuild) due to unknown reasons.

The firebase deploy command is invoked with --token argument, so it doesn't seem like an authentication issue, in fact, hosting files are being deployed without any issues.

One suspicion I have is that when I run this locally, it works like a charm, and the obvious difference is the part that says package . (263 B) for uploading because when I run it locally, it has way more than 263-bytes (local says 69.23 MB). Also, because it runs locally without any issues, I don't think there is any issue with firebase.json is configured incorrectly.

Has anyone ran into a similar issue?

$ export DOTENV_RUNTIME=qa1 && cross-env NODE_ENV=production firebase deploy --only hosting,functions --token $FIREBASE_TOKEN

...
i  deploying functions, hosting
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing . directory for uploading...
i  functions: packaged . (263 B) for uploading
✔  functions: . folder uploaded successfully
i  hosting[project-xyz]: beginning deploy...
i  hosting[project-xyz]: found 47 files in public
✔  hosting[project-xyz]: file upload complete
i  functions: updating Node.js 12 function nextServer(us-central1)...
⚠  functions[nextServer(us-central1)]: Deployment error.
Build failed: function.js does not exist; Error ID: 7485c5b6


Functions deploy had errors with the following functions:
    nextServer


To try redeploying those functions, run:
    firebase deploy --only "functions:nextServer"


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here are the contents of some of the relevant configuration files:

firebase.json

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "function": "nextServer"
      }
    ]
  },
  "functions": {
    "source": ".",
    "ignore": [
      ".git/**",
      ".firebase/**",
      ".firebaserc",
      "**/node_modules/**",
      "**/public/**",
      "**/src/**"
    ]
  }
}

package.json

{
  ...
  "main": "dist/server/index.js",
  "engines": {
    "node": "12"
  },
  ...
}
Here's the root directory structure.
$ tree -v -L 1 -a
.
├── .firebase
├── .firebaserc
├── .git
├── .gitignore
├── README.md
├── dist
├── firebase.json
├── node_modules
├── package.json
├── public
├── src
└── yarn.lock

Upvotes: 1

Views: 396

Answers (1)

Yusuke Izumi
Yusuke Izumi

Reputation: 41

I went through the firebase-tools source code and found that when using AWS Code Build, the source is downloaded and built under /codebuild/output/src123456789/src/github.com/.... If you ignore **/src/**, no files would be targeted for deploy because the path name contains src. This also answers why the packaged size was so small.

Thanks to @nVitius for raising questions.

Upvotes: 1

Related Questions