version: "3.1"
#name: gw02-mysql
services:
  db:
    image: mariadb
    hostname: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: Kc8P4h573W67Dd
      MYSQL_USER: cart # GRANT ALL PRIVILEGES ON database.* TO 'user'@'%' IDENTIFIED BY 'password';
      MYSQL_PASSWORD: cartpw2024
      MYSQL_DATABASE: cart # This will create a database named 'cart'
    stdin_open: true
    tty: true
    ports:
      - 3307:3306
    volumes:
      - /mnt/data/apps/docker_volumes/cart/database:/var/lib/mysql
    # command: >
    #   sh -c '
    #   export MYSQL_ROOT_PASSWORD=$$(openssl rand -base64 12);
    #   echo "Generated MariaDB root password: $$MYSQL_ROOT_PASSWORD";
    #   docker-entrypoint.sh mysqld
    #   '
  adminer:
    image: adminer
    restart: always
    environment:
      - PHP_INI_UPLOAD_MAX_FILESIZE=500M
      - PHP_INI_POST_MAX_SIZE=500M
    ports:
      - 8083:8080

  # THE APP
  nextjs-app:
    image: sachinvashist/nextjs-docker
    ports:
      - "8005:8005"
    volumes:
      - /mnt/data/apps/docker_volumes/cart/app:/app
    environment:
      - NODE_ENV=demo
      - DATABASE=mysql://cart:cartpw2024@mariadb:3306/cart
    #! entrypoint: ["/bin/sh", "/entrypoint.sh"]
    #run: npm install && npx prisma generate && npm run test;
    # command: "npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start"
    # command: "npx prisma migrate resolve --applied 20231227185411_remove_email_unique_constraint && npx prisma migrate deploy &&  npx prisma migrate deploy && npm run build && npm run start"
    #command: /bin/sh -c "npm install && npx prisma generate && npm run test" # Install dependencies and start the app
    command: "npm run test"
    # command: >
    #   /bin/sh -c "
    #     apt-get update && apt-get install -y git || exit 1;
    #     if [ ! -d '/app/.git' ]; then
    #       echo 'Cloning stable branch from git.d-popov.com...';
    #       git clone -b stable https://git.d-popov.com/repository.git /app || exit 1;
    #     fi;
    #     cd /app;
    #     npm install && npx prisma migrate deploy && npm run build && npm run prod
    #   "
    tty: true
    stdin_open: true
    # depends_on:
    #   - mariadb
