You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Installation and Usage Using Docker](#installation-and-usage-using-docker)
14
+
-[Docker Dependencies](#docker-dependencies)
14
15
-[Docker for Localhost Development](#docker-for-localhost-development)
15
16
-[Docker for Production Deployment](#docker-for-production-deployment)
16
-
-[Pre-built Server Docker Image](#pre-built-server-docker-image)
17
+
-[Pre-built Server Docker Image](#pre-built-server-docker-image)
17
18
-[References](#references)
18
19
19
20
## Requirements
@@ -50,9 +51,10 @@ A basic web app client in the **/client** directory will show basic API usage an
50
51
| --- | --- |
51
52
|FIREBASE_SERVICE_ACC| The project's private key file contents, condensed into one line and minus all whitespace characters.<br><br>The service account JSON file is generated from the Firebase project's **Project Settings** page, on **Project Settings** -> **Service accounts** -> **Generate new private key**|
52
53
|FIREBASE_PRIVATE_KEY| The `private_key` entry from the service account JSON file.<br> <blockquote> **NOTE:** Take note to make sure that the value starts and ends with a double-quote on WINDOWS OS localhost. Some systems may or may not require the double-quotes (i.e., Ubuntu running on heroku).</blockquote> |
53
-
|ALLOWED_ORIGINS|IP/domain origins in comma-separated values that are allowed to access the API. Include `http://localhost:3000` by default to allow CORS access to the `/client` app.|
54
+
|ALLOWED_ORIGINS|IP/domain origins in comma-separated values that are allowed to access the API if `ALLOW_CORS=1`. Include `http://localhost:3000` by default to allow CORS access to the `/client` app.|
54
55
|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]`|
55
-
|ALLOW_CORS|Allow Cross-Origin Resource Sharing (CORS) on the API endpoints.<br><br>Default value is `1`. Setting to `0` will make all endpoints accept requests from all domains, including Postman.|
56
+
|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.|
57
+
|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.|
56
58
57
59
### client
58
60
@@ -140,6 +142,14 @@ Copies the built `/client` website from `/client/build` to the server's root dir
140
142
141
143
We can use Docker to run dockerized **client** and **server** apps for local development. The following methods require Docker and Docker compose correctly installed and set up on your development machine.
142
144
145
+
### Docker Dependencies
146
+
147
+
The following dependencies are used to build and run the image. Please feel feel free to use other versions as needed.
148
+
149
+
1. Ubuntu 20.04 (Host)
150
+
2. Docker version 20.10.17, build 100c701
151
+
3. Docker Compose version v2.6.0
152
+
143
153
### Docker for Localhost Development
144
154
145
155
1. Set-up the environment variables and firebase configuration file for the **/client** app.
@@ -164,51 +174,85 @@ We can use Docker to run dockerized **client** and **server** apps for local dev
164
174
165
175
### Docker for Production Deployment
166
176
167
-
The following docker-compose commands build small client and server images targeted for creating optimized dockerized apps running on self-managed production servers. Hot reload is not available when editing source codes from `/client/src` or `/server/src`.
177
+
#### Option #1 - Client and Server as (2) Separate Images and Services
178
+
179
+
The following docker-compose commands build small `client` and `server` images targeted for creating optimized dockerized apps running on self-managed production servers. An **Nginx** service serves the frontend `client` on port `3000`. The `server`, running on a separate **Nodejs (pm2)** service, is also served by the client's Nginx service in a reverse proxy on port `3001`. Hot reload is not available when editing source codes from `/client/src` or `/server/src`.
168
180
169
181
1. Install and set up the required **client** and **server** environment variables as with the required variables on [**Docker for Localhost Development**](#docker-for-localhost-development).
170
182
2. Build the client and server docker services for production deployment.
3. At this point, we can opt to push the docker images to a docker registry of your choice. (Requires sign-in to the selected docker registry).
173
-
-`docker-compose -f docker-compose-prod.yml push`
174
-
4. Create and start the client and server containers.
175
-
`docker-compose -f docker-compose-prod.yml up`
176
-
5. Run a script in the container to create the default `[email protected]` account, if it does not yet exist in the Firestore database.
177
-
`docker exec -it server-prod npm run seed`
178
-
6. Launch the dockerized (prod) client app on
184
+
3. Create and start the containers.
185
+
-`docker-compose -f docker-compose-prod.yml up`
186
+
4. Run a script in the container to create the default `[email protected]` account, if it does not yet exist in the Firestore database.
187
+
-`docker exec -it server-prod npm run seed`
188
+
5. Launch the dockerized (prod) client app on
189
+
`http://localhost:3000`
190
+
6. Launch the dockerized (prod) server app's API documentation on
191
+
`http://localhost:3001/docs`
192
+
7. Stop and remove containers, networks, images and volumes:
193
+
-`docker-compose -f docker-compose-prod.yml down`
194
+
195
+
#### Option #2 - Client and Server Bundled in (1) Image and Service
196
+
197
+
The following docker-compose commands build a small `server` image targeted for creating an optimized dockerized Express app running on self-managed production servers. The frontend `client` is served in an a static directory using the Express static middleware.
198
+
199
+
1. Install and set up the required **client** and **server** environment variables as with the required variables on [**Docker for Localhost Development**](#docker-for-localhost-development).
200
+
-> **INFO:** This build method requires CORS checking dissabled, since the client and server will run on the same port (3001).
201
+
> - Disable CORS by setting `ALLOW_CORS=0` in the **.env** file to avoid `Same Origin` errors.
202
+
2. Build the client and server docker services for production deployment.
203
+
-`docker-compose -f docker-compose-app.yml build`
204
+
3. Create and start the containers.
205
+
-`docker-compose -f docker-compose-app.yml up`
206
+
4. Run a script in the container to create the default `[email protected]` account, if it does not yet exist in the Firestore database.
207
+
-`docker exec -it firebase-users-admin-app npm run seed`
208
+
5. Launch the dockerized (prod) client + server app on
179
209
`http://localhost:3000`
180
-
7. Launch the dockerized (prod) server app's API documentation on
210
+
6. Launch the dockerized (prod) client + server app API documentation on
181
211
`http://localhost:3001/docs`
182
-
8. Stop and remove containers, networks, images and volumes:
183
-
`docker-compose -f docker-compose-prod.yml down`
212
+
7. Stop and remove containers, networks, images and volumes:
213
+
-`docker-compose -f docker-compose-app.yml down`
184
214
185
215
## Pre-built Server Docker Image
186
216
187
-
**firebase-users-admin**'s `server` component is available as a stand-alone docker image on Docker Hub with customizable environment variables (.env file).
217
+
The `server` component of **firebase-users-admin** is available as a stand-alone docker image on Docker Hub with customizable environment variables (.env file).
188
218
189
-
1. Pull the (production) **/server** docker image from Docker Hub.
The server also serves the pre-built `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**](#option-2---client-and-server-bundled-in-1-image-and-service).
220
+
221
+
### Steps
222
+
223
+
1. Pull the (production) **/server**[docker image](https://hub.docker.com/repository/docker/ciatphdev/firebase-users-admin-app) from Docker Hub.
- Read [**Installation - server #3**](#server) for more information.
193
-
- Replace the variables accordingly in the `.env` file.
227
+
- 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.
0 commit comments