Skip to content

Commit 0020182

Browse files
committed
feat(node): Add firebase integration
1 parent 40f04bc commit 0020182

36 files changed

+1461
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
57+
58+
test-results
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Assuming you already have installed docker desktop or orbstack etc. or any other docker software
2+
3+
### Enabling / authorising firebase emulator through docker
4+
5+
1. Run the docker
6+
7+
```bash
8+
pnpm docker
9+
```
10+
11+
2. In new tab, enter the docker container by simply running
12+
13+
```bash
14+
docker exec -it sentry-firebase bash
15+
```
16+
17+
3. Now inside docker container run
18+
19+
```bash
20+
firebase login
21+
```
22+
23+
4. You should now see a long link to authenticate with google account, copy the link and open it using your browser
24+
5. Choose the account you want to authenticate with
25+
6. Once you do this you should be able to see something like "Firebase CLI Login Successful"
26+
7. And inside docker container you should see something like "Success! Logged in as <here is the email you have chosen>"
27+
8. Now you can exit docker container
28+
29+
```bash
30+
exit
31+
```
32+
33+
9. Switch back to previous tab, stop the docker container (ctrl+c).
34+
10. You should now be able to run the test, as you have correctly authenticated the firebase emulator
35+
36+
### Preparing data for CLI
37+
38+
1. Please authorize the docker first - see the previous section
39+
2. Once you do that you can generate .env file locally, to do that just run
40+
41+
```bash
42+
npm run createEnvFromConfig
43+
```
44+
45+
3. It will create a new file called ".env" inside folder "docker"
46+
4. View the file. There will be 2 params CONFIG_FIREBASE_TOOLS and CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS.
47+
5. Now inside the CLI create a new variable under the name CONFIG_FIREBASE_TOOLS and
48+
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS - take values from mentioned .env file
49+
6. File .env is ignored to avoid situation when developer after authorizing firebase with private account will
50+
accidently push the tokens to github.
51+
7. But if we want the users to still have some default to be used for authorisation (on their local development) it will
52+
be enough to commit this file, we just have to authorize it with some "special" account.
53+
54+
**Some explanation towards environment settings, the environment variable defined directly in "environments" takes
55+
precedence over .env file, that means it will be safe to define it in CLI and still keeps the .env file.**
56+
57+
### Scripts - helpers
58+
59+
- createEnvFromConfig - it will use the firebase docker authentication and create .env file which will be used then by
60+
docker whenever you run emulator
61+
- createConfigFromEnv - it will use '.env' file in docker folder to create .config for the firebase to be used to
62+
authenticate whenever you run docker, Docker by default loads .env file itself
63+
64+
Use these scripts when testing and updating the environment settings on CLI
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path');
2+
const dotent = require('dotenv');
3+
dotent.config({ path: path.resolve(__dirname, './docker/.env') });
4+
5+
const createConfigFromEnv = require('./docker/firebase/utils').createConfigFromEnv;
6+
7+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
8+
(async () => {
9+
try {
10+
await createConfigFromEnv();
11+
} catch (e) {
12+
console.error(e);
13+
}
14+
})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const createEnvFromConfig = require('./docker/firebase/utils').createEnvFromConfig;
2+
3+
(async () => {
4+
try {
5+
await createEnvFromConfig();
6+
} catch (e) {
7+
console.error(e);
8+
}
9+
})();
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.config
2+
cache
3+
firebase/data
4+
firebase/firebase-export-*
5+
*-debug.log
6+
.env
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:20-alpine
2+
3+
ARG FIREBASE_VERSION
4+
5+
RUN apk --no-cache add openjdk11-jre bash curl openssl gettext nano nginx sudo && \
6+
npm cache clean --force && \
7+
npm i -g firebase-tools@$FIREBASE_VERSION
8+
9+
COPY nginx.conf /etc/nginx/
10+
COPY serve.sh /usr/bin/
11+
RUN chmod +x /usr/bin/serve.sh
12+
13+
WORKDIR /srv/firebase
14+
15+
ENTRYPOINT ["/usr/bin/serve.sh"]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
services:
2+
emulator:
3+
container_name: sentry-firebase
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
args:
8+
- FIREBASE_VERSION=13.19.0
9+
stop_grace_period: 1m
10+
environment:
11+
FIREBASE_AUTH_EMULATOR_HOST: 'localhost:5507'
12+
FIRESTORE_EMULATOR_HOST: 'localhost:5504'
13+
PUBSUB_EMULATOR_HOST: 'localhost:5505'
14+
FUNCTIONS_EMULATOR_HOST: 'localhost:5503'
15+
FIREBASE_PROJECT: 'sentry-15d85'
16+
GCLOUD_PROJECT: 'sentry-15d85'
17+
FORCE_COLOR: 'true'
18+
DATA_DIRECTORY: 'data'
19+
CHOKIDAR_USEPOLLING: 'true'
20+
CONFIG_FIREBASE_TOOLS: ${CONFIG_FIREBASE_TOOLS}
21+
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS: ${CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS}
22+
ports:
23+
- '5500:4001' # ui
24+
- '5501:4401' # hub
25+
- '5502:4601' # logging
26+
- '5503:5002' # functions
27+
- '5504:8081' # firestore
28+
- '5505:8086' # pubsub
29+
- '5506:9001' # database
30+
- '5507:9100' # auth
31+
- '5508:9200' # Storage
32+
- '5509:6001' # Hosting
33+
- '5510:9081' # firestore (grpc)
34+
- '5511:9230' # cloud_functions_debug
35+
- '9005:9005' # to be able to authenticate using gmail and docker
36+
volumes:
37+
- type: bind
38+
source: ./firebase
39+
target: /srv/firebase
40+
bind:
41+
create_host_path: true
42+
- type: bind
43+
source: ./cache
44+
target: /root/.cache
45+
bind:
46+
create_host_path: true
47+
- type: bind
48+
source: .config
49+
target: /root/.config
50+
bind:
51+
create_host_path: true
52+
- type: bind
53+
source: ./firebase/data
54+
target: /srv/firebase/data
55+
bind:
56+
create_host_path: true
57+
58+
networks:
59+
default:
60+
driver: bridge
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "sentry-project-436908"
4+
}
5+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
68+
# dataconnect generated files
69+
.dataconnect

0 commit comments

Comments
 (0)