version: '3.8'
name: sellrapido
services:

  mysql:
    image: mysql:8.0
    container_name: sr_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_ROOT_HOST: "%"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

  tomcat:
    image: tomcat:9.0.115-jdk17-temurin
    container_name: sr_tomcat
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    ports:
      - "8081:8080"
    volumes:
      - ./wars/sr_company_client.war:/usr/local/tomcat/webapps/sr_company_client.war
      - ./wars/sr_company_ws.war:/usr/local/tomcat/webapps/sr_company_ws.war
      - ./jar/mariadb-java-client-3.5.3.jar:/usr/local/tomcat/lib/mariadb-java-client-3.5.3.jar
      - ./jar/mysql-connector-java-5.1.49.jar:/usr/local/tomcat/lib/mysql-connector-java-5.1.49.jar
      - tomcat_logs:/usr/local/tomcat/logs
    environment:
      DB_HOST: mysql
      DB_PORT: 3306
      DB_USER: sr_mysql_user
      DB_PASSWORD: sr_mysql_user

volumes:
  mysql_data:
  tomcat_logs:
