Skip to content

Commit c5fab84

Browse files
authored
Merge pull request #4 from mapswipe/project/backend-integration
Project: Backend integration
2 parents cd72fac + 689b9ad commit c5fab84

File tree

18 files changed

+2118
-178
lines changed

18 files changed

+2118
-178
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Docker publish dev
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "develop"
8+
pull_request:
9+
10+
jobs:
11+
docker-publish:
12+
name: Publish docker
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: 🐳 Prepare Docker
19+
id: prep
20+
env:
21+
REPO_NAME: ghcr.io/${{ github.repository }}
22+
run: |
23+
REPO_NAME=$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')
24+
TAG="0.0.1-dev"
25+
26+
# Docker
27+
echo "docker_image_name=${REPO_NAME}" >> $GITHUB_OUTPUT
28+
echo "docker_image_tag=${TAG}" >> $GITHUB_OUTPUT
29+
echo "docker_image=${REPO_NAME}:${TAG}" >> $GITHUB_OUTPUT
30+
31+
- name: Login to GitHub Container Registry
32+
if: github.event_name != 'pull_request'
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: 🐳 Set up Docker Buildx
40+
id: buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: 🐳 Cache Docker layers
44+
uses: actions/cache@v4
45+
with:
46+
path: /tmp/.buildx-cache
47+
key: ${{ runner.os }}-buildx-${{ github.ref }}
48+
restore-keys: |
49+
${{ runner.os }}-buildx-refs/develop
50+
${{ runner.os }}-buildx-
51+
52+
- name: 🐳 Build image
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
builder: ${{ steps.buildx.outputs.name }}
57+
file: Dockerfile
58+
push: false
59+
load: true
60+
provenance: false # XXX: Without this we have untagged images in ghcr.io
61+
tags: ${{ steps.prep.outputs.docker_image }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
65+
- name: 🐳 Docker push
66+
if: github.event_name != 'pull_request'
67+
env:
68+
DOCKER_IMAGE: ${{ steps.prep.outputs.docker_image }}
69+
run: docker push $DOCKER_IMAGE

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ node_modules/
6363
.env
6464

6565
.DS_Store
66+
67+
# Firebase emulator temp export files
68+
firebase-export-*
69+
70+
*.egg-info
71+
72+
__pycache__

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
FROM node:14.18.0-alpine
2-
RUN npm install firebase-functions@latest firebase-admin@latest --save
3-
RUN npm install -g [email protected]
4-
COPY . /firebase
5-
RUN cd firebase/functions && npm install
6-
WORKDIR /firebase/
1+
# NOTE: If you make any BREAKING CHANGE:
2+
# - Update the Docker image tag in `./.github/workflows/docker-push-dev.yml`
3+
# - Update the `mapswipe-backend` workflow to use the new image tag
4+
FROM node:22-bullseye-slim
5+
6+
RUN apt-get update -y \
7+
&& apt-get install -y --no-install-recommends openjdk-11-jdk bash procps
8+
9+
WORKDIR /firebase
10+
11+
# renovate: datasource=github-tags depName=firebase/firebase-tools
12+
ARG FIREBASE_TOOLS_VERSION=14.5.1
13+
14+
RUN --mount=type=cache,target=/root/.npm \
15+
npm install -g firebase-tools@$FIREBASE_TOOLS_VERSION \
16+
# Download jar files
17+
&& firebase setup:emulators:database \
18+
&& firebase setup:emulators:firestore \
19+
&& firebase setup:emulators:storage \
20+
&& firebase setup:emulators:ui

docker_entrypoint.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# TODO: This may need another look
6+
cd functions
7+
yarn install --frozen-lockfile
8+
yarn build
9+
cd ../
10+
11+
# PIDs
12+
pid=0
13+
tail_pid=0
14+
15+
# Signal handler for graceful shutdown
16+
graceful_shutdown() {
17+
echo "[INFO] Caught termination signal. Forwarding to Firebase emulator..."
18+
19+
if kill -0 "$pid" 2>/dev/null; then
20+
kill -TERM "$pid"
21+
wait "$pid"
22+
fi
23+
24+
if kill -0 "$tail_pid" 2>/dev/null; then
25+
kill "$tail_pid"
26+
wait "$tail_pid"
27+
fi
28+
29+
echo "[INFO] Firebase shut down gracefully, export should be complete."
30+
exit 0
31+
}
32+
33+
# Trap SIGINT and SIGTERM for Docker shutdown
34+
trap graceful_shutdown SIGINT SIGTERM
35+
36+
# Start Firebase emulator in background
37+
echo "[INFO] Starting Firebase emulator..."
38+
FIREBASE_EMULATOR_DATA_DIR=${FIREBASE_EMULATOR_DATA_DIR?FIREBASE_EMULATOR_DATA_DIR is required}
39+
firebase emulators:start --import="$FIREBASE_EMULATOR_DATA_DIR" --export-on-exit &
40+
pid="$!"
41+
42+
43+
# Keep container alive with dummy tail
44+
tail -f /dev/null &
45+
tail_pid="$!"
46+
47+
# Wait on both Firebase and tail, exit if either ends
48+
wait -n "$pid" "$tail_pid"
49+
50+
# If we got here without a signal, something ended unexpectedly
51+
echo "[ERROR] Firebase or keep-alive process exited unexpectedly"
52+
exit 1

firebase.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,27 @@
2424
]
2525
},
2626
"emulators": {
27+
"singleProjectMode": true,
2728
"auth": {
29+
"host": "0.0.0.0",
2830
"port": 9099
2931
},
3032
"functions": {
33+
"host": "0.0.0.0",
3134
"port": 5001
3235
},
3336
"database": {
37+
"host": "0.0.0.0",
3438
"port": 9000
3539
},
3640
"hosting": {
41+
"host": "0.0.0.0",
3742
"port": 5000
3843
},
3944
"ui": {
40-
"enabled": true
45+
"enabled": true,
46+
"port": 4000,
47+
"host": "0.0.0.0"
4148
}
4249
}
4350
}

0 commit comments

Comments
 (0)