GithubHelp home page GithubHelp logo

isabella232 / gcp-firestore-emulator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alma/gcp-firestore-emulator

0.0 0.0 0.0 4 KB

Run GCP Firestore emulator in a Docker container for development and testing purposes

License: MIT License

Dockerfile 87.16% Shell 12.84%

gcp-firestore-emulator's Introduction

gcp-firestore-emulator

Run GCP Firestore emulator in a Docker container for development and testing purposes

Usage

Retrieve the latest version of the Docker image:

$ docker pull "getalma/gcp-firestore-emulator:latest"

Run the Docker container, by making it reachable through port 8086:

$ docker run \
	--rm --tty --interactive \
	--publish "8086:8086" \
	--name "firestore_emulator" \
	"getalma/gcp-firestore-emulator:latest"

or using docker-compose:

$ cat docker-compose.yml
version: "3"

services:
  firestore-emulator:
    image: getalma/gcp-firestore-emulator:latest

  some-service:
    image: python:3.8
    environment:
      - FIRESTORE_EMULATOR_HOST=firestore-emulator:8086
    depends_on:
      - firestore-emulator
    entrypoint:
      - /bin/bash

$ docker-compose up "some-service"
Creating firestore-emulator_1 ... done
Creating some-service_1 ... done
Attaching to some-service_1
...

You can, now, use the emulator to develop and test your application.

Run an application against the emulator

First install the Google Cloud Firestore client library (in a virtualenv on inside a Docker container):

$ pip install --upgrade firebase-admin

Then, set the environment variable that will allow your code to run on the emulator, instead of trying to connect to Google Cloud Firestore:

export FIRESTORE_EMULATOR_HOST=localhost:8086

After this, you can use the client library to ...

from unittest import mock
from google.cloud import firestore
import google.auth.credentials

credentials = mock.Mock(spec=google.auth.credentials.Credentials)
db = firestore.Client(project="test", credentials=credentials)

user_ref = db.collection("users").document("22")

user_ref.set({"name": "John Doe", "age": 37}) 

print(user_ref.get().to_dict())

assert user_ref.get().to_dict() == {"name": "John Doe", "age": 37}

gcp-firestore-emulator's People

Contributors

hyahiaoui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.