services:
  prod-app:
    image: node:${NODE_VERSION:-22.22.2}-bookworm
    container_name: ai-code-app-prod
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    user: "0:0"
    cpus: 1.0
    mem_limit: 1536m
    working_dir: /prod-app
    ports:
      - '127.0.0.1:5173:5173'
    volumes:
      - ${PROD_APP_SOURCE:-.}:/prod-app
      - ./.docker/prod-app/node_modules:/prod-app/node_modules
      - ./.docker/prod-app/home:/home/how2ice
    networks:
      - default
      - work-backend
    environment:
      HOME: /home/how2ice
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      WORK_SERVER_URL: http://work-server:3100
      VITE_DISABLE_APP_UPDATE: "true"
    command: >
      sh -c "npm ci --legacy-peer-deps && npm run build:test-app && npm run preview:test-app -- --host 0.0.0.0 --port 5173 --strictPort"

  app:
    image: node:${NODE_VERSION:-22.22.2}-bookworm
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    user: "0:0"
    cpus: 1.0
    mem_limit: 1536m
    working_dir: /app
    ports:
      - '127.0.0.1:5174:5173'
    volumes:
      - ./:/app
      - app-node-modules:/app/node_modules
      - app-home:/home/how2ice
    networks:
      - default
      - work-backend
    environment:
      HOME: /home/how2ice
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      WORK_SERVER_URL: http://work-server:3100
    command: >
      sh -c "npm ci --legacy-peer-deps && npm run build:test-app && npm run preview:test-app -- --host 0.0.0.0 --port 5173 --strictPort"

  release-app:
    image: node:${NODE_VERSION:-22.22.2}-bookworm
    container_name: ai-code-app-release
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    user: "0:0"
    cpus: 1.0
    mem_limit: 1536m
    working_dir: /workspace/auto_codex/repo
    ports:
      - '127.0.0.1:5175:5173'
    volumes:
      - ./.auto_codex/repo:/workspace/auto_codex/repo
      - ./.docker/release-app/node_modules:/workspace/auto_codex/repo/node_modules
      - ./.docker/release-app/home:/home/how2ice
    networks:
      - default
      - work-backend
    environment:
      HOME: /home/how2ice
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      VITE_PUBLIC_HMR_HOST: rel.sm-home.cloud
      VITE_PUBLIC_HMR_PROTOCOL: wss
      VITE_PUBLIC_HMR_CLIENT_PORT: 443
    command: >
      sh -c "npm ci --legacy-peer-deps && npm run dev -- --host 0.0.0.0 --port 5173"

networks:
  work-backend:
    name: work-backend

volumes:
  app-node-modules:
  app-home:
