version: '3.8'

volumes:
  data:

services:
  db:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: 1234qwer
      MYSQL_DATABASE: shortener
      MYSQL_USER: shortener_user
      MYSQL_PASSWORD: 1234qwer
    volumes:
      - data:/var/lib/mysql
      - ./create.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "3306:3306"

  app:
    labels:
      - "TUSC The URL Shortener Company"
    #Build from docker hub image .Comment/Uncomment Below
    image: nmpl/shortener:latest

  # Build from local Dockerfile.Comment/Uncomment Below
  #  build:
  #    context: .
  #    dockerfile: Dockerfile

    healthcheck:
      test: [ "CMD-SHELL", "curl", "-f", "http://localhost:8080/monitoring" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    restart: unless-stopped

    ports:
      - "8080:8080"
    depends_on:
      - db

