Skip to content
/ find Public

Firebase IN Docker - test your firebase locally in containerised environment

License

Notifications You must be signed in to change notification settings

younver/find

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find

Firebase in Docker - run firebase locally in containerised environment for development and testing purposes.

Run

Default

docker run -it --rm -p 9000:9000 -p 9099:9099 -p 4000:4000 --name find ghcr.io/younver/find:main

With custom configurations

# Create database.rules.json
echo '{
  "rules": {
    ".read": false,
    ".write": false
  }
}' > database.rules.json
# Create firebase.json
echo '{
  "database": {
    "rules": "database.rules.json"
  },
  "emulators": {
    "database": {
      "host": "0.0.0.0",
      "port": 9000
    },
    "auth": {
      "host": "0.0.0.0",
      "port": 9099
    },
    "ui": {
      "enabled": true,
      "host": "0.0.0.0",
      "port": 4000
    }
  }
}
' > firebase.json
# Docker run find with firebase.json and database.rules.json
docker run -it --rm -p 9000:9000 -p 9099:9099 -p 4000:4000 -v ./firebase.json:/app/firebase.json -v ./database.rules.json:/app/database.rules.json --name find ghcr.io/younver/find:main

With Compose

services:
  ...
  firebase:
    image: "ghcr.io/younver/find:main"
    ports:
      - "9000:9000"
      - "9099:9099"
      - "4000:4000"
  ...

Usage

Python

from firebase_admin import initialize_app, db

app = initialize_app(options={"databaseURL": "http://localhost:9000?ns=find"})
db.reference("users").child("123").set(
    {"username": "ada.lovelace", "email": "[email protected]"}
)
print(db.reference("users").child("123").get())

Go

package main

import (
	"context"
	"log"

	firebase "firebase.google.com/go/v4"
)

const (
	FIREBASE_PROJECT_ID   = "find"
	FIREBASE_DATABASE_URL = "localhost:9000?ns=find"
)

func main() {
	ctx := context.Background()

	firebaseApp, err := firebase.NewApp(ctx, &firebase.Config{ProjectID: FIREBASE_PROJECT_ID, DatabaseURL: FIREBASE_DATABASE_URL})
	if err != nil {
		log.Fatalf("Error initializing firebase app: %v", err)
	}

	db, err := firebaseApp.Database(ctx)
	if err != nil {
		log.Fatalf("Error initializing firebase database client: %v", err)
	}

	user := map[string]interface{}{
		"username": "ada.lovelace",
		"email":    "[email protected]",
	}
	if err := db.NewRef("users").Child("123").Set(ctx, &user); err != nil {
		log.Fatalf("Error setting value: %v", err)
	}

	var dbUser map[string]interface{}
	if err := db.NewRef("users").Child("123").Get(ctx, &dbUser); err != nil {
		log.Fatalf("Error reading value: %v", err)
	}

	log.Printf("User: %v", dbUser)
}

Further configurations

To configure firebase emulators and rules, you can edit firebase.json and database.rules.json following the document about configuring and integrating firebase local emulator suite.

Roadmap

  • Authentication
  • Emulator Suite UI
  • Realtime Database
  • Cloud Firestore
  • Cloud Storage for Firebase
  • Cloud Functions

About

Firebase IN Docker - test your firebase locally in containerised environment

Resources

License

Stars

Watchers

Forks

Packages