diff --git a/docker-compose.yml b/docker-compose.yml index 2129cb5f8..db8caa6b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,5 @@ services: - 4001-4008:4001-4008 volumes: - ./functions:/app/functions - - ./functions/data/emulator/:/seed - - # - ./functions/logs/firestore-debug.log:/app/firestore-debug.log \ No newline at end of file + - ./functions/data/emulator:/seed + - ./functions/logs:/app/logs \ No newline at end of file diff --git a/functions/emulator/Dockerfile b/functions/emulator/Dockerfile index b50f593dd..0f6c1b41c 100644 --- a/functions/emulator/Dockerfile +++ b/functions/emulator/Dockerfile @@ -20,7 +20,7 @@ # docker run -v ./functions/data/emulator:/seed -v ./functions:/app/functions -p 4001-4008:4001-4008 -it emulator # # EXPORT (while the container is running) -# docker exec -it /app/easy-export.sh +# docker exec -it /app/export.js # docker cp :/app/dump ./whatever # # HOW TO DEBUG THE CONTAINER WHILE IT IS RUNNING: @@ -71,12 +71,14 @@ RUN \ firebase setup:emulators:storage && \ firebase setup:emulators:pubsub -COPY ./firebase.json ./firebase.json -COPY ./firebase.storage.rules ./firebase.storage.rules -COPY ./firestore.indexes.json ./firestore.indexes.json -COPY ./firestore.rules ./firestore.rules +COPY ./firebase.json ./firebase.json +COPY ./firebase.storage.rules ./firebase.storage.rules +COPY ./firestore.indexes.json ./firestore.indexes.json +COPY ./firestore.rules ./firestore.rules -COPY ./functions/emulator/easy-export.sh ./easy-export.sh +COPY ./functions/emulator/export.js ./export.js + +COPY ./functions/emulator/link-logs.js ./link-logs.js # This folder needs to exist because otherwise # the emulators error if the user did not mount @@ -86,8 +88,9 @@ RUN mkdir /seed # These should be the ports specified in firebase.json EXPOSE 4001 4002 4003 4004 4005 4006 4007 4008 -# Do firebase emulators:start --help for details CMD \ + ./link-logs.js & \ + # Do firebase emulators:start --help for details firebase emulators:start \ --project demo-community-platform-emulated \ --only auth,functions,firestore,pubsub,storage,hosting,database \ diff --git a/functions/emulator/easy-export.sh b/functions/emulator/easy-export.sh deleted file mode 100755 index 688109f2c..000000000 --- a/functions/emulator/easy-export.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -firebase \ - emulators:export \ - --project demo-community-platform-emulated \ - --force ./dump \ No newline at end of file diff --git a/functions/emulator/export.js b/functions/emulator/export.js new file mode 100755 index 000000000..78e3dc61d --- /dev/null +++ b/functions/emulator/export.js @@ -0,0 +1,14 @@ +#!/usr/bin/env node + +const { exec } = require('child_process') + +const command = 'firebase emulators:export --project demo-community-platform-emulated --force ./dump' + +exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`) + return + } + console.log(`stdout: ${stdout}`) + console.error(`stderr: ${stderr}`) +}) diff --git a/functions/emulator/link-logs.js b/functions/emulator/link-logs.js new file mode 100755 index 000000000..c0235c630 --- /dev/null +++ b/functions/emulator/link-logs.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +// Continuously copy the log files into a common folder +// making it easier to export them. +// +// This script knows the folder structure of the container. +// +// Symbolic links did not work. + +const fs = require('fs') + +const isDebug = false + +log('setup...') + +const files = [ + 'database-debug.log', + 'firebase-debug.log', + 'firestore-debug.log', + 'pubsub-debug.log', + 'ui-debug.log' +] + +// clear the files so the they are also cleared on the host. +files.forEach((filename) => { + fs.writeFileSync('/app/' + filename, '') +}) + +fs.watch('/app', {}, (event, filename) => { + log('event: ' + event) + log('filename: ' + filename) + + if (files.includes(filename)) { + log('updating... ' + filename) + fs.copyFileSync('/app/' + filename, '/app/logs/' + filename) + } +}) + +function log(statement) { + if (isDebug) { + console.log('[LINK-LOGS] ' + statement) + } +} \ No newline at end of file diff --git a/functions/logs/.gitignore b/functions/logs/.gitignore new file mode 100644 index 000000000..bf0824e59 --- /dev/null +++ b/functions/logs/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/functions/logs/.gitkeep b/functions/logs/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/documentation/docs/Backend Development/firebase-emulator.md b/packages/documentation/docs/Backend Development/firebase-emulator.md index e66912c13..2a8b080fb 100644 --- a/packages/documentation/docs/Backend Development/firebase-emulator.md +++ b/packages/documentation/docs/Backend Development/firebase-emulator.md @@ -109,7 +109,7 @@ You can improve the seed data by making changes via the application or Firebase 2. Run the export script: ``` -docker exec -it /app/easy-export.sh +docker exec -it /app/export.js ``` 3. Transfer the data from the container to your machine: