Skip to content

Commit d1635db

Browse files
authored
Merge pull request #85 from ciatph/dev
v1.1.6
2 parents c47d7ec + ebf9cfd commit d1635db

File tree

10 files changed

+122
-12
lines changed

10 files changed

+122
-12
lines changed

.github/workflows/pull-images.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Pull the Docker images from Docker Hub on schedule
2+
name: Pull Docker Images
3+
4+
on:
5+
schedule:
6+
# Runs "At 00:00 on day-of-month 1 in every 2nd month."
7+
- cron: '0 0 1 */2 *'
8+
9+
jobs:
10+
pull-images:
11+
name: Pull App Image
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout the repository
15+
uses: actions/checkout@v3
16+
17+
- name: Fetch and check out latest tag
18+
run: |
19+
git fetch --tags
20+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
21+
echo "Checking out latest tag: $LATEST_TAG"
22+
git checkout $LATEST_TAG
23+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
24+
25+
- name: Create temporary env variables
26+
run: |
27+
cp client/.env.example client/.env
28+
cp server/.env.example server/.env
29+
30+
- name: Pull App Image
31+
run: |
32+
sed -i "s/:latest/:$LATEST_TAG/" docker-compose.app.yml
33+
docker compose -f docker-compose.app.yml pull
34+
35+
- name: Pull Development Images
36+
run: docker compose -f docker-compose.dev.yml pull

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to Development Environment
1+
name: Deploy to Production Environment
22

33
# This workflow will trigger on any tag/release created on *any* branch
44
# Make sure to create tags/releases only from the "master" branch for consistency

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.env
2-
.vscode
32
*.zip

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "attach",
10+
"name": "Docker: Attach to Node",
11+
"port": 9229,
12+
"address": "localhost",
13+
"localRoot": "${workspaceFolder}//server",
14+
"remoteRoot": "/opt/server",
15+
"protocol": "inspector",
16+
"restart": true,
17+
"sourceMaps": true,
18+
"skipFiles": ["<node_internals>/**"]
19+
},
20+
{
21+
"type": "node",
22+
"request": "launch",
23+
"name": "Launch Program",
24+
"skipFiles": [
25+
"<node_internals>/**"
26+
],
27+
"program": "${workspaceFolder}\\server\\src\\index.js",
28+
"envFile": "${workspaceFolder}/server/.env"
29+
}
30+
]
31+
}

README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ A basic web app client in the **/client** directory will show basic API usage an
1414
- [Docker Dependencies](#docker-dependencies)
1515
- [Docker for Localhost Development](#docker-for-localhost-development)
1616
- [Docker for Production Deployment](#docker-for-production-deployment)
17-
- [Pre-built Server Docker Image](#pre-built-server-docker-image-app)
18-
- [Pre-built Server Docker Image](#pre-built-server-docker-image-client--server-development)
17+
- [Pre-built Server Docker Image (App)](#pre-built-server-docker-image-app)
18+
- [Pre-built Server Docker Image (Client + Server) Development](#pre-built-server-docker-image-client--server-development)
19+
- [Deploy with GitHub Actions](#deploy-with-gitHub-actions)
1920
- [References](#references)
2021

2122
## Requirements
@@ -56,6 +57,8 @@ A basic web app client in the **/client** directory will show basic API usage an
5657
|EMAIL_WHITELIST| Comma-separated email addresses linked to Firebase Auth UserRecords that are not allowed to be deleted or updated (write-protected)<br><br>Default value is `[email protected]`|
5758
|ALLOW_CORS|Allow Cross-Origin Resource Sharing (CORS) on the API endpoints.<br><br>Default value is `1`, allowing access to domains listed in `ALLOWED_ORIGINS`. Setting to `0` will make all endpoints accept requests from all domains, including Postman.|
5859
|ALLOW_AUTH|Restrict access to the `POST`, `PATCH` and `DELETE` API endpoints by allowing signed-in Firebase user Bearer Authorization (Firebase token) checking.<br><br>Retrieve the signed-in Firebase token by signing in a user using the Firebase Web JS SDK `signInWithEmailAndPassword()` method, then retrieve the latest token value using `getIdTokenResult()`.<br><br>Default value is `1`. Setting to `0` will disable Bearer Authorization checking on the listed API endpoints.|
60+
| CHOKIDAR_USEPOLLING | Enables hot reload on `nodemon` running inside Docker containers on a Windows host. Set it to true if running Docker Desktop with WSL2 on a Windows OS. |
61+
| CHOKIDAR_INTERVAL | Chokidar polling interval. Set it along with `CHOKIDAR_USEPOLLING=true` if running Docker Desktop with WSL2 on a Windows OS. The default value is `1000`. |
5962

6063
### client
6164

@@ -82,6 +85,7 @@ A basic web app client in the **/client** directory will show basic API usage an
8285
| REACT_APP_FIREBASE_MESSAGING_SENDER_ID | Firebase web messaging sender ID from the Firebase Project Settings configuration file. |
8386
| REACT_APP_FIREBASE_APP_ID | Firebase web web app key from the Firebase Project Settings configuration file. |
8487
| REACT_APP_FIREBASE_MEASUREMENT_ID | Firebase web measurement ID from the Firebase Project Settings configuration file. |
88+
| WATCHPACK_POLLING | Enables hot reload on React apps running inside Docker containers on a Windows host. Set it to `true` if running Docker Desktop with WSL2 on a Windows OS. |
8589

8690
4. Run the app in development mode.
8791
`npm start`
@@ -234,8 +238,8 @@ The server also serves the pre-built `client` website from a static directory us
234238
### Steps
235239

236240
1. Pull the (production) **/server** [Docker image](https://hub.docker.com/repository/docker/ciatphdev/firebase-users-app) from Docker Hub.
237-
- Find the latest version tag from https://hub.docker.com/r/ciatphdev/firebase-users-app, i.e., `v1.1.5`
238-
- `docker pull ciatphdev/firebase-users-app:v1.1.5`
241+
- Find the latest version tag from https://hub.docker.com/r/ciatphdev/firebase-users-app, i.e., `v1.1.6`
242+
- `docker pull ciatphdev/firebase-users-app:v1.1.6`
239243
2. Create a `.env` file.
240244
- Read [**Installation - server #3**](#server) for more information.
241245
- Replace the variables accordingly in the `.env` file. Set `ALLOW_CORS=0` to allow `Same Origin` requests. Read [**Option #2 - Client and Server Bundled in (1) Image and Service**](#option-2---client-and-server-bundled-in-1-image-and-service) for more information.
@@ -252,7 +256,7 @@ The server also serves the pre-built `client` website from a static directory us
252256
docker run -it --rm \
253257
--env-file .env \
254258
-p 3001:3001 \
255-
ciatphdev/firebase-users-admin-app:v1.1.5
259+
ciatphdev/firebase-users-admin-app:v1.1.6
256260
```
257261
4. Run a script in the container to create the default `[email protected]` account, if it does not yet exist in the Firestore database.
258262
`docker exec -it firebase-users-admin-app npm run seed`
@@ -293,6 +297,40 @@ https://hub.docker.com/r/ciatphdev/firebase-users-server/tags
293297
docker run -it --rm --env-file .env -p 3001:3001 ciatphdev/firebase-users-server:dev
294298
```
295299
300+
## Deploy with GitHub Actions
301+
302+
### Requirements
303+
304+
1. Firebase project
305+
- with Authentication (Email/Password) activated
306+
2. Docker Hub account
307+
308+
### Steps
309+
310+
1. Create the following GitHub Secrets:<br>
311+
**client** `.env` variables
312+
```
313+
REACT_APP_BASE_URL
314+
REACT_APP_FIREBASE_API_KEY
315+
REACT_APP_FIREBASE_AUTHDOMAIN
316+
REACT_APP_FIREBASE_PROJECT_ID
317+
REACT_APP_FIREBASE_STORAGE_BUCKET
318+
REACT_APP_FIREBASE_MESSAGING_SENDER_ID
319+
REACT_APP_FIREBASE_APP_ID
320+
REACT_APP_FIREBASE_MEASUREMENT_ID
321+
```
322+
323+
**Docker Hub Account**
324+
| GitHub Secret | Description |
325+
| --- | --- |
326+
| DOCKERHUB_USERNAME | Docker Hub username |
327+
| DOCKERHUB_TOKEN | Deploy token for the Docker Hub account |
328+
329+
2. Create Release/Tag from the `master` branch to trigger deployment to the **production** environment:
330+
- Deploy front end (React) to Firebase Hosting
331+
- Build and push Docker images to Docker Hub
332+
333+
3. Inspect the contents of the `.github/workflows/release.yml` for reference.
296334
297335
## References
298336

client/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ REACT_APP_FIREBASE_PROJECT_ID=users-admin-firebase
55
REACT_APP_FIREBASE_STORAGE_BUCKET=users-admin-firebase.appspot.com
66
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=761515421472
77
REACT_APP_FIREBASE_APP_ID=1:761515421472:web:d7c737ba274515297f3145
8-
REACT_APP_FIREBASE_MEASUREMENT_ID=G-ZCWY6YX0P0
8+
REACT_APP_FIREBASE_MEASUREMENT_ID=G-ZCWY6YX0P0
9+
# Uncomment this line if using Docker Desktop and WSL2 on Windows OS
10+
# WATCHPACK_POLLING=true

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ services:
3434
- /opt/server/node_modules
3535
ports:
3636
- "3001:3001"
37+
- "9229:9229"
3738

3839
networks:
3940
firebase-users-dev:

server/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ FIREBASE_PRIVATE_KEY=PRIVATE-KEY-FROM-FIREBASE-SERVICE-ACCOUNT-JSON-WITH-DOUBLE-
44
EMAIL_WHITELIST=[email protected]
55
ALLOW_CORS=1
66
ALLOW_AUTH=1
7+
# Uncomment these 2 CHOKIDAR lines if running Express on Docker Desktop and WSL2 on Windows OS
8+
# CHOKIDAR_USEPOLLING=true
9+
# CHOKIDAR_INTERVAL=1000

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"pm2": "pm2 start process.json --no-daemon",
1212
"start": "node src/index.js",
1313
"build": "npm run gen:docs",
14-
"dev": "nodemon watch src/index.js",
14+
"dev": "nodemon --inspect=0.0.0.0:9229 src/index.js",
1515
"seed": "node src/scripts/seeder.js",
1616
"lint": "eslint src --ignore-path .gitignore",
1717
"lint:fix": "eslint --ignore-path .gitignore --fix src",

server/src/utils/templates/header.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ firebase-users-admin's server component, hosting all the listed endpoints below
2222
The server also serves a pre-built [`client`](https://github.com/ciatph/firebase-users-admin/tree/dev/client) website from a static directory using the `express.static()` middleware, following the build instructions from [**Option #2 - Client and Server Bundled in (1) Image and Service**](https://github.com/ciatph/firebase-users-admin#option-2---client-and-server-bundled-in-1-image-and-service).
2323

2424
1. Pull the (production) **/server** [Docker image](https://hub.docker.com/repository/docker/ciatphdev/firebase-users-app) from Docker Hub.
25-
- Find the latest version tag from https://hub.docker.com/r/ciatphdev/firebase-users-app, i.e., `v1.1.5`
26-
- `docker pull ciatphdev/firebase-users-app:v1.1.5`
25+
- Find the latest version tag from https://hub.docker.com/r/ciatphdev/firebase-users-app, i.e., `v1.1.6`
26+
- `docker pull ciatphdev/firebase-users-app:v1.1.6`
2727
2. Create a `.env` file.
2828
- Read [**Installation - server #3**](https://github.com/ciatph/firebase-users-admin#server) for more information.
2929
- Replace the variables accordingly in the `.env` file. Set `ALLOW_CORS=0` to allow `Same Origin` requests. Read [**Option #2 - Client and Server Bundled in (1) Image and Service**](https://github.com/ciatph/firebase-users-admin#option-2---client-and-server-bundled-in-1-image-and-service) for more information.
@@ -40,7 +40,7 @@ The server also serves a pre-built [`client`](https://github.com/ciatph/firebase
4040
docker run -it --rm \
4141
--env-file .env
4242
-p 3001:3001 \
43-
ciatphdev/firebase-users-admin-app:v1.1.5
43+
ciatphdev/firebase-users-admin-app:v1.1.6
4444
```
4545
4. Run a script in the container to create the default `[email protected]` account, if it does not yet exist in the Firestore database.
4646
`docker exec -it firebase-users-admin-app npm run seed`

0 commit comments

Comments
 (0)