fix: add functions build wait for docker emulator

This commit is contained in:
Chris
2022-04-28 21:36:53 +01:00
parent 1b0c5152db
commit 76e8a16102
2 changed files with 19 additions and 2 deletions

View File

@@ -44,7 +44,9 @@ Note - any data populated into the emulator will be deleted after the emulator h
## Resetting seed data
When the emulator is stopped the image is destroyed, so each time the emulators are restarted a clean set of data will be available
When the emulator is stopped the image is destroyed, so each time the emulators are restarted a clean set of data will be available.
If using the frontend data changes may still persist due to the browser's own caching mechanisms. In this case the browser indexeddb cache will need to be manually cleared
## Frontend

View File

@@ -1,6 +1,7 @@
import Dockerode from 'dockerode'
import boxen from 'boxen'
import logUpdate from 'log-update'
import fs from 'fs-extra'
import {
CONTAINER_NAME,
getFirebasePortMapping,
@@ -95,11 +96,18 @@ function attachContainer(container: Dockerode.Container) {
}
async function createNewContainer() {
// ensure functions dist exists for binding
if (!fs.existsSync(PATHS.functionsDistIndex)) {
console.log('Waiting for functions to be built...')
await _wait(5000)
return createNewContainer()
}
// pull remote image if required
if (REPOSITORY) {
await pullRemoteImage(IMAGE_NAME)
}
const { ExposedPorts, PortBindings } = rewritePortMapping()
return new Promise<Dockerode.Container>((resolve, reject) => {
return new Promise<Dockerode.Container>(async (resolve, reject) => {
docker.createContainer(
{
// Image: 'goatlab/firebase-emulator:latest',
@@ -237,4 +245,11 @@ function execContainerCmd(container: Dockerode.Container, Cmd: string[]) {
)
}
/** Wait an aribitrary number of milliseconds before continuing */
async function _wait(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
start()