本地调试coze-studio源代码(非docker)

参考自官方文档:

https://github.com/coze-dev/coze-studio/wiki/7.-开发规范#开发调试


1. 修改${coze-studio}/docker/docker-compose.yml文件

  • 注释掉coze-servercoze-web,只保留它的中间件,同时:

    • 将名称改为coze-middleware

    • 将网络模式由bridge改为host

name: coze-middleware

x-env-file: &env_file
  - .env

services:
  mysql:
    image: mysql:8.4.5
    container_name: coze-mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-opencoze}
      MYSQL_USER: ${MYSQL_USER:-coze}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-coze123}
    env_file: *env_file
    # ports:
    #   - '3306'
    volumes:
      - ./data/mysql:/var/lib/mysql
      - ./volumes/mysql/schema.sql:/docker-entrypoint-initdb.d/init.sql
      - ./atlas/opencoze_latest_schema.hcl:/opencoze_latest_schema.hcl:ro
    entrypoint:
      - bash
      - -c
      - |
        /usr/local/bin/docker-entrypoint.sh mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci &
        MYSQL_PID=$$!

        echo 'Waiting for MySQL to start...'
        until mysqladmin ping -h localhost -u root -p$${MYSQL_ROOT_PASSWORD} --silent 2>/dev/null; do
          echo 'MySQL is starting...'
          sleep 2
        done

        echo 'Waiting for workflow_version table to exist...'
        while true; do
          if mysql -h localhost -u root -p$${MYSQL_ROOT_PASSWORD} $${MYSQL_DATABASE} -e "SHOW TABLES LIKE 'workflow_version';" 2>/dev/null | grep -q "workflow_version"; then
            echo 'Found workflow_version table, continuing...'
            break
          else
            echo 'workflow_version table not found, retrying in 2 seconds...'
            sleep 2
          fi
        done

        echo 'MySQL is ready, installing Atlas CLI...'

        if ! command -v atlas >/dev/null 2>&1; then
          echo 'Installing Atlas CLI...'
          curl -sSf https://atlasgo.sh | sh -s -- -y --community
          export PATH=$$PATH:/root/.local/bin
        else
          echo 'Atlas CLI already installed'
        fi

        if [ -f '/opencoze_latest_schema.hcl' ]; then
          echo 'Running Atlas migrations...'
          ATLAS_URL="mysql://$${MYSQL_USER}:$${MYSQL_PASSWORD}@localhost:3306/$${MYSQL_DATABASE}"
          atlas schema apply -u "$ATLAS_URL" --to "file:///opencoze_latest_schema.hcl" --exclude "atlas_schema_revisions,table_*" --auto-approve
          echo 'Atlas migrations completed successfully'
        else
          echo 'No migrations found'
        fi
        wait $$MYSQL_PID
    healthcheck:
      test:
        [
          'CMD',
          'mysqladmin',
          'ping',
          '-h',
          'localhost',
          '-u$${MYSQL_USER}',
          '-p$${MYSQL_PASSWORD}',
        ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    network_mode: host
    # networks:
    #   - coze-network

  redis:
    image: bitnami/redis:8.0
    container_name: coze-redis
    restart: always
    user: root
    privileged: true
    env_file: *env_file
    environment:
      - REDIS_AOF_ENABLED=${REDIS_AOF_ENABLED:-no}
      - REDIS_PORT_NUMBER=${REDIS_PORT_NUMBER:-6379}
      - REDIS_IO_THREADS=${REDIS_IO_THREADS:-4}
      - ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD:-yes}
    # ports:
    #   - '6379'
    volumes:
      - ./data/bitnami/redis:/bitnami/redis/data:rw,Z
    command: >
      bash -c "
        /opt/bitnami/scripts/redis/setup.sh
        # Set proper permissions for data directories
        chown -R redis:redis /bitnami/redis/data
        chmod g+s /bitnami/redis/data

        exec /opt/bitnami/scripts/redis/entrypoint.sh /opt/bitnami/scripts/redis/run.sh
      "
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 10s
      retries: 10
      start_period: 10s
    network_mode: host
    # networks:
    #   - coze-network

  elasticsearch:
    image: bitnami/elasticsearch:8.18.0
    container_name: coze-elasticsearch
    restart: always
    user: root
    privileged: true
    env_file: *env_file
    environment:
      - TEST=1
      # Add Java certificate trust configuration
      # - ES_JAVA_OPTS=-Djdk.tls.client.protocols=TLSv1.2 -Dhttps.protocols=TLSv1.2 -Djavax.net.ssl.trustAll=true -Xms4096m -Xmx4096m
    # ports:
    #   - '9200'
    volumes:
      - ./data/bitnami/elasticsearch:/bitnami/elasticsearch/data
      - ./volumes/elasticsearch/elasticsearch.yml:/opt/bitnami/elasticsearch/config/my_elasticsearch.yml
      - ./volumes/elasticsearch/analysis-smartcn.zip:/opt/bitnami/elasticsearch/analysis-smartcn.zip:rw,Z
      - ./volumes/elasticsearch/setup_es.sh:/setup_es.sh
      - ./volumes/elasticsearch/es_index_schema:/es_index_schema
    healthcheck:
      test:
        [
          'CMD-SHELL',
          'curl -f http://localhost:9200 && [ -f /tmp/es_plugins_ready ] && [ -f /tmp/es_init_complete ]',
        ]
      interval: 5s
      timeout: 10s
      retries: 10
      start_period: 10s
    network_mode: host
    # networks:
    #   - coze-network
    # Install smartcn analyzer plugin and initialize ES
    command: >
      bash -c "
        /opt/bitnami/scripts/elasticsearch/setup.sh
        # Set proper permissions for data directories
        chown -R elasticsearch:elasticsearch /bitnami/elasticsearch/data
        chmod g+s /bitnami/elasticsearch/data

        # Create plugin directory
        mkdir -p /bitnami/elasticsearch/plugins;

        # Unzip plugin to plugin directory and set correct permissions
        echo 'Installing smartcn plugin...';
        if [ ! -d /opt/bitnami/elasticsearch/plugins/analysis-smartcn
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值