version: "3.9"

services:
  postgres:
    image: postgres:14.5
    container_name: flowbuild_db
    restart: always
    env_file:
      - ./.env.docker
    ports:
      - 5432:5432

  app:
    image: node:18.12
    env_file:
      - ./.env.docker
    container_name: flowbuild_app
    restart: on-failure:10 # necessary due to possibility of postgres not being ready when service runs
    depends_on:
      - postgres
    ports:
      - 3000:3000
    volumes:
      - .:/usr/app
      - /usr/app/node_modules
    working_dir: /usr/app
    #command: ./scripts/start_dev.sh
    #command: bash -c " npm update && npm install knex -g && npm install nodemon -g && npm install && npm rebuild && npm run migrations && npm run seeds && npm run start "
    command: bash -c " npm install && npm audit fix && npm run migrations && npm run seeds && npm run start "
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/healthcheck"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 60s   

  socket:
    image: hivemq/hivemq4:latest
    container_name: flowbuild_mqtt
    restart: on-failure:10
    ports:
      - 8081:8080
      - 1883:1883
      - 8000:8000

  # optional broker
  # rabbitmq:
  #   image: rabbitmq:3-management-alpine
  #   container_name: rabbitmq
  #   ports:
  #     - 5672:5672
  #     - 15672:15672

  redis:
    image: redis:7-bullseye
    container_name: flowbuild_redis
    restart: always
    ports:
      - 6379:6379