version: "3"

services:
  web:
    image: registry.firefish.dev/firefish/firefish:latest
    container_name: firefish_web
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    ports:
      - "3000:3000"
    networks:
      - calcnet
#     - web
    environment:
      NODE_ENV: production
    volumes:
      - ./custom:/firefish/custom:ro
      - ./files:/firefish/files
      - ./.config:/firefish/.config:ro
    healthcheck:
      test: curl -f http://localhost:3000 || exit 1
      interval: 5s
      timeout: 5s
      retries: 5
    deploy:
      resources:
        limits:
          memory: 4096M

  redis:
    restart: unless-stopped
    image: docker.io/redis:7.0-alpine
    container_name: firefish_redis
    networks:
      - calcnet
    volumes:
      - ./redis:/data
    healthcheck:
      test: redis-cli ping
      interval: 5s
      timeout: 5s
      retries: 5
  #  deploy:
  #    resources:
  #      limits:
  #        memory: 200M


  db:
    restart: unless-stopped
    image: docker.io/groonga/pgroonga:3.1.8-alpine-16-slim
    container_name: firefish_db
    networks:
      - calcnet
    env_file:
      - .config/docker.env
    volumes:
      - ./db:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready --user="$${POSTGRES_USER}" --dbname="$${POSTGRES_DB}"
      interval: 5s
      timeout: 5s
      retries: 5
  #  deploy:
  #    resources:
  #      limits:
  #        memory: 200M

networks:
  calcnet:
  #  web:
  #    external:
  #      name: web
