services:
  work-server:
    image: nginx:1.27-alpine
    container_name: work-server
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    mem_limit: 256m
    ports:
      - '127.0.0.1:3100:3100'
    volumes:
      - ./.docker/proxy/default.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - work-backend

  work-server-blue:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: work-server-blue
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    user: "0:0"
    group_add:
      - "${SERVER_COMMAND_DOCKER_GID:-984}"
    mem_limit: 2048m
    working_dir: /app
    env_file:
      - path: ./.env.example
        required: false
      - path: ./.env
        required: false
    volumes:
      - ./:/app
      - work-server-node-modules:/app/node_modules
      - ../../../:/workspace/main-project
      - ../../../.auto_codex:/workspace/auto_codex
      - ../../../scripts:/workspace/repo-scripts:ro
      - ${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}:${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}
      - ./.docker/home:/home/how2ice
      - ./.docker/codex-home:/codex-home
      - ./.docker/codex-home-template:/codex-home-template
    environment:
      TZ: ${APP_TIME_ZONE:-Asia/Seoul}
      HOME: /home/how2ice
      CODEX_HOME: /codex-home
      PLAN_CODEX_TEMPLATE_HOME: /codex-home-template
      PLAN_CODEX_BIN: ${PLAN_CODEX_BIN:-codex}
      PLAN_CODEX_ENABLED: ${PLAN_CODEX_ENABLED:-false}
      PLAN_WORKER_ENABLED: ${PLAN_WORKER_ENABLED:-false}
      APP_TIME_ZONE: ${APP_TIME_ZONE:-Asia/Seoul}
      DB_TIME_ZONE: ${DB_TIME_ZONE:-Asia/Seoul}
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      WORK_SERVER_DIST_DIR: /app/dist
      WORK_SERVER_SLOT: blue
      SERVER_COMMAND_DOCKER_SOCKET: ${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}
      DOCKER_HOST: ${DOCKER_HOST:-}
    networks:
      - work-backend
    extra_hosts:
      - 'host.docker.internal:host-gateway'

  work-server-green:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: work-server-green
    logging:
      driver: json-file
      options:
        max-size: "200m"
        max-file: "2"
    user: "0:0"
    group_add:
      - "${SERVER_COMMAND_DOCKER_GID:-984}"
    mem_limit: 2048m
    working_dir: /app
    env_file:
      - path: ./.env.example
        required: false
      - path: ./.env
        required: false
    volumes:
      - ./:/app
      - work-server-node-modules:/app/node_modules
      - ../../../:/workspace/main-project
      - ../../../.auto_codex:/workspace/auto_codex
      - ../../../scripts:/workspace/repo-scripts:ro
      - ${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}:${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}
      - ./.docker/home:/home/how2ice
      - ./.docker/codex-home:/codex-home
      - ./.docker/codex-home-template:/codex-home-template
    environment:
      TZ: ${APP_TIME_ZONE:-Asia/Seoul}
      HOME: /home/how2ice
      CODEX_HOME: /codex-home
      PLAN_CODEX_TEMPLATE_HOME: /codex-home-template
      PLAN_CODEX_BIN: ${PLAN_CODEX_BIN:-codex}
      PLAN_CODEX_ENABLED: ${PLAN_CODEX_ENABLED:-false}
      PLAN_WORKER_ENABLED: ${PLAN_WORKER_ENABLED:-false}
      APP_TIME_ZONE: ${APP_TIME_ZONE:-Asia/Seoul}
      DB_TIME_ZONE: ${DB_TIME_ZONE:-Asia/Seoul}
      NPM_CONFIG_CACHE: /home/how2ice/.npm
      WORK_SERVER_DIST_DIR: /app/dist
      WORK_SERVER_SLOT: green
      SERVER_COMMAND_DOCKER_SOCKET: ${SERVER_COMMAND_DOCKER_SOCKET:-/var/run/docker.sock}
      DOCKER_HOST: ${DOCKER_HOST:-}
    networks:
      - work-backend
    extra_hosts:
      - 'host.docker.internal:host-gateway'

networks:
  work-backend:
    name: work-backend

volumes:
  work-server-node-modules:
