version: "3.9"
   
services:
  db:
    image: postgres
    volumes:
      - database:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=werkout
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  web:
    build: .
    command: >
      sh -c "python manage.py collectstatic --noinput && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    environment:
      - POSTGRES_NAME=werkout
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    depends_on:
      db:
        condition: service_healthy
    links:
      - db

  redis:
    image: redis:alpine

  celery:
    restart: always
    build:
      context: .
    command: celery -A werkout_api worker -l info
    volumes:
      - .:/code
    environment:
      - DB_HOST=db
      - DB_NAME=werkout
      - DB_USER=postgres
      - DB_PASS=postgres
    depends_on:
      - db
      - redis
      - web

volumes:
  database: