Installation
Here you will find the steps to set up the project. You can choose between a containerized approach using Docker (recommended) or running it Natively.
Docker Way¶
Create the Docker Compose file¶
Create a docker-compose.yml file and paste the following configuration:
services:
db: # (1)!
image: postgres:15-alpine
container_name: movies_db
restart: always
env_file:
- .env # (2)!
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data # (3)!
healthcheck: # (4)!
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 5s
timeout: 5s
retries: 5
api: # (5)!
image: moviesxmovies/backend:latest # (6)!
container_name: movies_api
restart: always # (7)!
pull_policy: always # (8)!
env_file:
- .env # (9)!
ports:
- "7996:7996" # (10)!
depends_on:
db: # (11)!
condition: service_healthy
volumes: # (12)!
- static_data:/app/staticfiles
- media_data:/app/media
redis: # (21)!
image: redis:7-alpine # (22)!
container_name: movies_redis
restart: always
healthcheck:
test: ["CMD", "redis-cli", "ping"] # (23)!
interval: 5s
timeout: 3s
retries: 5
worker: # (24)!
image: moviesxmovies/backend:latest # (25)!
restart: always
pull_policy: always
command: python manage.py rqworker default # (26)!
env_file:
- .env
depends_on: # (27)!
db:
condition: service_healthy
redis:
condition: service_healthy
volumes: # (28)!
- static_data:/app/staticfiles
- media_data:/app/media
web: # (13)!
image: moviesxmovies/frontend:latest
container_name: movies_frontend
restart: always # (14)!
pull_policy: always # (15)!
volumes: # (16)!
- frontend_data:/app
volumes:
postgres_data: # (17)!
static_data: # (18)!
driver: local
driver_opts:
type: none
o: bind
device: /var/www/moviesxmovies/static
media_data: # (19)!
driver: local
driver_opts:
type: none
o: bind
device: /var/www/moviesxmovies/media
frontend_data: # (20)!
driver: local
driver_opts:
type: none
o: bind
device: /var/www/moviesxmovies/app
- Creates a Postgres container as the database.
- Injects
.envas environment variables. - Links database files with a volume named
postgres_data. - Healthcheck to ensure the DB is up before other services start.
- Creates a container using the backend API image.
- Uses the
latesttag of our backend image. - Retries automatically if the launch fails.
- Pulls the image to keep it updated if there are upstream changes.
- Injects
.envas environment variables. - Maps port
7996of the host to port7996of the container. - Waits for the
dbcontainer to be healthy before starting up. - Links two volumes for static files and media files.
- Creates a container using the Frontend image.
- Retries automatically if the launch fails.
- Pulls the image to keep it updated.
- Links frontend files with the
frontend_datavolume. - Creates a volume for the database files.
- Creates a volume for static files mounted on a host directory.
- Creates a volume for media files mounted on a host directory.
- Creates a volume for frontend files mounted on a host directory.
- Creates a container using an alpine Redis image.
- Official Alpine Redis image.
- Healthcheck to verify Redis is ready.
- Creates a worker container (scalable if needed).
- Uses the backend image to get the latest code.
- Overrides the base command to run an
rqworker. - Ensures
dbandredisare up before the worker starts. - Mounts volumes to allow access to static and media data.
Verify Directories¶
Important Prerequisites
Before running Docker Compose, ensure the following directories exist on your machine and that the Docker user has ownership of them:
* /var/www/moviesxmovies/app
* /var/www/moviesxmovies/media
* /var/www/moviesxmovies/static
Setup Environment Variables¶
Create your own .env file using the following structure as a reference:
SECRET_KEY="any_key"
DEBUG=false
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0,192.168.0.13,moviesxmovies.jonaykb.com
DB_ENGINE=django.db.backends.postgresql
DB_NAME=db_name
DB_USER=db_user
DB_PASSWORD=bd_passowrd
DB_HOST=127.0.0.1
DB_PORT=5432
Execute¶
Run the following command to start all the necessary containers in detached mode:
Native¶
If you prefer to run the application natively, you need to set up the backend and frontend separately. Choose the environment you want to set up below:
Backend(API)¶
Clone the repository:¶
git clone [https://github.com/moviesxmovies/MoviesXMoviesBackend](https://github.com/moviesxmovies/MoviesXMoviesBackend)
cd MoviesXMoviesBackend
Environment Variables:¶
Open example.env and create a .env file, changing the variables as needed.
Setup:¶
Execute:¶
Using Just:
Using Django'smanage.py:
Frontend¶
Clone the repository:¶
git clone [https://github.com/moviesxmovies/MoviesXMoviesFrontend](https://github.com/moviesxmovies/MoviesXMoviesFrontend)
cd MoviesXMoviesFrontend
Environment Variables:¶
Open example.env and create a .env file, changing the variables as needed.
*#### Setup:
Execute:¶
Using Just:
Using npm:Accessing the Application¶
Once your preferred environment is up and running, you can access the different parts of the application using the following links:
| Service | URL |
|---|---|
| 🎨 Frontend | http://localhost:5173 |
| ⚙️ API Base | http://localhost:8000/api |
| 📚 Swagger Docs | http://localhost:8000/api/docs |