name: {{PROJECT_NAME}}

services:
{{DOCKER_DATABASE_SERVICES}}
  redis:
    image: redis:7.4-alpine
    environment:
      REDIS_PASSWORD: ${LUCKYSTACK_LOCAL_REDIS_PASSWORD:-${LUCKYSTACK_REDIS_PASSWORD:-docker-local-change-me}}
    command:
      - /bin/sh
      - -ec
      - exec redis-server --appendonly yes --requirepass "$$REDIS_PASSWORD"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD-SHELL", "redis-cli -a \"$$REDIS_PASSWORD\" --no-auth-warning ping | grep -q PONG"]
      interval: 3s
      timeout: 3s
      retries: 30
    restart: unless-stopped

  app:
    build:
      context: .
      target: app
    env_file:
      - path: .env
        required: false
      - path: .env.docker
        required: false
    environment:
      NODE_ENV: production
      LUCKYSTACK_ENV_FILES: /dev/null
      SERVER_IP: 0.0.0.0
      PORT: "4100"
      LUCKYSTACK_PRESET: ${LUCKYSTACK_PRESET:-default}
      PUBLIC_URL: ${PUBLIC_URL:-http://localhost:${LUCKYSTACK_PORT:-8080}}
      SECURE: ${SECURE:-false}
      PROJECT_NAME: {{PROJECT_NAME}}-docker
      DATABASE_URL: ${LUCKYSTACK_DATABASE_URL:-{{DOCKER_DATABASE_URL}}}
      REDIS_HOST: ${LUCKYSTACK_REDIS_HOST:-redis}
      REDIS_PORT: ${LUCKYSTACK_REDIS_PORT:-6379}
      REDIS_USER: ${LUCKYSTACK_REDIS_USER:-default}
      REDIS_PASSWORD: ${LUCKYSTACK_REDIS_PASSWORD:-docker-local-change-me}
    depends_on:
      redis:
        condition: service_healthy
{{DOCKER_DATABASE_DEPENDS_ON}}    extra_hosts:
      - host.docker.internal:host-gateway
    volumes:
      - uploads_data:/app/uploads
{{DOCKER_APP_DATA_VOLUME}}    read_only: true
    tmpfs:
      - /tmp
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    stop_grace_period: 20s
    restart: unless-stopped

{{DOCKER_ROUTER_SERVICE}}  web:
    build:
      context: .
      target: web
    ports:
      - 127.0.0.1:${LUCKYSTACK_PORT:-8080}:8080
    depends_on:
      {{DOCKER_WEB_DEPENDENCY}}:
        condition: service_healthy
    read_only: true
    tmpfs:
      - /tmp
      - /var/cache/nginx
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    restart: unless-stopped

volumes:
{{DOCKER_DATABASE_VOLUMES}}  redis_data:
  uploads_data:
{{DOCKER_APP_DATA_DECLARATION}}