Skip to content

Commit

Permalink
chore: fix docker emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaisdavid committed May 26, 2024
1 parent e8868e5 commit e658765
Show file tree
Hide file tree
Showing 78 changed files with 735 additions and 1,655 deletions.
53 changes: 46 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,62 @@ This project and everyone participating in it is governed by the [Code of Conduc

## 📟   Getting started

**Prerequisites**
### Prerequisites

- [Node.js v20](https://nodejs.org/en/download/)
- [Yarn v3](https://yarnpkg.com/getting-started/install)

With the above tools available, you are ready:
### One time setup

1. Fork the repository.

2. Clone the project from the fork you have created previously at first step :
`git clone https://github.com/`**your-github-user**`/community-platform.git`
2. Clone the project from the fork you have created previously at first step:

```
git clone https://github.com/<your-github-username>/community-platform.git
```

3. Install dependencies
`yarn`
```
yarn install
```

### Running the web app

There are two options.

#### Option 1

This option is simple but only starts the frontend. The backend services are hosted on the internet (https://precious-plastics-v4-dev.firebaseapp.com) and may be accessed by many developers.

This setup is:

- Good for starting
- Good for frontend development
- Bad for backend development

Simply run:

```
yarn run start
```

In this case:

- frontend: http://localhost:3000

#### Option 2

This option is slightly more complicated but allows you to run the frontend and backend system locally (except sending emails.)

This setup is:

- Good for frontend development
- Good for backend development

See the details at [here](https://docs.platform.onearmy.earth/Backend%20Development/firebase-emulator/).

4. Run the dev server
`yarn start`
### Learn more

More information is available in the [developer documentation](https://docs.platform.onearmy.earth/).

Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# TODO: update to a more new version
version: "2.1"
services:

emulator:
build:
context: ./
dockerfile: ./functions/Dockerfile.emulator
ports:
- 4001-4008:4001-4008
volumes:
- ./functions:/app/functions
- ./functions/data/emulator/:/app/seed
# TODO: make logs easily viewable on the host machine.
# - ./logs/ui-debug.log:/app/ui-debug.log
# - ./logs/firestore-debug.log:/app/firestore-debug.log
# - ./logs/database-debug.log:/app/database-debug.log
# - ./logs/pubsub-debug.log:/app/pubsub-debug.log
# - ./logs/firebase-debug.log:/app/firebase-debug.log
24 changes: 16 additions & 8 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,36 @@
"emulators": {
"ui": {
"enabled": true,
"port": 4001
"port": 4001,
"host": "0.0.0.0"
},
"functions": {
"port": 4002
"port": 4002,
"host": "0.0.0.0"
},
"firestore": {
"port": 4003
"port": 4003,
"host": "0.0.0.0"
},
"hosting": {
"port": 4004
"port": 4004,
"host": "0.0.0.0"
},
"auth": {
"port": 4005
"port": 4005,
"host": "0.0.0.0"
},
"database": {
"port": 4006
"port": 4006,
"host": "0.0.0.0"
},
"storage": {
"port": 4007
"port": 4007,
"host": "0.0.0.0"
},
"pubsub": {
"port": 4008
"port": 4008,
"host": "0.0.0.0"
}
},
"storage": {
Expand Down
1 change: 0 additions & 1 deletion functions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ lib/
dist

# Emulator data
data/emulated
data/exported
data/seed/*
!data/seed/.gitkeep
Expand Down
70 changes: 70 additions & 0 deletions functions/Dockerfile.emulator
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
####################################################################
#
# Due to complexities with Yarn workspaces, this Dockerfile
# does not create the `dist` folder. It should be mounted from
# the host machine to the container, using the `-v` flag.
#
# Optionally, initial data can be setup by mounting `/app/seed`.
#
# COMMANDS (used from the root directory of the project):
# docker build -f ./functions/Dockerfile.emulator -t emulator .
# docker run -v ./functions:/app/functions -p 4001-4008:4001-4008 -it emulator
#
# HOW TO DEBUG THE CONTAINER WHILE IT IS RUNNING:
# 1) Open a new terminal.
# 2) Run `docker ps` command.
# 3) Find the name for the container.
# 4) Run `docker exec -it <name> bash` command.
#
# TECHNICAL NOTES:
# Due to Docker, the Firebase emulators should run on 0.0.0.0
# https://stackoverflow.com/a/52518929
#
####################################################################

FROM node:20.9.0-bullseye-slim

ENV SHOULD_REGULARLY_EXPORT_DATA='false'

WORKDIR /app

RUN \
apt-get update && \
# For Firebase
# https://firebase.google.com/docs/emulator-suite/install_and_configure
apt-get -y install openjdk-11-jre-headless && \
# For debugging
apt-get -y install nano && \
apt-get clean

# TODO: someone else can figure out a good way to install the Firebase CLI.
RUN npm install -g firebase-tools

# Doing setup saves time when running the container.
# There are no setup commands for functions, hosting, or auth.
RUN \
firebase setup:emulators:ui && \
firebase setup:emulators:firestore && \
firebase setup:emulators:database && \
firebase setup:emulators:storage && \
firebase setup:emulators:pubsub

COPY ./../firebase.json /app/firebase.json
COPY ./../firebase.storage.rules /app/firebase.storage.rules
COPY ./../firestore.indexes.json /app/firestore.indexes.json
COPY ./../firestore.rules /app/firestore.rules

# Create script for easy exporting
RUN \
echo "#!/bin/bash\n" >> /app/export.sh && \
echo "firebase emulators:export --project demo-community-platform-emulated --force /app/dump\n" >> /app/export.sh && \
chmod +x /app/export.sh

# These should be the ports specified in firebase.json
EXPOSE 4001 4002 4003 4004 4005 4006 4007 4008

CMD \
firebase emulators:start \
--project demo-community-platform-emulated \
--only auth,functions,firestore,pubsub,storage,hosting,database \
--import=/app/seed
2 changes: 1 addition & 1 deletion functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This documentation likely requires updating, and the information provided may no longer be fully valid. Please feel free to create a new issue for any specific items identified as conflict/confusing or possibly no longer valid.

Some additional, newer information can also be found in [Firebase Emulators Docs](../packages/documentation/docs/Backend%20Development/firebase-emulators.md)
Some additional, newer information can also be found in [Firebase Emulators Docs](../packages/documentation/docs/Backend%20Development/firebase-emulator.md)

---

Expand Down
Empty file removed functions/data/emulated/.gitkeep
Empty file.
72 changes: 72 additions & 0 deletions functions/data/emulator/auth_export/accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"kind": "identitytoolkit#DownloadAccountResponse",
"users": [
{
"localId": "2djSop7XvY0NEg7QY5rZrm0Wc2N1",
"createdAt": "1716744480141",
"lastLoginAt": "1716746234545",
"displayName": "admin",
"passwordHash": "fakeHash:salt=fakeSaltRpTXy52dXY1DgyPT6odF:password=wow_backend_development_is_fun",
"salt": "fakeSaltRpTXy52dXY1DgyPT6odF",
"passwordUpdatedAt": 1716744766896,
"providerUserInfo": [
{
"providerId": "password",
"email": "admin@example.com",
"federatedId": "admin@example.com",
"rawId": "admin@example.com",
"displayName": "admin"
}
],
"validSince": "1716744766",
"email": "admin@example.com",
"emailVerified": false,
"disabled": false,
"lastRefreshAt": "2024-05-26T17:57:14.545Z"
},
{
"localId": "WrCrfu7FS3vJcFswZr1yufwlPtCl",
"lastLoginAt": "1716745935132",
"emailVerified": false,
"email": "precious-plastic@example.com",
"salt": "fakeSalt5z1E4omMRGeny2KD9xUb",
"passwordHash": "fakeHash:salt=fakeSalt5z1E4omMRGeny2KD9xUb:password=precious-plastic",
"passwordUpdatedAt": 1716745327556,
"validSince": "1716745327",
"createdAt": "1716745327556",
"providerUserInfo": [
{
"providerId": "password",
"email": "precious-plastic@example.com",
"federatedId": "precious-plastic@example.com",
"rawId": "precious-plastic@example.com",
"displayName": "precious-plastic"
}
],
"lastRefreshAt": "2024-05-26T17:52:15.132Z",
"displayName": "precious-plastic"
},
{
"localId": "uf0mBGfLKGQwoJ1FWiqH0xQSatKM",
"lastLoginAt": "1716746297841",
"emailVerified": false,
"email": "normal_jim@example.com",
"salt": "fakeSalt88tfIY4E8ASJgTGvE3th",
"passwordHash": "fakeHash:salt=fakeSalt88tfIY4E8ASJgTGvE3th:password=thanks_emulator_man",
"passwordUpdatedAt": 1716746026812,
"validSince": "1716746026",
"createdAt": "1716746026812",
"providerUserInfo": [
{
"providerId": "password",
"email": "normal_jim@example.com",
"federatedId": "normal_jim@example.com",
"rawId": "normal_jim@example.com",
"displayName": "normal_jim"
}
],
"lastRefreshAt": "2024-05-26T17:58:17.841Z",
"displayName": "normal_jim"
}
]
}
4 changes: 4 additions & 0 deletions functions/data/emulator/auth_export/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"signIn": { "allowDuplicateEmails": false },
"emailPrivacyConfig": { "enableImprovedEmailPrivacy": false }
}
20 changes: 20 additions & 0 deletions functions/data/emulator/firebase-export-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "13.10.1",
"firestore": {
"version": "1.19.6",
"path": "firestore_export",
"metadata_file": "firestore_export/firestore_export.overall_export_metadata"
},
"database": {
"version": "4.11.2",
"path": "database_export"
},
"auth": {
"version": "13.10.1",
"path": "auth_export"
},
"storage": {
"version": "13.10.1",
"path": "storage_export"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions functions/data/emulator/storage_export/buckets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"buckets": [
{
"id": "demo-community-platform-emulated.appspot.com"
},
{
"id": "default-bucket"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uploads/howtos/sSJu2x5kxs6piq2L0U6y/shredder-5-18fb5fb1d5f.jpg",
"bucket": "default-bucket",
"metageneration": 1,
"generation": 1716745089801,
"contentType": "image/jpeg",
"storageClass": "STANDARD",
"contentDisposition": "inline",
"downloadTokens": ["10d20f04-0b90-4c8b-9b7e-c50c87bc0714"],
"etag": "Nqnyu2+k4zpFsVWiaL5TPKwrBug",
"customMetadata": {},
"timeCreated": "2024-05-26T17:38:09.801Z",
"updated": "2024-05-26T17:38:09.801Z",
"size": 60814,
"md5Hash": "VmzZq8sK2od3snVOMkN8fw==",
"crc32c": "3186773085"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uploads/users/precious-plastic/5e0701c9be0f82741b72d8b2_Version-4-team-18ee73f92fa-18fb600cf66.jpg",
"bucket": "default-bucket",
"metageneration": 1,
"generation": 1716745458997,
"contentType": "image/jpeg",
"storageClass": "STANDARD",
"contentDisposition": "inline",
"downloadTokens": ["f2bb53ba-4797-4b87-a77f-f9b8c63568ab"],
"etag": "cr6McE2FKWCJWvEYkPz1OIQ6KyE",
"customMetadata": {},
"timeCreated": "2024-05-26T17:44:18.997Z",
"updated": "2024-05-26T17:44:18.997Z",
"size": 494337,
"md5Hash": "BH2ssfCv5sFxvwv68s9qKQ==",
"crc32c": "3221583768"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uploads/howtos/sSJu2x5kxs6piq2L0U6y/shredder-2-18391b3997d-18fb5fa4b14.jpg",
"bucket": "default-bucket",
"metageneration": 1,
"generation": 1716745089742,
"contentType": "image/jpeg",
"storageClass": "STANDARD",
"contentDisposition": "inline",
"downloadTokens": ["0180dc00-c762-498f-8353-d379d591554f"],
"etag": "KjajQC8dFUsg0dzLFUPkJ/wJGI0",
"customMetadata": {},
"timeCreated": "2024-05-26T17:38:09.742Z",
"updated": "2024-05-26T17:38:09.742Z",
"size": 54654,
"md5Hash": "VVJqkJWfPH+7DH6rUj3fBA==",
"crc32c": "1100890625"
}
Loading

0 comments on commit e658765

Please sign in to comment.