Skip to content

Commit

Permalink
Feature Docker Container (#145)
Browse files Browse the repository at this point in the history
# *Feature Docker*

## ♻️ Current situation & Problem
Currently, setting up Firebase emulators requires manual installation
and platform-specific scripts, which can cause issues, especially on
Windows. This complicates the development process across different
environments.


## ⚙️ Release Notes 

- Added a Docker setup for Firebase emulators with a `Dockerfile` and
`docker-compose.yml` for easier cross-platform usage, especially on
Windows.
- Updated `README.md` with instructions on using Docker for emulators.
- Modified `serve:seeded` script in `functions/package.json` to handle
execution inside Docker containers.


![image](https://github.com/user-attachments/assets/2dcf33d9-fdce-4b7b-9c61-5320d3bcc078)


![image](https://github.com/user-attachments/assets/93cec4d6-31df-4a15-a2c6-2ddb3187eb3c)



### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Basler182 authored Sep 27, 2024
1 parent 8bd8b0a commit 430235f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:22-bullseye-slim

RUN apt update -y && apt install -y openjdk-11-jdk bash curl

RUN npm install -g firebase-tools

COPY . .

RUN npm run prepare

EXPOSE 5001 9099 8080 9199 4000

ENV IN_DOCKER_CONTAINER=true

ENTRYPOINT ["/bin/bash", "-c", "npm run serve:seeded && sleep infinity"]
5 changes: 5 additions & 0 deletions Dockerfile.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project

SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,14 @@ To make this structure simpler to use, we provide different scripts as part of t

For using the emulators for client applications, it is probably easiest to call `npm run prepare` whenever files could have changed (e.g. when changing branch or pulling new changes) and then calling `npm run serve:seeded` to start up the emulators in a seeded state. Both of these commands are performed in the root directory of this repository.

Otherwise, you may want to use Docker to run the emulators. For this, you can use the following command:

```bash
docker-compose up
```

This can be especially useful if you're using an operating system like Windows, as scripts contain OS-specific commands that may not work the same way across different platforms.

# Resources

- See [resources/algorithms](resources/algorithms) for diagrams describing the different algorithms for medication recommendations.
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
firebase:
container_name: firebase-emulator
build:
context: .
ports:
- 8080:8080 # **FIRESTORE_PORT**
- 5001:5001 # **FUNCTIONS_PORT**
- 9099:9099 # **AUTH_PORT**
- 9199:9199 # **STORAGE_PORT**
- 4000:4000 # **HOSTING_PORT**
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080" ]
interval: 30s
timeout: 10s
retries: 3
logging: # Log rotation configuration
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
5 changes: 5 additions & 0 deletions docker-compose.yml.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project

SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"serve:watch": "npm run build -- --watch | npm run serve",
"serve:seed": "curl -s -X PUT localhost:4400/functions/disableBackgroundTriggers 1>/dev/null && npm run serve:seed:withoutDisablingTriggers && curl -s -X PUT localhost:4400/functions/enableBackgroundTriggers 1>/dev/null",
"serve:seed:withoutDisablingTriggers": "curl --location \"http://localhost:5001/stanford-bdhg-engage-hf/us-central1/defaultSeed\" --header \"Content-Type: application/json\" --data \"{\\\"staticData\\\": {}}\"",
"serve:seeded": "firebase emulators:exec --only auth,firestore,functions,storage --ui \"npm run serve:seed && read -rd \\\"\\\"\"",
"serve:seeded": "firebase emulators:exec --only auth,firestore,functions,storage --ui \"npm run serve:seed && if [ -z $IN_DOCKER_CONTAINER ]; then read -rd \\\"\\\"; else sleep infinity; fi\"",
"shell": "firebase functions:shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
Expand Down

0 comments on commit 430235f

Please sign in to comment.