|
| 1 | +# Planet Development Setup Tutorial |
| 2 | + |
| 3 | +## Objectives |
| 4 | + |
| 5 | +- Learn about running the Planet development environment |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +For development, the following additional tools are required: |
| 10 | + |
| 11 | +- Node.js v14 |
| 12 | +- Angular CLI v10 |
| 13 | + |
| 14 | +### Node.js |
| 15 | + |
| 16 | +[**Node.js**](https://nodejs.org) is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. |
| 17 | + |
| 18 | +1. Check if Node.js is already installed by running `node -v` in your terminal or Git Bash. If the output starts with `v14.`, you can skip the rest and proceed to "Angular CLI." |
| 19 | +2. Check if you have a Node.js environment manager, such as `nvm` or `fnm`, by running `nvm -v` and `fnm -v`. If installed, use `nvm install 14` or `fnm use --install-if-missing 14` to install Node.js 14. |
| 20 | +3. If neither is installed, you can install Node.js v14 by visiting [**Node.js — Download Node.js**](https://nodejs.org/en/download/package-manager): |
| 21 | + 1. In the first dropdown, select version `v14.*.*` |
| 22 | + 2. In the second dropdown, select your operating system. |
| 23 | + 3. In the third dropdown: |
| 24 | + - For Linux, select `nvm` |
| 25 | + - For Windows, select `fnm` |
| 26 | + - For macOS, select `fnm` |
| 27 | + 4. Follow the instruction to install node.js v14 onto your system |
| 28 | + |
| 29 | +### Angular CLI |
| 30 | + |
| 31 | +[**Angular CLI**](https://cli.angular.io) is a command-line interface for Angular. After installing node 14, run `npm install -g @angular/cli@10` to install Angular CLI v10. |
| 32 | + |
| 33 | +## Introduction |
| 34 | + |
| 35 | +After setting up the production server for Planet, we will now configure the development environment and server. This will allow you to make changes to the code and see the results in real-time. |
| 36 | + |
| 37 | +To ensure all required software is installed, run the following commands: |
| 38 | + |
| 39 | +- `docker -v` - Should display Docker version |
| 40 | +- `git -v` - Should display git version |
| 41 | +- `node -v` - Should display "v14.*" |
| 42 | +- `npm -v` - Should display "v6.*" |
| 43 | +- `ng version` - Should display "Angular CLI: 10.*" |
| 44 | + |
| 45 | +## Container Setup |
| 46 | + |
| 47 | +1. Create a `planetdev` directory for the planet dev data: |
| 48 | + - **Linux**: |
| 49 | + ```bash |
| 50 | + mkdir -p /srv/planetdev && cd /srv/planetdev |
| 51 | + ``` |
| 52 | + - **macOS/Windows**: |
| 53 | + ```bash |
| 54 | + mkdir -p ~/srv/planetdev && cd ~/srv/planetdev |
| 55 | + ``` |
| 56 | +2. Configure the necessary environment variables: |
| 57 | + - `echo "OPENAI_API_KEY=APIKEYHERE" > .chat.env` |
| 58 | + - `echo "PERPLEXITY_API_KEY=APIKEYHERE" >> .chat.env` |
| 59 | + - *Note*: Don't worry about the actual API keys for now, we will generate them for you if you work on related features. |
| 60 | +3. Download the development yml file: |
| 61 | + - **Linux**: |
| 62 | + ```bash |
| 63 | + wget https://raw.githubusercontent.com/ole-vi/planet-prod-configs/main/planet-dev.yml |
| 64 | + ``` |
| 65 | + - **macOS/Windows**: |
| 66 | + ```bash |
| 67 | + curl https://gist.githubusercontent.com/xyb994/0d14dfe302df0df0d4e8d8df0d1d5feb/raw/planet-dev-mac.yml -o planet-dev.yml |
| 68 | + ``` |
| 69 | +4. Start the containers: `docker compose -f planet-dev.yml -p planet-dev up -d` |
| 70 | +5. After a minute, run `docker ps -a` to verify that you have 2 runnning containers – `chatapi` and `couchdb`, the `db-init` container should have exited. |
| 71 | +
|
| 72 | +## Configure CORS for CouchDB with add-cors-to-couchdb project: |
| 73 | +
|
| 74 | +We use the [Add Cors to CouchDB](https://github.com/pouchdb/add-cors-to-couchdb) project to enable CORS on the CouchDB server. This is necessary for the Planet project to work correctly. We only need this for initialization purposes. |
| 75 | +
|
| 76 | +```bash |
| 77 | +# change directory to the dedicated ole folder you created in Step 1's "Preparation" section |
| 78 | +# this is just an example |
| 79 | +cd ~/Documents/ole |
| 80 | + |
| 81 | +# clone Add Cors to CouchDB repository |
| 82 | +git clone https://github.com/pouchdb/add-cors-to-couchdb.git |
| 83 | + |
| 84 | +# cd into the repo folder and install required node modules for this project |
| 85 | +cd add-cors-to-couchdb |
| 86 | +npm install |
| 87 | + |
| 88 | +# ensure couchdb docker service is up and running then update CouchDB with CORS settings |
| 89 | +while ! curl -X GET http://127.0.0.1:2200/_all_dbs ; do sleep 1; done |
| 90 | +node bin.js http://localhost:2200 |
| 91 | +``` |
| 92 | + |
| 93 | +## Configure the Planet project: |
| 94 | + |
| 95 | +```bash |
| 96 | +# ensure that `couchdb` and the `chatapi` containers are running before proceeding. |
| 97 | +docker ps -a |
| 98 | + |
| 99 | +# go back to your dedicated ole folder |
| 100 | +cd .. |
| 101 | + |
| 102 | +# clone ole's planet repository |
| 103 | +git clone https://github.com/open-learning-exchange/planet.git |
| 104 | +cd planet |
| 105 | + |
| 106 | +# adjust the logging configuration and authentication settings of the CouchDB service |
| 107 | +curl -X PUT http://localhost:2200/_node/nonode@nohost/_config/log/file -d '"/opt/couchdb/var/log/couch.log"' |
| 108 | +curl -X PUT http://localhost:2200/_node/nonode@nohost/_config/log/writer -d '"file"' |
| 109 | +curl -X PUT http://localhost:2200/_node/nonode@nohost/_config/chttpd/authentication_handlers -d '"{chttpd_auth, cookie_authentication_handler}, {chttpd_auth, proxy_authentication_handler}, {chttpd_auth, default_authentication_handler}"' |
| 110 | + |
| 111 | +# run the couchdb-setup.sh script to set up the couchdb database for the planet project |
| 112 | +chmod +x couchdb-setup.sh |
| 113 | +bash couchdb-setup.sh -p 2200 -i |
| 114 | + |
| 115 | +#### Troubleshooting #### |
| 116 | +# If you encounter permission issues, run the command below, |
| 117 | +# replacing `username` and `password` with your preferred credentials. |
| 118 | +# Be sure to save these credentials, as you'll need them to access CouchDB through the Fauxton interface (`localhost:2200/_utils`). |
| 119 | +bash couchdb-setup.sh -p 2200 -i -u "username" -w "password" |
| 120 | +``` |
| 121 | + |
| 122 | +Install dependecies and serve the app |
| 123 | + |
| 124 | +- `npm install` |
| 125 | + - **Note**: This step may take longer than expected based on recent experiences. If the installation progress seems stuck, we recommend leaving it running in the background and checking back after 30 minutes to see if it has progressed. Once the installation is complete, it should display the total time taken. Please share how long it took in the `#vi-software` Discord channel. |
| 126 | +This version emphasizes clarity and readability while retaining the original message. |
| 127 | +- `ng serve` |
| 128 | +- Visit <localhost:3000> to access the planet app |
| 129 | +- Similarly to [Step 2.2 - Planet Configurations](vi-planet-configurations.md#Configure_Your_Planet_Community), you’ll need to configure a new planet community with a slightly modified name (e.g., `<YourUserName>dev`). |
| 130 | +- Take a screenshot of the new configuration page and post it in the #vi-software channel on our Discord server. |
| 131 | + |
| 132 | +## Service Ports |
| 133 | + |
| 134 | +**Note**: The port numbers for the development and production servers are different |
| 135 | + |
| 136 | +||**production**|**development**| |
| 137 | +|---|--------------|---------------| |
| 138 | +| *planet* | 3300 | 3000 | |
| 139 | +| *chatapi* | 5050 | 5000 (5400 for mac/windows) | |
| 140 | +| *couchdb* | 2300 | 2200 | |
0 commit comments