Skip to content

Commit 957b3b3

Browse files
authored
Merge pull request #37 from mapswipe/feat/disable-firebase-functions
2 parents fb3dba3 + 6e3e012 commit 957b3b3

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

.github/workflows/docker-push-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
REPO_NAME: ghcr.io/${{ github.repository }}
2222
run: |
2323
REPO_NAME=$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')
24-
TAG="0.3.1-dev"
24+
TAG="0.3.3-dev"
2525
2626
# Docker
2727
echo "docker_image_name=${REPO_NAME}" >> $GITHUB_OUTPUT
@@ -54,6 +54,7 @@ jobs:
5454
with:
5555
context: .
5656
builder: ${{ steps.buildx.outputs.name }}
57+
target: emulator
5758
file: Dockerfile
5859
push: false
5960
load: true

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# NOTE: If you make any BREAKING CHANGE:
22
# - Update the Docker image tag in `./.github/workflows/docker-push-dev.yml`
33
# - Update the `mapswipe-backend` workflow to use the new image tag
4-
FROM node:20-bullseye-slim
4+
FROM node:20-bullseye-slim AS base
55

66
ENV PNPM_HOME="/pnpm"
77
ENV PATH="$PNPM_HOME:$PATH"
@@ -18,9 +18,12 @@ WORKDIR /firebase
1818
ARG FIREBASE_TOOLS_VERSION=14.5.1
1919

2020
RUN --mount=type=cache,target=/root/.npm \
21-
npm install -g firebase-tools@$FIREBASE_TOOLS_VERSION \
22-
# Download jar files
23-
&& firebase setup:emulators:database \
21+
npm install -g firebase-tools@$FIREBASE_TOOLS_VERSION
22+
23+
FROM base AS emulator
24+
25+
# Pre-download firebase emulator tools
26+
RUN firebase setup:emulators:database \
2427
&& firebase setup:emulators:firestore \
2528
&& firebase setup:emulators:storage \
2629
&& firebase setup:emulators:ui

docker_entrypoint.sh

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22

33
set -e
44

5+
FIREBASE_EMULATOR_FUNCTIONS_DISABLED=${FIREBASE_EMULATOR_FUNCTIONS_DISABLED:-false}
6+
57
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
68
FIREBASE_FUNCTIONS_DIR="$BASE_DIR/functions/"
79

8-
cd "$BASE_DIR"
910

10-
# NOTE: when we are using mapswipe-firebase as a submodule inside docker,
11-
# the .git directory is not accessible. The parent .git directory is in host
12-
# system not accesssible by the container
13-
# Inside the container, pnpm install fails when we are installing packages from git repository.
14-
# So, we need to switch to /tmp directory as a workaround
15-
echo "[INFO] Installing dependencies for transpiling functions for Firebase..."
16-
cd /tmp/
17-
pnpm --dir "$FIREBASE_FUNCTIONS_DIR" install --frozen-lockfile
11+
cd "$BASE_DIR"
1812

19-
echo "[INFO] Transpiling functions for Firebase..."
20-
cd "$FIREBASE_FUNCTIONS_DIR"
21-
pnpm build
13+
if [ $FIREBASE_EMULATOR_FUNCTIONS_DISABLED != "true" ]; then
14+
# NOTE: when we are using mapswipe-firebase as a submodule inside docker,
15+
# the .git directory is not accessible. The parent .git directory is in host
16+
# system not accesssible by the container
17+
# Inside the container, pnpm install fails when we are installing packages from git repository.
18+
# So, we need to switch to /tmp directory as a workaround
19+
echo "[INFO] Installing dependencies for transpiling functions for Firebase..."
20+
cd /tmp/
21+
pnpm --dir "$FIREBASE_FUNCTIONS_DIR" install --frozen-lockfile
22+
23+
echo "[INFO] Transpiling functions for Firebase..."
24+
cd "$FIREBASE_FUNCTIONS_DIR"
25+
pnpm build
26+
fi
2227

2328
# PIDs
2429
pid=0
@@ -49,8 +54,13 @@ trap graceful_shutdown SIGINT SIGTERM
4954
# Start Firebase emulator in background
5055
echo "[INFO] Starting Firebase emulator..."
5156
FIREBASE_EMULATOR_DATA_DIR=${FIREBASE_EMULATOR_DATA_DIR?FIREBASE_EMULATOR_DATA_DIR is required}
52-
firebase emulators:start --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
53-
pid="$!"
57+
if [ $FIREBASE_EMULATOR_FUNCTIONS_DISABLED != "true" ]; then
58+
firebase emulators:start --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
59+
pid="$!"
60+
else
61+
firebase emulators:start --only database,hosting,auth --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
62+
pid="$!"
63+
fi
5464

5565

5666
# Keep container alive with dummy tail

0 commit comments

Comments
 (0)