Skip to main content
Gestor de Torneos requires Python 3.12 and a MySQL 8 database. Docker Compose is the recommended way to run the full stack with a single command.

Environment variables

The application reads the following variables to connect to MySQL. Defaults match the values used in docker-compose.yml.
VariableDefaultDescription
DB_NAMEtfgDatabase name
DB_USERtfgDatabase user
DB_PASSWORDtfgDatabase password
DB_HOSTdbDatabase host
DB_PORT3306Database port
The default SECRET_KEY in config/settings.py and the credentials above are for development only. Replace them before deploying to any public environment.
1

Clone the repository

git clone https://github.com/raafaa22/gestor-de-torneos.git
cd gestor-de-torneos
2

Review docker-compose.yml

The compose file defines two services: a MySQL 8.4 database and the Django application.
docker-compose.yml
services:
  db:
    image: mysql:8.4
    container_name: tfg_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: tfg
      MYSQL_USER: tfg
      MYSQL_PASSWORD: tfg
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 10

  gestor_torneos:
    build: .
    container_name: gestor
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    environment:
      DB_NAME: tfg
      DB_USER: tfg
      DB_PASSWORD: tfg
      DB_HOST: db
      DB_PORT: "3306"
    command: sh -c "sleep infinity"

volumes:
  mysql_data:
The default command in docker-compose.yml is sleep infinity, which keeps the container running without starting the server. Override it or exec into the container to run the application manually (see next step).
3

Start the services

docker compose up --build
Docker Compose waits for the database health check to pass before starting the application container.
4

Run migrations and start the server

The Dockerfile’s default command runs migrations and starts the development server:
docker compose exec gestor_torneos sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
The application is now available at http://localhost:8000.

Manual local setup

1

Install system dependencies

The application requires the MySQL client library. On Debian/Ubuntu:
sudo apt-get install build-essential pkg-config default-libmysqlclient-dev gettext
2

Create a virtual environment and install packages

python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
Core dependencies from requirements.txt:
  • Django>=5.1,<5.2
  • gunicorn>=22.0
  • mysqlclient>=2.2
Development dependencies from requirements-dev.txt (pytest, pytest-django, pytest-cov) are only needed for running tests.
3

Configure environment variables

Export the database connection variables before running any Django commands:
export DB_NAME=your_db
export DB_USER=your_user
export DB_PASSWORD=your_password
export DB_HOST=127.0.0.1
export DB_PORT=3306
4

Run migrations and start the server

python manage.py migrate
python manage.py runserver 0.0.0.0:8000
The application will be available at http://localhost:8000.

Development vs production

The current configuration is set up for development. Before deploying to production, you must:
  • Set a strong, unique SECRET_KEY in your environment (replace the hardcoded value in config/settings.py).
  • Set DEBUG = False.
  • Restrict ALLOWED_HOSTS to your actual domain instead of ["*"].
  • Use a production-grade WSGI server such as gunicorn (already included in requirements.txt) instead of runserver.
  • Secure your database credentials.