Skip to content

Commit

Permalink
Add Firebase emulator docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Feb 27, 2021
1 parent b0fb6d6 commit a00f125
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 20 deletions.
13 changes: 13 additions & 0 deletions src/api/config/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"emulators": {
"ui": {
"enabled": true,
"host": "0.0.0.0",
"port": 4000
},
"firestore": {
"port": "8088",
"host": "0.0.0.0"
}
}
}
39 changes: 39 additions & 0 deletions src/api/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
################################################################################
# Development containers only to support local development, testing, and CI.
#
# This docker-compose file is meant to be used with src/api/docker-compose.yml
# as a base specification:
#
# $ docker-compose -f docker-compose.yml -f development.yml up -d
#
# See https://docs.docker.com/compose/production/
################################################################################
version: '3'

services:
# Firebase Emulator for offline testing
firebase:
container_name: 'firebase'
image: andreysenov/firebase-tools
volumes:
# Copy firebase.config into the container so we get proper ip/port binding
- ./config/firebase.json:/home/node/firebase.json
command: firebase emulators:start --project telescope --only firestore
ports:
# Emulator Suite UI
- '4000'
# Cloud Firestore
- '8088:8088'
depends_on:
- traefik
labels:
# Enable Traefik on the firebase container
- 'traefik.enable=true'
# Traefik routing for the firebase UI at http://ui.firebase.localhost
- 'traefik.http.routers.firebase_ui.rule=Host(`ui.firebase.localhost`)'
- 'traefik.http.routers.firebase_ui.service=firebase_ui'
- 'traefik.http.services.firebase_ui.loadbalancer.server.port=4000'
# Traefik routing for the Firebase Firestore at http://firestore.firebase.localhost
- 'traefik.http.routers.firebase_firestore.rule=Host(`firestore.firebase.localhost`)'
- 'traefik.http.routers.firebase_firestore.service=firebase_firestore'
- 'traefik.http.services.firebase_firestore.loadbalancer.server.port=8088'
10 changes: 8 additions & 2 deletions src/api/env.development
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
################################################################################
# Environment Variables for Development
#
# Copy this file to `.env` for use by docker-compose.
################################################################################

COMPOSE_PROJECT_NAME=telescope_api

# Compose files to use together on production. NOTE: we specify separator below
# so it will work on Windows and Unix, see
# https://docs.docker.com/compose/reference/envvars/#compose_file
COMPOSE_PATH_SEPARATOR=;
COMPOSE_FILE=docker-compose.yml;development.yml

# The host where all the microservices run (e.g., http://api.telescope.localhost)
API_HOST=api.telescope.localhost

Expand Down
44 changes: 26 additions & 18 deletions src/api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,54 @@
There are a number of [docker-compose](https://docs.docker.com/compose/) files available for running Telescope's services, including:

- [docker-compose.yml](docker-compose.yml) - the base docker-compose stack
definition of our microservices, dependent services, and our api gateway, [Traefik](https://traefik.io). This is meant to be used in development only.
definition of our microservices and our api gateway, [Traefik](https://traefik.io).
- [development.yml](development.yml) - dependent services needed for development, testing, and CI. This is meant to be used in development only.
- [production.yml](production.yml) - overrides and extensions to the base docker-compose
stack, with extra settings and services necessary for running in staging and production.

In conjunction with these, there are also multiple environment files, including:

- [env.development](env.development) - environment variables for local development. This
is likely what you need to adjust or pay attention to if you're developing Telescope.
- [env.development](env.development) - environment variables for local development.
- [env.staging](env.staging) - environment variables for our staging server.
- [env.production](env.production) - environment variables for our production server.

To use these files, you first need to pick a deployment type (e.g., development, staging, or production), and copy the appropriate environment file to `src/api/.env`. For example,
Telescope developers would do:
## Running the Services via docker-compose

Run the services from the root directory:

```
$ cp env.development .env
npm run services:start
```

Or the equivalent command to copy the file on their operating system.
This will (re)build all the services, pull any images that are necessary for dependent services, and start all the services
together. You can then access the services via the api hostname (see `API_HOST` in your .env file). For example:

## Running the Services via docker-compose
http://api.telescope.localhost/v1/image/gallery

Run the services via [docker-compose](https://docs.docker.com/compose/), which will use your `.env` to decide how
to pick which docker-compose files to run:
You can access logs for one or more services:

```
cd src/api
docker-compose up --build
npm run services:logs image firebase
```

This will (re)build all the services, pull any images that are necessary for dependent services, and start all the services
together. You can then access the services via the api hostname (see `API_HOST` in your .env file). For example:
To stop the services:

http://api.telescope.localhost/v1/image/gallery
```
npm run services:stop
```

## API Lookup Table

| API | Docker Tag | URL | Description |
| ------------- | ----------------- | --------- | ------------------------------------------- |
| Image Service | telescope_img_svc | /v1/image | Provides a dynamic image processing service |
| API | Docker Tag | URL | Description |
| ----- | ----------------- | --------- | ------------------------------------------- |
| image | telescope_img_svc | /v1/image | Provides a dynamic image processing service |

## Support Services Lookup Table (development only)

| API | URL | Description |
| ------------------ | ----------------------------------- | --------------------------------- |
| Firebase UI | http://ui.firebase.localhost | UI Dashboard to Firebase Emulator |
| Firebase Firestore | http://firestore.firebase.localhost | Firestore Emulator Service |

## References

Expand Down

0 comments on commit a00f125

Please sign in to comment.