version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ..:/workspace:cached

    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity

    # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
    network_mode: service:db

  db:
    image: yobasystems/alpine-mariadb:10.6
    volumes:
      - photosmariadb-data:/var/lib/mysql
      - ./dbinit:/docker-entrypoint-initdb.d:ro
    environment:
      MYSQL_DATABASE: photosdb
      MYSQL_USER: photosuser
      MYSQL_PASSWORD: photospass
      MYSQL_ROOT_PASSWORD: photosroot
    healthcheck:
      test: "mysql $$MYSQL_DATABASE -u$$MYSQL_USER -p$$MYSQL_PASSWORD -e 'SELECT 1;'"
      interval: 10s
      timeout: 10s
      retries: 10

volumes:
  photosmariadb-data:
