mirror of
https://github.com/fergalmoran/onearmy-community-platform.git
synced 2025-12-22 09:37:54 +00:00
chore: make logging good
This commit is contained in:
@@ -10,6 +10,5 @@ services:
|
|||||||
- 4001-4008:4001-4008
|
- 4001-4008:4001-4008
|
||||||
volumes:
|
volumes:
|
||||||
- ./functions:/app/functions
|
- ./functions:/app/functions
|
||||||
- ./functions/data/emulator/:/seed
|
- ./functions/data/emulator:/seed
|
||||||
|
- ./functions/logs:/app/logs
|
||||||
# - ./functions/logs/firestore-debug.log:/app/firestore-debug.log
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
# docker run -v ./functions/data/emulator:/seed -v ./functions:/app/functions -p 4001-4008:4001-4008 -it emulator
|
# docker run -v ./functions/data/emulator:/seed -v ./functions:/app/functions -p 4001-4008:4001-4008 -it emulator
|
||||||
#
|
#
|
||||||
# EXPORT (while the container is running)
|
# EXPORT (while the container is running)
|
||||||
# docker exec -it <conatiner_name> /app/easy-export.sh
|
# docker exec -it <conatiner_name> /app/export.js
|
||||||
# docker cp <conatiner_name>:/app/dump ./whatever
|
# docker cp <conatiner_name>:/app/dump ./whatever
|
||||||
#
|
#
|
||||||
# HOW TO DEBUG THE CONTAINER WHILE IT IS RUNNING:
|
# HOW TO DEBUG THE CONTAINER WHILE IT IS RUNNING:
|
||||||
@@ -71,12 +71,14 @@ RUN \
|
|||||||
firebase setup:emulators:storage && \
|
firebase setup:emulators:storage && \
|
||||||
firebase setup:emulators:pubsub
|
firebase setup:emulators:pubsub
|
||||||
|
|
||||||
COPY ./firebase.json ./firebase.json
|
COPY ./firebase.json ./firebase.json
|
||||||
COPY ./firebase.storage.rules ./firebase.storage.rules
|
COPY ./firebase.storage.rules ./firebase.storage.rules
|
||||||
COPY ./firestore.indexes.json ./firestore.indexes.json
|
COPY ./firestore.indexes.json ./firestore.indexes.json
|
||||||
COPY ./firestore.rules ./firestore.rules
|
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
|
# This folder needs to exist because otherwise
|
||||||
# the emulators error if the user did not mount
|
# 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
|
# These should be the ports specified in firebase.json
|
||||||
EXPOSE 4001 4002 4003 4004 4005 4006 4007 4008
|
EXPOSE 4001 4002 4003 4004 4005 4006 4007 4008
|
||||||
|
|
||||||
# Do firebase emulators:start --help for details
|
|
||||||
CMD \
|
CMD \
|
||||||
|
./link-logs.js & \
|
||||||
|
# Do firebase emulators:start --help for details
|
||||||
firebase emulators:start \
|
firebase emulators:start \
|
||||||
--project demo-community-platform-emulated \
|
--project demo-community-platform-emulated \
|
||||||
--only auth,functions,firestore,pubsub,storage,hosting,database \
|
--only auth,functions,firestore,pubsub,storage,hosting,database \
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
firebase \
|
|
||||||
emulators:export \
|
|
||||||
--project demo-community-platform-emulated \
|
|
||||||
--force ./dump
|
|
||||||
14
functions/emulator/export.js
Executable file
14
functions/emulator/export.js
Executable file
@@ -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}`)
|
||||||
|
})
|
||||||
43
functions/emulator/link-logs.js
Executable file
43
functions/emulator/link-logs.js
Executable file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
functions/logs/.gitignore
vendored
Normal file
1
functions/logs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.log
|
||||||
0
functions/logs/.gitkeep
Normal file
0
functions/logs/.gitkeep
Normal file
@@ -109,7 +109,7 @@ You can improve the seed data by making changes via the application or Firebase
|
|||||||
2. Run the export script:
|
2. Run the export script:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker exec -it <name> /app/easy-export.sh
|
docker exec -it <name> /app/export.js
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Transfer the data from the container to your machine:
|
3. Transfer the data from the container to your machine:
|
||||||
|
|||||||
Reference in New Issue
Block a user