cp .env-template .env
and edit environment variables- Run
./dev/setup_local_development.sh
from the root directory - Access Admier: http://localhost:8080/?pgsql=db&username=postgres
- Open RabbitMQ GUI: http://localhost:15672/. Default credentials are
guest
/guest
- Open the web app: http://localhost:3001/
It will run Postgres, Rabbit, Redis for caching requests, RedisInsights for a GUI for Redis, a REST API server and a web app.
Database backups are stored in the ~./pg_backup directory on the production server. To restore a database locally, run the ./dev/restore_db.sh
script.
Code is deployed using GitHub Actions. To deploy a new version, simply push a new tag following the semantic versioning format api-vX.Y.Z
(or app-vX.Y.Z
). The workflows are defined in .github/workflows
.
-
Update version info in
deployment/.dependencies
file. -
Tag and push your commit, this will trigger the GitHub Action workflow (replace
api
withapp
when needed)git tag api-vX.Y.Z git push origin api-vX.Y.Z
Workflows call deployment scripts on a production server. Deployment scripts are
deployment/deploy_api.sh
deployment/deploy_app.sh
Deployment scripts are not updated automatically, you need to update them manually. Deployment scripts are called using webhook
tool installed on the production server. Read more about webhook configuration in deployment/README.md
.
- Backup:
docker exec -ti spotify-grabtrack_db_1 pg_dump -U postgres -W -F c spotify -f /pg_backup/2022-03-31-backup.psql
- Restore:
docker exec -ti spotify-grabtrack_db_1 pg_restore -U postgres -d spotify /pg_backup/2022-03-30-backup.psql
Or
- Login to db Docker:
docker exec -ti spotify-grabtrack_db_1 bash --login
- Backup database:
pg_dump -U postgres -W -F c spotify > /pgdata/2022-03-31-backup.psql
- Restore:
pg_restore -U postgres -d pg_import_test /pgdata/2022-03-31-backup.psql
docker exec -ti spotify-grabtrack_db_1 bash --login
psql -U postgres
\connect postgres
ALTER DATABASE old_spotify RENAME TO spotify;
- Have the stack working (you need a running database)
docker-compose -f stack.yml up -d
docker build -t alembic-image ./db
docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic revision -m "Create indexes on tracks"
- Run migrations
docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic upgrade head
- Undo last migration
docker run -ti -v $(pwd)/db:/db --rm --network smartplaylist_network alembic-image alembic downgrade -1
Listeners are checking for Rabbit messages and downloading artist, album and track data from Spotify API.
- Get followed artists
docker run -ti --rm --network smartplaylist_network -p 8083:8083 -v $(pwd)/app/src:/app --env-file .env smartplaylist/app pipenv run python sync_followed_artists.py
- Run related artists listener:
docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_related_artists.py
- Get albums
docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_albums.py
- Get album details
docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_album_details.py
- Get track details
docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python get_track_details.py
- Update database stats
docker run -ti --network smartplaylist_network -v $(pwd)/app/src:/app --env-file .env --rm smartplaylist/app pipenv run python update_db_stats.py
After running sync_followed_artists.py
you will be asked to open an URL and paste the URL you were redirected to to obtain the oAuth token.
Remember, your Spotify Developer application in https://developer.spotify.com/dashboard/applications needs to have "Redirect URI" configured and same with env SPOTIPY_REDIRECT_URI