Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building with Firebase

Building with Firebase

This talk looks at converting an existing GCP serverless application into one build using Firebase. Firebase helps to simplify deployment, particularly around simple web hosting. The talk also looks at how easy it is to use GCP services integrated with Firebase such as authentication and Cloud Firestore.

Mike Fowler

October 07, 2019
Tweet

More Decks by Mike Fowler

Other Decks in Technology

Transcript

  1. Building with Firebase Mike Fowler, SRE - Google Professional Cloud

    Architect, Data Engineer & Developer PLACE CUSTOMER LOGO HERE
  2. AI Platform • Hosted Jupyter notebooks • Distributable training with

    automatic resource provisioning • Supports CPUs, GPUs and TPUs • Run across many nodes and multiple experiments • Automated hyperparameter tuning with HyperTune • Exportable models • Model hosting for online prediction
  3. Cloud Functions • Function-as-a-Service supporting: - Node.js 6, 8 &

    10 - Python 3.7.1 - Go 1.11.6 • Triggerable from: - HTTP - Cloud Storage - Pub/Sub - Cloud Scheduler
  4. Motivation for Building with Firebase • Ease of deployment •

    Simple hosting • Simple, but powerful, authentication
  5. Getting Started $ firebase init ◯ Database: Deploy Firebase Realtime

    Database Rules ◉ Firestore: Deploy rules and create indexes for Firestore ◉ Functions: Configure and deploy Cloud Functions ❯◉ Hosting: Configure and deploy Firebase Hosting sites ◯ Storage: Deploy Cloud Storage security rules
  6. Getting Started === 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 ? Do you want to use ESLint to catch probable bugs and enforce style? No ✔ Wrote functions/package.json ✔ Wrote functions/index.js ✔ Wrote functions/.gitignore ? Do you want to install dependencies with npm now? Yes
  7. Refactoring to Firebase exports.pdnotify = (req, res) => { //Handle

    PagerDuty notification }; const functions = require('firebase-functions'); exports.pdnotify = functions.https.onRequest((req, res) => { //Handle PagerDuty notification });
  8. Deployment $ firebase deploy --only functions === Deploying to 'omicron-theta-2336'...

    i deploying functions i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading... i functions: packaged functions (1.04 KB) for uploading ✔ functions: functions folder uploaded successfully i functions: creating Node.js 8 function pdnotify(us-central1)... ✔ functions[pdnotify(us-central1)]: Successful create operation. Function URL (pdnotify): https://us-central1-omicron-theta-2336.cloudfunctions.net/pdnotify
  9. Hosting === Hosting Setup Your public directory is the folder

    (relative to your project directory) that will contain Hosting assets to be uploaded with firebase deploy. If you have a build process for your assets, use your build's output directory. ? What do you want to use as your public directory? public ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ✔ Wrote public/index.html i Writing configuration info to firebase.json...
  10. Getting Authenticated var provider = new firebase.auth.GoogleAuthProvider(); firebase.auth().getRedirectResult().then(function(result) { if

    (result.credential) { //User is authenticated var user = result.user; var token = result.credential.accessToken; } else { //User is unauthenticated firebase.auth().signInWithRedirect(provider); } }).catch(function(error) { // Oops });
  11. Hosting Deployment $ firebase deploy --only hosting === Deploying to

    'omicron-theta-2336'... i deploying hosting i hosting[omicron-theta-2336]: beginning deploy... i hosting[omicron-theta-2336]: found 1 files in public ✔ hosting[omicron-theta-2336]: file upload complete i hosting[omicron-theta-2336]: finalizing version... ✔ hosting[omicron-theta-2336]: version finalized i hosting[omicron-theta-2336]: releasing new version... ✔ hosting[omicron-theta-2336]: release complete ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/omicron-theta-2336/overview Hosting URL: https://omicron-theta-2336.firebaseapp.com
  12. Cloud Pub/Sub • Publish/Subscribe messaging service • At-least-once delivery •

    Seek & Replay - A subscription only sees from after it was created
  13. Topic & Subscription Creation $ gcloud pubsub topics create pd-notify

    $ gcloud pubsub subscriptions create --topic pd-notify pd-notify-model $ gcloud pubsub subscriptions create --topic pd-notify pd-notify-firestore
  14. Cloud Firestore • Serverless NoSQL document database • ACID transactions

    • Automatic scaling & indexing • Multi-region replication • Client libraries provide live and offline synchronization
  15. Fin