You'll need to install Docker and NodeJS + NPM.
Follow this guide to install Docker: https://docs.docker.com/get-docker/
- If on Windows 10 Home, you'll need to first enable WSL 2
- If you're on Windows / macOS, follow Docker Desktop's "Getting Started" guide. It'll introduce you to the basics of Docker and give you an easy way to verify it's correctly installed.
Install NodeJS 16 LTS from here: https://nodejs.org/en/
Prior to cloning the repo, ensure you have registered your SSH key with GitLab (out of the scope of this guide).
Then run:
git clone https://csil-git1.cs.surrey.sfu.ca/415-cradle-sl/cradle-platform.git
#This had issues with the requirements.txt (try the link above)
(previously : https://csil-git1.cs.surrey.sfu.ca/415-cradle/cradle-platform.git)
Create a file named .env (extension only file) in the cradle-platform directory containing the following:
JWT_SECRET_KEY=[A_SECRET_KEY]
DB_USERNAME=[A_DATABASE_USERNAME]
DB_PASSWORD=[A_DATABASE_PASSWORD]
LIMITER_DISABLED=[True to disable or False to enable]
For example:
JWT_SECRET_KEY=supersecretkey
DB_USERNAME=user
DB_PASSWORD=abcd1234
LIMITER_DISABLED=True
Note you may set these to any arbitrary values.
In case connecting with cradle-sms-relay is needed, you should append your emulator's phone number to the .env file.
For example, add this line at the end of the lines mentioned above:
EMULATOR_PHONE_NUMBER=[PHONE_NUMBER_OF_EMULATOR_RUNNING_CRADLE_MOBILE_APP]
Your emulator's phone number will very likely be 5555215554 or 5555215556. The former is assigned to the first emulator that starts. The latter is assigned to the second emulator that starts.
At the time of writing this, the CRADLE Mobile app does not have the option to send the SMS messages to 5555215556. This means that the CRADLE Mobile app should be opened second, after opening the SMS Relay App. And therefore, the emulator phone number environment variable value should be 5555215556. Like so:
EMULATOR_PHONE_NUMBER=5555215556
Or in full:
JWT_SECRET_KEY=supersecretkey
DB_USERNAME=user
DB_PASSWORD=abcd1234
LIMITER_DISABLED=True
EMULATOR_PHONE_NUMBER=5555215556
From your OS's terminal (such as PowerShell in Windows) run:
docker compose up
All the Docker images will build and then the Docker containers will start. You may add the -d option to run the Docker containers in the background, although that makes it more difficult to see log messages from Flask and MySQL.
(If the Docker can not run properly, try close the mysql tasks in the task manager and run it again)
Now it's time to run the database migrations. Once the containers have fully started, run the following command in a new terminal window.
docker exec cradle_flask flask db upgrade
Data seeding is handled by the manage.py script in the server directory. There are 3 data seeding options which give various amounts of data:
seed_minimal: seeds the bare minimum amount of data to get the application running, useful if you want to debug something without having to trudge through unrelated dataseed_test_data: seeds data required to run the unit testsseed: seeds a generous amount of random data
In order to seed data, run docker exec cradle_flask python manage.py [SEED_OPTION] where [SEED_OPTION] is one of the options listed above. For example:
docker exec cradle_flask python manage.py seed_test_data
NPM is not run inside Docker (due to poor filesystem performance), so you'll need to run the following to start the NPM development server:
(Make sure you have NPM 7)
cd client
npm install
npm start
- Navigate to http://localhost:3000/ to check out the React client running in your browser, communicating to the server hosted at http://localhost:5000/ which is communicating with MySQL!
- You will be able work on the client-side and server-side code, all while being able to enjoy hot-reloading!
-
Make sure to check out the API documentation at http://localhost:5000/apidocs
-
Once the initial setup is completed, you'll only need to run
docker-compose upin thecradle-platformdirectory andnpm startin the client directory to run Cradle. -
If using Docker Desktop, you may also start / restart / stop the containers from within the GUI.
In order to pass the pipeline (and for readability) your code must be properly formatted.
Frontend code is formatted using Prettier and must pass ESLint. Run npm run format in the client directory to format all frontend files and run a lint check.
Backend code is formatted using Black. With your Docker containers running, run docker exec cradle_flask black . to format all backend files.
It's always best to avoid adding additional dependencies to the project if possible. Try to use existing packages rather than installing a new one.
- New packages can be installed in the frontend by running
npm install PACKAGE_NAMEin theclientfolder - If another team member has installed a new package, you'll need to run
npm install
- New packages can be installed in the backend by running
docker exec cradle_flask pip install PACKAGE_NAMEwith your Docker containers running - If another team member has installed a new package, you'll need to run
docker-compose buildwith your Docker containers off
-
If working on the backend, when you make database changes you'll need to create migrations: run
docker exec cradle_flask flask db migrateto do so -
If database changes have been made (by you or other team members), run
docker exec cradle_flask flask db upgradeto upgrade your database schema
If something has gone wrong and you're having issues with your database, you can always wipe it and reseed. To do so, with your Docker containers off:
- Run
docker container ls -aand look for a container namedcradle_mysqlor similar - Remove the container by running
docker container rm cradle_mysql(using the container name identified above) - Run
docker volume lsand look for the volume associated with the MySQL database. It's likely namedcradle-platform_mysql_dataor something similar - Remove the Docker volume:
docker volume rm 415-cradle-platform_mysql_data(using the volume name identified above) - Start your Docker containers:
docker-compose up - Upgrade your daabase schema:
docker exec cradle_flask flask db upgrade - Reseed:
docker exec cradle_flask python manage.py seed(see setup above for more seed options)
- Postman:
- Used to test API endpoints and send HTTP requests with a GUI
- Check out the Postman Workspace Setup Guide for how to set up the Postman Workspaces to begin testing the project REST APIs
- React Developer Tools
- allows you to observe what components make up the webpage/DOM
- allows you to observe the live values of props and state in components
- Redux DevTools
- allows you to view and debug how data is being passed to and from Redux