Skip to content

How to setup, test, and continuously deploy Firebase Cloud Function v1.0

License

Notifications You must be signed in to change notification settings

jeremylorino/firebase-functions-unittest-cd

Repository files navigation

Firebase Cloud Functions

How to setup, test, and continuously deploy Firebase Cloud Function v1.0

Table of Contents

Setup

To learn how to get started with Cloud Functions for Firebase by having a look at their Getting Started Guide, trying the quickstart samples and looking at the documentation.

  1. Install Node.js v8.10.0 or greater

  2. Install Node.js dependencies

    This will install everything required to setup, test, and deploy this repository:

     npm install
    

Obtain service account credentials

  • Go to API Manager -> Credentials
  • Click "New Credentials", and create a service account or click here
  • Download the JSON for this service account, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the file containing the JSON credentials.

Set the GOOGLE_APPLICATION_CREDENTIALS environment variable:

Linux:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json

Windows:

set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json

Windows (PowerShell):

$env:GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account_file.json"

Read more about Google Cloud Platform Authentication.

Authenticate the Firebase CLI

npm run firebase:login
> [email protected] firebase:login /home/ubuntu/workspace/firebase-functions-unittest-cd
> npm run firebase -- login --no-localhost


> [email protected] firebase /home/ubuntu/workspace/firebase-functions-unittest-cd
> firebase "login" "--no-localhost"

? Allow Firebase to collect anonymous CLI usage and error reporting information? Yes

Visit this URL on any device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=...

? Paste authorization code here: 4/my-auth-code

✔  Success! Logged in as [email protected]

Initialize the project directory

npm run firebase:init:functions
> [email protected] firebase:init:funcs /home/ubuntu/workspace/firebase-functions-unittest-cd
> npm run firebase -- init functions


> [email protected] firebase /home/ubuntu/workspace/firebase-functions-unittest-cd
> firebase "init" "functions"


     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  /home/ubuntu/workspace/firebase-functions-unittest-cd


=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

? Select a default Firebase project for this directory: (Use arrow keys)
  [don't setup a default project]
❯ My Firebase Project (myproject-198914)
  [create a new project]
=== Functions Setup

A functions directory will be created in your project with a Node.js
package pre-configured. Functions can be deployed with firebase deploy.

? What language would you like to use to write Cloud Functions?
  JavaScript
❯ TypeScript
? Do you want to use TSLint to catch probable bugs and enforce style? Yes
? File functions/package.json already exists. Overwrite? No
i  Skipping write of functions/package.json
? File functions/tslint.json already exists. Overwrite? No
? File functions/tsconfig.json already exists. Overwrite? No
i  Skipping write of functions/tslint.json
i  Skipping write of functions/tsconfig.json
? File functions/src/index.ts already exists. Overwrite? No
i  Skipping write of functions/src/index.ts
? Do you want to install dependencies with npm now? Yes

npm notice created a lockfile as package-lock.json. You should commit this file.
added 570 packages from 469 contributors in 29.528s

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

✔  Firebase initialization complete!

About

How to setup, test, and continuously deploy Firebase Cloud Function v1.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published