Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/docker-push-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
REPO_NAME: ghcr.io/${{ github.repository }}
run: |
REPO_NAME=$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')
TAG="0.3.1-dev"
TAG="0.3.3-dev"

# Docker
echo "docker_image_name=${REPO_NAME}" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -54,6 +54,7 @@ jobs:
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
target: emulator
file: Dockerfile
push: false
load: true
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NOTE: If you make any BREAKING CHANGE:
# - Update the Docker image tag in `./.github/workflows/docker-push-dev.yml`
# - Update the `mapswipe-backend` workflow to use the new image tag
FROM node:20-bullseye-slim
FROM node:20-bullseye-slim AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
Expand All @@ -18,9 +18,12 @@ WORKDIR /firebase
ARG FIREBASE_TOOLS_VERSION=14.5.1

RUN --mount=type=cache,target=/root/.npm \
npm install -g firebase-tools@$FIREBASE_TOOLS_VERSION \
# Download jar files
&& firebase setup:emulators:database \
npm install -g firebase-tools@$FIREBASE_TOOLS_VERSION

FROM base AS emulator

# Pre-download firebase emulator tools
RUN firebase setup:emulators:database \
&& firebase setup:emulators:firestore \
&& firebase setup:emulators:storage \
&& firebase setup:emulators:ui
38 changes: 24 additions & 14 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@

set -e

FIREBASE_EMULATOR_FUNCTIONS_DISABLED=${FIREBASE_EMULATOR_FUNCTIONS_DISABLED:-false}

BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
FIREBASE_FUNCTIONS_DIR="$BASE_DIR/functions/"

cd "$BASE_DIR"

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

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

echo "[INFO] Transpiling functions for Firebase..."
cd "$FIREBASE_FUNCTIONS_DIR"
pnpm build
fi

# PIDs
pid=0
Expand Down Expand Up @@ -49,8 +54,13 @@ trap graceful_shutdown SIGINT SIGTERM
# Start Firebase emulator in background
echo "[INFO] Starting Firebase emulator..."
FIREBASE_EMULATOR_DATA_DIR=${FIREBASE_EMULATOR_DATA_DIR?FIREBASE_EMULATOR_DATA_DIR is required}
firebase emulators:start --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
pid="$!"
if [ $FIREBASE_EMULATOR_FUNCTIONS_DISABLED != "true" ]; then
firebase emulators:start --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
pid="$!"
else
firebase emulators:start --only database,hosting,auth --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
pid="$!"
fi


# Keep container alive with dummy tail
Expand Down