# version of docker-compose
version: '3.6'

volumes:
  cache:
    driver: local

# list of containers
services:
  db:
    image: mysql
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    # (this is just an example, not intended to be a production configuration)
    # command: --default-authentication-plugin=mysql_native_password && /bin/sh -c "./init-scripts/db-init.sh"
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: Edgewebware13!
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  keystone:
    image: "node:18-alpine"
    user: "node"
    depends_on:
      db:
        condition: service_healthy
    environment:
      - NODE_ENV=development
      - DATABASE_URL=mysql://root:Edgewebware13!@db:3306/keystone
      - NEXT_CACHE_VALIDATION_KEY=I_GOT_THE_BEETIS
      - FRONTEND_CACHE_CLEAR_URL=http://next:3000/api/revalidate
      - FRONTEND_URL=http://localhost:3000
      - BASE_URL=http://keystone:3001
      - HTTP_AUTH_USERNAME=
      - HTTP_AUTH_PASSWORD=
      - NEXT_AUTHENTICATION_KEY=_NEXT_SECRETY_KEY_04222024
    working_dir: /home/keystone
    volumes:
      - ./projects/keystone:/home/keystone
      - ./projects/dependencies:/home/dependencies
      - ./init-scripts:/home/keystone/init-scripts
    ports:
      - "3001:3001"
    command: /bin/sh -c "./init-scripts/keystone-init.sh"

  next:
    image: "node:18-alpine"
    user: "node"
    depends_on:
      keystone:
        condition: service_started
    environment:
      - NODE_ENV=development
      - KEYSTONE_IMAGE_DOMAIN=keystone
      - KEYSTONE_PORT=3001
      - NEXT_PUBLIC_KEYSTONE_API_URL=http://keystone:3001/api/graphql
      - CACHE_REVALIDATE_SECRET=I_GOT_THE_BEETIS
      - FONTAWESOME_PACKAGE_TOKEN=${FONTAWESOME_PACKAGE_TOKEN}
      - NEXT_KEYSTONE_AUTH_KEY=_NEXT_SECRETY_KEY_04222024
    working_dir: /home/next
    volumes:
      - ./projects/next:/home/next
      - ./projects/dependencies:/home/dependencies
      - ./init-scripts:/home/next/init-scripts
    ports:
      - "3000:3000"
    command: /bin/sh -c "./init-scripts/next-init.sh"
    