This project for task management based on Django and Django REST Framework.
- Docker (https://docs.docker.com/get-docker/)
- Docker Compose (https://docs.docker.com/compose/install/)
- Python 3.x (for local development) (https://www.python.org/downloads/)
-
Clone the repository:
git clone https://github.com/Diyarbekoralbaev/ustudy-test-task.git cd ustudy-test-task
-
Create a
.env
file in the project root with the following content:SECRET_KEY=diyarbed54861e74d7fe449d874a2c2bb499c1af321f8458a354256f72fcff3d4cf83 DEBUG=True ALLOWED_HOSTS=* CORS_ALLOW_ALL_ORIGINS=True TIME_ZONE=Asia/Tashkent DB_HOST=ustudy_test_task_db DB_NAME=ustudy_task DB_USER=postgres DB_PASSWORD=02052005 DB_PORT=5432 ACCESS_TOKEN_LIFETIME=60 REFRESH_TOKEN_LIFETIME=1440 PROJECT_PORT=8000 DEPLOYMENT_URL=http://localhost:8000
Note: The
PROJECT_PORT
variable is used to specify the port on which the application will run locally. -
Install the required Python packages:
sudo apt install pipx && pipx install invoke && sudo pipx ensurepath && pipx runpip invoke install rich
This project uses Invoke to manage tasks. Here are the available commands:
invoke setup
: Set up the application (build, start, and prepare)invoke build
: Build Docker imagesinvoke start
: Start Docker containersinvoke stop
: Stop Docker containersinvoke restart
: Restart Docker containersinvoke remove
: Remove Docker containersinvoke purge
: Purge the full environment (stop containers, remove volumes, images, and orphans)
invoke prepare
: Prepare the application (apply migrations and collect static files)invoke backupdb
: Backup the databaseinvoke restoredb
: Restore the database from a backupinvoke demodb
: Load demo datainvoke cleardb
: Clear the database
invoke test
: Run testsinvoke logs [--tail=10] [--follow] [--container=<container_name>]
: Fetch logs from Docker containers--tail
: Number of lines to show from the end of the logs (default: 10)--follow
: Follow log output (default: True)--container
: Specify container(s) to fetch logs from (comma-separated for multiple)
invoke webshell
: Access the Django shell
To run a command, use:
invoke <command-name>
For example, to set up the application:
invoke setup
invoke -l
: List all available tasksinvoke --help <task-name>
: Show help for a specific task
setup
: This task runsbuild
,start
, andprepare
in sequence to fully set up the application.build
: Builds the Docker images defined in your docker-compose.yml file.start
: Starts the Docker containers in detached mode.stop
: Stops the running Docker containers.restart
: Stops and then starts the Docker containers.remove
: Removes the Docker containers, networks, and volumes.purge
: Stops containers, removes containers, networks, volumes, and images created by docker-compose up.
prepare
: Runs database migrations, creates necessary database tables, and collects static files.backupdb
: Creates a backup of the current database state.restoredb
: Restores the database from the most recent backup.demodb
: Loads demo data into the database for testing purposes.cleardb
: Clears all data from the database and re-runs migrations.
test
: Runs the project's test suite.logs
: Displays the logs from the Docker containers. You can specify which container's logs to view and how many lines to display.webshell
: Opens an interactive Django shell for debugging and development purposes.
For local development, you can use the following workflow:
- Make your changes
- Set up the environment:
invoke setup
- Run tests:
invoke test
- If tests pass, commit your changes
To deploy the application:
- Set up the environment:
invoke setup
The application will be available at http://localhost:8000
(or the port specified in your .env file).
If you encounter any issues:
- Check the logs:
invoke logs
- Restart the containers:
invoke restart
- If problems persist, try purging the environment and setting up again:
invoke purge
followed byinvoke setup
For more information on each command, you can use invoke --help <command-name>
.
The .env
file contains important configuration for the project. Here's a brief explanation of each variable:
SECRET_KEY
: Django secret key for cryptographic signingDEBUG
: Set to True for development, False for productionALLOWED_HOSTS
: Hosts/domain names that this Django site can serveCORS_ALLOW_ALL_ORIGINS
: Allow all origins for CORS if set to TrueTIME_ZONE
: The time zone for the applicationDB_*
: Database connection detailsACCESS_TOKEN_LIFETIME
: Lifetime of access tokens in minutesREFRESH_TOKEN_LIFETIME
: Lifetime of refresh tokens in minutesPROJECT_PORT
: The port on which the application will run locallyDEPLOYMENT_URL
: The URL where the application is deployed
Make sure to adjust these variables according to your environment and requirements.