Skip to content

Commit

Permalink
feat: deploy firebase/firestore rules, #143
Browse files Browse the repository at this point in the history
  • Loading branch information
weaponsforge committed Sep 27, 2024
1 parent dab6ffa commit eadd4dc
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 10 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- dev
- feat/weaponsforge-143

jobs:
lint-export-client:
Expand All @@ -17,11 +18,16 @@ jobs:
NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN: ${{ secrets.FIREBASE_WEB_AUTHDOMAIN_DEV }}
NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID: ${{ secrets.FIREBASE_WEB_PROJECT_ID_DEV }}
NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET: ${{ secrets.FIREBASE_WEB_STORAGE_BUCKET_DEV }}
FIREBASE_HOSTING_DEV: ${{ secrets.FIREBASE_WEB_STORAGE_BUCKET_DEV }}
FIREBASE_TARGET: 'dev'
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: 'dev'
ref: 'feat/weaponsforge-143'
# ref: $FIREBASE_TARGET
- name: Build Firebase Settings
run: chmod u+x scripts/build.sh && ./scripts/build.sh
- name: Use NodeJS v16.14.2
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -49,7 +55,8 @@ jobs:
client/.firebaserc
retention-days: 3

deploy-client:
# Deploy Firebase: Hosting, Firestore/Storage Rules and Indexes
deploy-firebase:
name: Deploy Client to Firebase Hosting
needs: lint-export-client
runs-on: ubuntu-latest
Expand All @@ -61,6 +68,8 @@ jobs:
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: use dev && firebase deploy --only hosting:dev
args: >
use $FIREBASE_TARGET &&
deploy --only hosting:$FIREBASE_TARGET,firestore:rules,storage
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ jobs:
NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN: ${{ secrets.FIREBASE_WEB_AUTHDOMAIN_PROD }}
NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID: ${{ secrets.FIREBASE_WEB_PROJECT_ID_PROD }}
NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET: ${{ secrets.FIREBASE_WEB_STORAGE_BUCKET_PROD }}
FIREBASE_TARGET: 'prod'
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.release.tag_name }}
- name: Build Firebase Settings
run: chmod u+x scripts/build.sh && ./scripts/build.sh
- name: Use NodeJS v16.14.2
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -48,6 +51,25 @@ jobs:
path: client/out
retention-days: 3

# Deploy Firebase: Firestore/Storage Rules and Indexes
deploy-firebase:
name: Deploy Client to Firebase Hosting
needs: lint-export-client
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: dev-app
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: >
use $FIREBASE_TARGET &&
deploy --only firestore:rules,storage
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

deploy-client:
name: Deploy client to Github Pages
needs: lint-export-client
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,68 @@ docker compose -f docker-compose.prod.yml up
docker compose -f docker-compose.prod.yml down
```

## Deploy With GitHub Actions

### Requirements

1. Two (2) Firebase Projects (to use for development/production environments), pre-activated with:
- Firestore Database
- Firebase Storage
- Firebase Hosting
- Authentication (Email/Address)

> [!TIP]
> Refer to the server README for additional setup information
2. Firebase configuration settings for each of the two (2) Firebase projects.

3. Service account JSON file for each of the two (2) Firebase projects.

## Steps

Follow the steps to self-host the project in your own repository and Firebase projects.

### 1. GitHub Secrets

Create the following GitHub Secrets, using values from the Firebase configuration and settings from the requirements.

| GitHub Secret | Description |
| --- | --- |
| NEXT_PUBLIC_BASE_PATH | Root directory path name that NextJS uses for assets, media and client-side routing for the app.<br><br>Set its value to blank `''` when working on development mode in localhost.<br><br>Set its value to the sub-directory name where the exported NextJS app is to be deployed, i.e. `/<YOUR_REPOSITORY_NAME>` when<br> deploying on a repository (sub-directory) of a root GitHub Pages site, i.e, on `https://<YOUR_GITHUB_USERNAME>.github.io/<YOUR_REPOSITORY_NAME>` |
| FIREBASE_WEB_API_KEY_DEV | Firebase web API key from the Firebase Project Settings configuration file for the (development) environment. |
| FIREBASE_WEB_AUTHDOMAIN_DEV | Firebase web auth domain key from the Firebase Project Settings configuration for the (development) environment. |
| FIREBASE_WEB_PROJECT_ID_DEV | Firebase web project ID from the Firebase Project Settings configuration file for the (development) environment. |
| FIREBASE_WEB_STORAGE_BUCKET_DEV | Firebase web storage bucket key from the Firebase Project Settings configuration file for the (development) environment. |
| FIREBASE_WEB_API_KEY_PROD | Firebase web API key from the Firebase Project Settings configuration file for the (production) environment. |
| FIREBASE_WEB_AUTHDOMAIN_PROD | Firebase web auth domain key from the Firebase Project Settings configuration for the (production) environment. |
| FIREBASE_WEB_PROJECT_ID_PROD | Firebase web project ID from the Firebase Project Settings configuration file for the (production) environment. |
| FIREBASE_WEB_STORAGE_BUCKET_PROD | Firebase web storage bucket key from the Firebase Project Settings configuration file for the (production) environment. |
| FIREBASE_TOKEN | Firebase CLI deploy token, retrieved with `"firebase login:ci"` |
| FIREBASE_HOSTING_DEV | Firebase Hosting name under the `FIREBASE_WEB_PROJECT_ID_DEV` |

### 2. Firebase Hosting

> The project website deploys to Firebase Hosting for its development environment on push or updates to the `dev` branch.
Initialize a Firebase Hosting website in the _**development**_ Firebase project.

### 3. GitHub Pages

Initialize an empty branch in the repository to use for deployment to GitHub Pages.

```bash
# While inside the project code repository root
git checkout --orphan gh-pages
git reset
git commit --allow-empty -m "Initial commit"
git push --set-upstream origin gh-pages
```

### 4. Ship and Deploy

- Deploy to the **development** environment (Firebase Hosting) by pushing or merging updates to the `dev` branch.
- Deploy to the **production** environment (GitHub Pages) by creating a Release/Tag from the `master` branch.


@weaponsforge<br>
20230326
14 changes: 7 additions & 7 deletions client/.firebaserc
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"projects": {
"dev": "climate-profile-app",
"prod": "gsites-embed"
"dev": "FIREBASE_PROJECT_DEV",
"prod": "FIREBASE_PROJECT_PROD"
},
"targets": {
"climate-profile-app": {
"FIREBASE_PROJECT_DEV": {
"hosting": {
"dev": [
"climate-profile-dev"
"FIREBASE_HOSTING_DEV"
]
},
"storage": {
"dev": [
"climate-profile-app.appspot.com"
"FIREBASE_PROJECT_DEV.appspot.com"
]
}
},
"gsites-embed": {
"FIREBASE_PROJECT_PROD": {
"storage": {
"dev": [
"gsites-embed.appspot.com"
"FIREBASE_PROJECT_PROD.appspot.com"
]
}
}
Expand Down
15 changes: 15 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "Setting the .firebaserc values..."

if [ "$FIREBASE_TARGET" == "dev" ]; then
# Replace placeholders with development Firebase settings
sed -i -e "s/FIREBASE_PROJECT_DEV/${NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID}/g" client/.firebaserc
sed -i -e "s/FIREBASE_HOSTING_DEV/${FIREBASE_HOSTING_DEV}/g" client/.firebaserc
elif [ "$FIREBASE_TARGET" == "prod" ]; then
# Replace placeholders with production Firebase settings
sed -i -e "s/FIREBASE_PROJECT_PROD/${NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID}/g" client/.firebaserc
else
echo "Error: FIREBASE_TARGET must be 'dev' or 'prod', value: $FIREBASE_TARGET"
exit 1
fi

0 comments on commit eadd4dc

Please sign in to comment.