diff --git a/.github/workflows/docker-push-dev.yml b/.github/workflows/docker-push-dev.yml index bb6b8c8..c1df118 100644 --- a/.github/workflows/docker-push-dev.yml +++ b/.github/workflows/docker-push-dev.yml @@ -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 @@ -54,6 +54,7 @@ jobs: with: context: . builder: ${{ steps.buildx.outputs.name }} + target: emulator file: Dockerfile push: false load: true diff --git a/Dockerfile b/Dockerfile index b78189a..bbd3135 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" @@ -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 diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index ad129d5..6d98d45 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -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 @@ -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