Workout tracker
General Info
domain: 192.168.2.205:3000 Admin: 192.168.2.205:8000/config-panel
Database
Access database
run psql -h localhost -U flavoie workout to access the database
Backing up database
- run the bash script from the root directory of the project
source script/db-backup
A cronjob is created to run the backup script every day at midnight UTC
- run
crontab -lto see a list of all cron jobs - run
crontab -eto create a cronjob - cron schedule:
0 0 * * *which will run every day at midnight (UTC)
Copy backup file to MacBook
- run
scp pi@192.168.2.205:~/workout-tracker/BACKUP/db_backups/<file_name>.dump ~/dev/workout-tracker/BACKUP/db_backups/<file_name>.dump
Restoring database
In order to restore a DB dump locally, run the docker containers and stop the server container, or simply run the DB container on its own. Then, tun the following commands one at at time. Once done, restart the server container and run the frontend server to access the app locally and see the data.
- run
dropdb -h localhost -U flavoie workoutto delete the database "workout" - run
createdb -h localhost -U flavoie -T template0 workoutto recreate the "workout" database - run
pg_restore -h localhost -U flavoie -d workout BACKUP/db_backups/<file_name>.dumpto restore all the data
Client
The following notes relate to the front end React code
Update front end code in production
- build the static files locally by running
yarn build - run the frontend server by running
yarn prod
Server
Update back end code in production
- pull the changes from github
- navigate into the
/serverdirectory and rundocker-compose stop - run
docker-compose up -d --build serverto rebuild the django web server image. This will not rebuild the postgres image which is critical
Local Development
When working in the code base, run the virtual environment before opening the code in VSCode to get the proper python interpreter to provide the paths to the packages.
Run virtual environment
- run
source venv/bin/activate - If running the project for the first time, run
pip install -r server/requirements.txt
Stop virtual environment
run deactivate to stop the virtual environment
Run front end server
- navigate to
/client/and runyarn start
Run back end server
- navigate to
/server/and rundocker-compose upordocker-compose up -d - alternatively, you can run
docker exec web python manage.py runserverif the container is running already
Check security of settings
run docker exec web python manage.py check --deploy
Working with Docker
- run
docker logs -f <container_id>to see the server logs api endpoints are hit - run
docker-compose up -d --buildto build the images - run
docker-compose exec web python manage.py migrateto run the migration in the database - run
docker-compose exec web python manage.py createsuperuserto create the superuser -
run
docker-compose exec web python manage.py collectstaticto create the static files for the admin panel and the rest-framework -
run
docker-compose build --no-cache <service_name>to rebuild a service when changes occur