|
4 | 4 |
|
5 | 5 | A basic web app client in the **/client** directory will show basic API usage and demonstration. |
6 | 6 |
|
| 7 | +## Content |
| 8 | + |
| 9 | +- [Requirements](#requirements) |
| 10 | +- [Installation](#installation) |
| 11 | +- [Usage](#usage) |
| 12 | +- [Available Scripts - server](#available-scripts---server) |
| 13 | +- [Installation and Usage Using Docker](#installation-and-usage-using-docker) |
| 14 | + - [Docker for Localhost Development](#docker-for-localhost-development) |
| 15 | + - [Docker for Production Deployment](#docker-for-production-deployment) |
| 16 | +- [References](#references) |
| 17 | + |
7 | 18 | ## Requirements |
8 | 19 |
|
9 | 20 | 1. Windows 10, MacOS, Linux |
@@ -57,6 +68,7 @@ A basic web app client in the **/client** directory will show basic API usage an |
57 | 68 | - You can find this file in a Firebase project's |
58 | 69 | **Project Settings** -> **General** -> **Web apps** (Add an app if needed) -> **SDK setup and configuration** |
59 | 70 | 3. Create a `/client/.env` file from the `/client/.env.example` file. |
| 71 | + - The `firebase.config.js` settings must match with the `FIREBASE_SERVICE_ACC` environment variable provided on **server - step # 3.** |
60 | 72 | - Replace `REACT_APP_BASE_URL` with the domain on which the CRUD API is running (default value is `http://localhost:3001/api` on localhost. See the [server](#server) set-up instructions for more information). |
61 | 73 | 4. Run the app in development mode. |
62 | 74 | `npm start` |
@@ -85,7 +97,6 @@ A basic web app client in the **/client** directory will show basic API usage an |
85 | 97 | - Try signing in these users to the `/client` app. |
86 | 98 | - > **NOTE:** Comment out the `cors` options line `app.use(cors(corsOptions))` on **/server/src/index.js** when testing on Postman and other http clients other than the `/client` app. |
87 | 99 |
|
88 | | - |
89 | 100 | ## Available Scripts - server |
90 | 101 |
|
91 | 102 | The npm scripts listed below are available under the **/server** directory. |
@@ -124,5 +135,52 @@ Copies the built `/client` website from `/client/build` to the server's root dir |
124 | 135 | ``` |
125 | 136 | - The built client app will be viewable on `http://localhost:3001` if the server is running. |
126 | 137 |
|
| 138 | + |
| 139 | +## Installation and Usage Using Docker |
| 140 | + |
| 141 | +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 | + |
| 143 | +### Docker for Localhost Development |
| 144 | + |
| 145 | +1. Set-up the environment variables and firebase configuration file for the **/client** app. |
| 146 | + - Create (your own) `firebase.config.js` file under `/client/utils/firebase/firebase.config.js` as advised on [**Installation - client # 2**](#client). |
| 147 | + - Create the `.env` file under the **/client** directory as advised on [**Installation - client # 3**](#client). |
| 148 | +2. Set-up the environment variables for the **/server** app. |
| 149 | + - Create the `.env` file under the **/server** directory as advised on [**Installation - server # 3**](#server). |
| 150 | +3. Build the client and server docker services for localhost development. |
| 151 | + - `docker-compose -f docker-compose-dev.yml build` |
| 152 | + - > **INFO:** Building the images for localhost development takes a while, around ~7min+. |
| 153 | +4. Create and start the client and server containers. |
| 154 | +`docker-compose -f docker-compose-dev.yml up` |
| 155 | +5. Launch the dockerized (dev) client app on |
| 156 | +`http://localhost:3000` |
| 157 | +6. Launch the dockerized (dev) server app's API documentation on |
| 158 | +`http://localhost:3001/docs` |
| 159 | +7. Edit source the codes in `/client/src` or `/server/src` as needed. Verify that hot reload is working on both the client and server apps. |
| 160 | +8. Stop and remove containers, networks, images and volumes: |
| 161 | +`docker-compose -f docker-compose-dev.yml down` |
| 162 | + |
| 163 | +### Docker for Production Deployment |
| 164 | + |
| 165 | +The following docker-compose commands build small client and server images targeted for creating optimized dockerized apps running on production servers. Hot reload is not available when editing source codes from `/client/src` or `/server/src`. |
| 166 | + |
| 167 | +1. Install and set up the required environment variables as with the required variables on **Docker for Localhost Development**. |
| 168 | +2. Build the client and server docker services for production deployment. |
| 169 | + - `docker-compose -f docker-compose-prod.yml build` |
| 170 | +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). |
| 171 | + - `docker-compose -f docker-compose-prod.yml push` |
| 172 | +4. Create and start the client and server containers. |
| 173 | +`docker-compose -f docker-compose-prod.yml up` |
| 174 | +5. Launch the dockerized (prod) client app on |
| 175 | +`http://localhost:3000` |
| 176 | +6. Launch the dockerized (prod) server app's API documentation on |
| 177 | +`http://localhost:3001/docs` |
| 178 | +7. Stop and remove containers, networks, images and volumes: |
| 179 | +`docker-compose -f docker-compose-prod.yml down` |
| 180 | + |
| 181 | +## References |
| 182 | + |
| 183 | +[[1]](https://docs.docker.com/compose/reference/) - docker compose commands |
| 184 | + |
127 | 185 | @ciatph |
128 | 186 | 20220406 |
0 commit comments