Skip to content

Commit dc9a0fa

Browse files
authored
Merge pull request #27 from mapswipe/deploy/alpha
Deployment: Alpha
2 parents 9ae0b1b + 80bb75b commit dc9a0fa

File tree

10 files changed

+5388
-4065
lines changed

10 files changed

+5388
-4065
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ jobs:
1515
with:
1616
enable-cache: true
1717

18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v4
20+
with:
21+
package_json_file: ./functions/package.json
22+
23+
- name: Setup node environment
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version-file: ./functions/package.json
27+
cache: 'pnpm'
28+
cache-dependency-path: ./functions/pnpm-lock.yaml
29+
1830
- name: Setup python environment
1931
working-directory: ./functions/generated/pyfirebase
2032
run: uv venv
@@ -32,20 +44,13 @@ jobs:
3244
with:
3345
extra_args: --all-files --hook-stage manual --show-diff-on-failure
3446

35-
- name: Setup node environment
36-
uses: actions/setup-node@v4
37-
with:
38-
node-version: 22
39-
cache: 'yarn'
40-
cache-dependency-path: ./functions/yarn.lock
41-
4247
- name: Install JS dependencies
4348
working-directory: ./functions
44-
run: yarn install --frozen-lockfile
49+
run: pnpm install --frozen-lockfile
4550

4651
- name: Generate python definition files
4752
working-directory: ./functions
48-
run: yarn generate:py
53+
run: pnpm generate:py
4954

5055
- name: Run pre-commit for generated python definition files
5156
run: |
@@ -76,7 +81,7 @@ jobs:
7681
- name: Check if generated definition files are up to date.
7782
run: |
7883
if ! git diff --quiet ./functions/generated/; then
79-
echo "❌ Generated definition files are not up-to-date. Run 'yarn generate:py' to update the generated definitionfiles."
84+
echo "❌ Generated definition files are not up-to-date. Run 'pnpm generate:py' to update the generated definitionfiles."
8085
git status
8186
git --no-pager diff
8287
exit 1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7+
.pnpm-debug.log
8+
.pnpm-store/
9+
710
firebase-debug.log*
811

912
# Firebase cache
@@ -70,3 +73,5 @@ firebase-export-*
7073
*.egg-info
7174

7275
__pycache__
76+
77+
serviceAccount.json

DEPLOY.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Deployment
2+
3+
> ![CAUTION]
4+
> This is a work in progress documentation, make sure to take it with precaution
5+
6+
## Setup
7+
8+
### Google Cloud Project setup
9+
10+
Enable APIs in your new project:
11+
12+
- Cloud Build
13+
- e.g: https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com?project=mapswipe-alpha-01
14+
- Cloud Function
15+
- e.g: https://console.cloud.google.com/apis/library/cloudfunctions.googleapis.com?project=mapswipe-alpha-01
16+
- Firebase Extensions
17+
- e.g: https://console.cloud.google.com/apis/api/firebaseextensions.googleapis.com/metrics?project=mapswipe-alpha-01
18+
- Cloud Billing
19+
- e.g: https://console.cloud.google.com/apis/api/cloudbilling.googleapis.com/metrics?project=mapswipe-alpha-01
20+
21+
### Service account for deployment
22+
23+
- https://console.cloud.google.com/iam-admin/serviceaccounts
24+
- Select project (e.g: "mapswipe-alpha-01")
25+
- Create service account
26+
- Create service account
27+
- **Service account name:** firebase-deploy
28+
- **Service account ID:** firebase-deploy
29+
- Create and continue
30+
- Permissions (Add)
31+
- Role: Cloud Function Developer
32+
- Role: Firebase Admin
33+
- Role: Firebase Hosting Admin
34+
- Role: Firebase Rules Admin
35+
- Role: Service Account User
36+
- Principals with access (Skip)
37+
- Select the new service account (firebase-deploy...)
38+
- Keys
39+
- Add key
40+
- Create new key
41+
- JSON
42+
- Create

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
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:22-bullseye-slim
4+
FROM node:20-bullseye-slim
5+
6+
ENV PNPM_HOME="/pnpm"
7+
ENV PATH="$PNPM_HOME:$PATH"
58

69
RUN apt-get update -y \
710
&& apt-get install -y --no-install-recommends \
8-
openjdk-11-jdk bash procps git
11+
openjdk-11-jdk bash procps git \
12+
&& corepack enable \
13+
&& corepack prepare [email protected] --activate
914

1015
WORKDIR /firebase
1116

deploy.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -xe
4+
5+
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
FIREBASE_FUNCTIONS_DIR="$BASE_DIR/functions/"
7+
8+
cd "$BASE_DIR"
9+
10+
echo "[INFO] Installing dependencies for transpiling functions for Firebase..."
11+
cd /tmp/
12+
13+
pnpm --filter "$FIREBASE_FUNCTIONS_DIR" install --frozen-lockfile
14+
15+
echo "[INFO] Transpiling functions for Firebase..."
16+
cd "$FIREBASE_FUNCTIONS_DIR"
17+
18+
cd "$BASE_DIR"
19+
20+
firebase use ${FIREBASE_PROJECT?error}
21+
22+
firebase target:apply hosting auth "$FIREBASE_AUTH_SITE"
23+
24+
firebase functions:config:set \
25+
osm.redirect_uri="$OSM_OAUTH_REDIRECT_URI" \
26+
osm.redirect_uri_web="$OSM_OAUTH_REDIRECT_URI_WEB" \
27+
osm.app_login_link="$OSM_OAUTH_APP_LOGIN_LINK" \
28+
osm.app_login_link_web="$OSM_OAUTH_APP_LOGIN_LINK_WEB" \
29+
osm.api_url="$OSM_OAUTH_API_URL" \
30+
osm.client_id="$OSM_OAUTH_CLIENT_ID" \
31+
osm.client_id_web="$OSM_OAUTH_CLIENT_ID_WEB" \
32+
osm.client_secret="$OSM_OAUTH_CLIENT_SECRET" \
33+
osm.client_secret_web="$OSM_OAUTH_CLIENT_SECRET_WEB"
34+
35+
firebase deploy --only hosting
36+
firebase deploy --only database
37+
firebase deploy --only functions

docker_entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ cd "$BASE_DIR"
1010
# NOTE: when we are using mapswipe-firebase as a submodule inside docker,
1111
# the .git directory is not accessible. The parent .git directory is in host
1212
# system not accesssible by the container
13-
# Inside the container, yarn install fails when we are installing packages from git repository.
13+
# Inside the container, pnpm install fails when we are installing packages from git repository.
1414
# So, we need to switch to /tmp directory as a workaround
1515
echo "[INFO] Installing dependencies for transpiling functions for Firebase..."
1616
cd /tmp/
17-
yarn --cwd "$FIREBASE_FUNCTIONS_DIR" install --frozen-lockfile
17+
pnpm --filter "$FIREBASE_FUNCTIONS_DIR" install --frozen-lockfile
1818

1919
echo "[INFO] Transpiling functions for Firebase..."
2020
cd "$FIREBASE_FUNCTIONS_DIR"
21-
yarn build
21+
pnpm build
2222

2323
# PIDs
2424
pid=0

functions/package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"name": "functions",
33
"description": "Cloud Functions for Firebase",
4-
"packageManager": "[email protected]",
54
"scripts": {
65
"lint": "eslint --ext .js,.ts .",
76
"build": "tsc",
87
"build:watch": "tsc --watch",
98
"generate:ts": "typesync generate-ts --target firebase-admin@10 --definition 'definition/**/*.yaml' --indentation 4 --outFile generated/models.ts",
109
"generate:py": "typesync generate-py --target firebase-admin@6 --definition 'definition/**/*.yaml' --indentation 4 --outFile generated/pyfirebase/pyfirebase_mapswipe/models.py",
1110
"generate:rules": "typesync generate-rules --definition 'definition/**/*.yaml' --outFile ../database.rules.json",
12-
"serve": "yarn build && firebase emulators:start --only functions",
13-
"shell": "yarn build && firebase functions:shell",
14-
"start": "yarn shell",
11+
"serve": "pnpm build && firebase emulators:start --only functions",
12+
"shell": "pnpm build && firebase functions:shell",
13+
"start": "pnpm shell",
1514
"deploy": "firebase deploy --only functions",
1615
"deploy-rules": "firebase deploy --only database:rules",
1716
"logs": "firebase functions:log"
1817
},
1918
"main": "lib/index.js",
2019
"dependencies": {
20+
"@google-cloud/functions-framework": "^4.0.0",
2121
"axios": "^0.25.0",
2222
"cookie-parser": "^1.4.4",
2323
"firebase-admin": "^10.0.2",
@@ -27,6 +27,7 @@
2727
"simple-oauth2": "3.3.0"
2828
},
2929
"devDependencies": {
30+
"@togglecorp/typesync-cli": "^1.1.0",
3031
"@types/cookie-parser": "^1.4.3",
3132
"@types/simple-oauth2": "2.5.5",
3233
"@typescript-eslint/eslint-plugin": "^5.12.0",
@@ -36,12 +37,17 @@
3637
"eslint-plugin-import": "^2.25.4",
3738
"eslint-plugin-promise": "^4.0.1",
3839
"firebase-functions-test": "^0.2.0",
39-
"typescript": "^5.9.2",
40-
"typesync-cli": "https://github.com/toggle-corp/typesync#v1.1.0"
40+
"typescript": "^5.9.2"
4141
},
42+
"packageManager": "[email protected]",
4243
"engines": {
43-
"node": "22",
44-
"yarn": "1.22"
44+
"node": "20",
45+
"pnpm": "10.6.1"
4546
},
46-
"private": true
47+
"private": true,
48+
"pnpm": {
49+
"onlyBuiltDependencies": [
50+
"protobufjs"
51+
]
52+
}
4753
}

0 commit comments

Comments
 (0)