services:
  web:
    build: .
    ports:
      - "${HTTP_PORT:-8080}:80"
    environment:
      DB_HOST: db
      DB_USER: root
      DB_PASS: ${MYSQL_ROOT_PASSWORD:-rootpass}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpass}
      MYSQL_USER: ${MYSQL_USER:-htdocs}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-htdocspass}
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/init:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-rootpass}"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 30s
    restart: unless-stopped

volumes:
  mysql_data:
