Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Add firebase integration #13954

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ jobs:
'create-remix-app-express-legacy',
'create-remix-app-express-vite-dev',
'default-browser',
'firebase',
'node-express-esm-loader',
'node-express-esm-preload',
'node-express-esm-without-loader',
Expand Down
58 changes: 58 additions & 0 deletions dev-packages/e2e-tests/test-applications/firebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

test-results
2 changes: 2 additions & 0 deletions dev-packages/e2e-tests/test-applications/firebase/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
64 changes: 64 additions & 0 deletions dev-packages/e2e-tests/test-applications/firebase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Assuming you already have installed docker desktop or orbstack etc. or any other docker software

### Enabling / authorising firebase emulator through docker

1. Run the docker

```bash
pnpm docker
```

2. In new tab, enter the docker container by simply running

```bash
docker exec -it sentry-firebase bash
```

3. Now inside docker container run

```bash
firebase login
```

4. You should now see a long link to authenticate with google account, copy the link and open it using your browser
5. Choose the account you want to authenticate with
6. Once you do this you should be able to see something like "Firebase CLI Login Successful"
7. And inside docker container you should see something like "Success! Logged in as <here is the email you have chosen>"
8. Now you can exit docker container

```bash
exit
```

9. Switch back to previous tab, stop the docker container (ctrl+c).
10. You should now be able to run the test, as you have correctly authenticated the firebase emulator

### Preparing data for CLI

1. Please authorize the docker first - see the previous section
2. Once you do that you can generate .env file locally, to do that just run

```bash
npm run createEnvFromConfig
```

3. It will create a new file called ".env" inside folder "docker"
4. View the file. There will be 2 params CONFIG_FIREBASE_TOOLS and CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS.
5. Now inside the CLI create a new variable under the name CONFIG_FIREBASE_TOOLS and
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS - take values from mentioned .env file
6. File .env is ignored to avoid situation when developer after authorizing firebase with private account will
accidently push the tokens to github.
7. But if we want the users to still have some default to be used for authorisation (on their local development) it will
be enough to commit this file, we just have to authorize it with some "special" account.

**Some explanation towards environment settings, the environment variable defined directly in "environments" takes
precedence over .env file, that means it will be safe to define it in CLI and still keeps the .env file.**

### Scripts - helpers

- createEnvFromConfig - it will use the firebase docker authentication and create .env file which will be used then by
docker whenever you run emulator
- createConfigFromEnv - it will use '.env' file in docker folder to create .config for the firebase to be used to
authenticate whenever you run docker, Docker by default loads .env file itself

Use these scripts when testing and updating the environment settings on CLI
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');
const dotent = require('dotenv');
dotent.config({ path: path.resolve(__dirname, './docker/.env') });

const createConfigFromEnv = require('./docker/firebase/utils').createConfigFromEnv;

// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
try {
await createConfigFromEnv();
} catch (e) {
console.error(e);
}
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const createEnvFromConfig = require('./docker/firebase/utils').createEnvFromConfig;

(async () => {
try {
await createEnvFromConfig();
} catch (e) {
console.error(e);
}
})();

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.config
cache
firebase/data
firebase/firebase-export-*
*-debug.log
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-alpine

ARG FIREBASE_VERSION

RUN apk --no-cache add openjdk11-jre bash curl openssl gettext nano nginx sudo && \
npm cache clean --force && \
npm i -g firebase-tools@$FIREBASE_VERSION

COPY nginx.conf /etc/nginx/
COPY serve.sh /usr/bin/
RUN chmod +x /usr/bin/serve.sh

WORKDIR /srv/firebase

ENTRYPOINT ["/usr/bin/serve.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
services:
emulator:
container_name: sentry-firebase
build:
context: .
dockerfile: Dockerfile
args:
- FIREBASE_VERSION=13.19.0
stop_grace_period: 1m
environment:
FIREBASE_AUTH_EMULATOR_HOST: "localhost:5507"
FIRESTORE_EMULATOR_HOST: "localhost:5504"
PUBSUB_EMULATOR_HOST: "localhost:5505"
FUNCTIONS_EMULATOR_HOST: "localhost:5503"
FIREBASE_PROJECT: "sentry-15d85"
GCLOUD_PROJECT: "sentry-15d85"
FORCE_COLOR: "true"
DATA_DIRECTORY: "data"
CHOKIDAR_USEPOLLING: "true"
CONFIG_FIREBASE_TOOLS: ${CONFIG_FIREBASE_TOOLS}
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS: ${CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS}
ports:
- "5500:4001" # ui
- "5501:4401" # hub
- "5502:4601" # logging
- "5503:5002" # functions
- "5504:8081" # firestore
- "5505:8086" # pubsub
- "5506:9001" # database
- "5507:9100" # auth
- "5508:9200" # Storage
- "5509:6001" # Hosting
- '5510:9081' # firestore (grpc)
- '5511:9230' # cloud_functions_debug
- '9005:9005' # to be able to authenticate using gmail and docker
volumes:
- type: bind
source: ./firebase
target: /srv/firebase
bind:
create_host_path: true
- type: bind
source: ./cache
target: /root/.cache
bind:
create_host_path: true
- type: bind
source: .config
target: /root/.config
bind:
create_host_path: true
- type: bind
source: ./firebase/data
target: /srv/firebase/data
bind:
create_host_path: true

networks:
default:
driver: bridge
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "sentry-project-436908"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# dataconnect generated files
.dataconnect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const createOrUpdateConfigIfPossible = require('./utils').createOrUpdateConfigIfPossible;

createOrUpdateConfigIfPossible();
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
"rules": {
".read": false,
".write": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"emulators": {
"auth": {
"port": 5507
},
"firestore": {
"port": 5504
},
"database": {
"port": 5506
},
"ui": {
"enabled": true,
"port": 5500
},
"singleProjectMode": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{file=**} {
allow read, write: if true;
}
}
}
Loading
Loading