services:

  postgres:
    image: postgres
    ports:
      - 5433:5432
    environment:
      - POSTGRES_DB=consumo_gasolina
      - POSTGRES_PASSWORD=123456
    volumes:
      - db-data:/var/lib/postgresql/data
    deploy:
      placement:
        constraints: [node.role == manager]

  core:
    image: chiavegatto/consumo-gasolina-service
    ports:
      - 8000:8000
    env_file: consumo_gasolina.conf
    command: >-
              /bin/sh -c "./wait-for-it.sh -t 60 postgres:5432 -- echo 'postgres is up'
              && python -u manage.py migrate
              && python -u production-server.py"
    deploy:
      mode: replicated
      replicas: 2
      labels: [APP=API]
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.role == manager]

volumes:
  db-data:
