feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOCKER_DIR="$(cd "$SCRIPT_DIR/../../docker" && pwd)"
BACKEND_DIR="$(cd "$SCRIPT_DIR/../../backend" && pwd)"
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
cd "$DOCKER_DIR/atlas"
source "$DOCKER_DIR/.env"
echo "ATLAS_URL: $ATLAS_URL"
# Check if ATLAS_URL is set
if [ -z "$ATLAS_URL" ]; then
echo -e "${RED}Error: ATLAS_URL is not set. Please set the ATLAS_URL environment variable.${NC}"
exit 1
fi
# check if atlas is installed
OS=$(uname -s)
if command -v atlas &>/dev/null; then
echo -e "${GREEN}Atlas is installed.${NC}"
else
if [ "$OS" = "Darwin" ]; then
# macOS prompt
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
echo -e "${RED}brew install ariga/tap/atlas${NC}"
exit 1
else
# Linux prompt
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
echo -e "${RED}curl -sSf https://atlasgo.sh | sh -s -- --community${NC}"
exit 1
fi
fi
cd "$DOCKER_DIR/atlas"
atlas schema apply -u $ATLAS_URL --to file://opencoze_latest_schema.hcl --exclude "atlas_schema_revisions,table_*" --auto-approve
echo -e "${GREEN}✅ apply mysql schema successfully${NC}"
# if [ "$OS" = "Darwin" ]; then
# atlas schema apply -u $ATLAS_URL --to file://opencoze_latest_schema.hcl --auto-approve --exclude "table_*"
# echo -e "${GREEN}✅ apply mysql schema successfully${NC}"
# elif [ "$OS" = "Linux" ]; then
# atlas migrate apply \
# --url "$ATLAS_URL" \
# --dir "file://migrations" \
# --revisions-schema opencoze \
# --baseline "20250703095335"
# echo -e "${GREEN}✅ migrate mysql successfully${NC}"
# elif [ "$OS" = "Windows" ]; then
# echo -e "${RED}Windows is not supported. Please install Atlas manually.${NC}"
# exit 1
# fi

View File

@@ -0,0 +1,45 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BASE_DIR="$(cd "$SCRIPT_DIR/../../" && pwd)"
ATLAS_DIR="$BASE_DIR/docker/atlas"
DOCKER_DIR="$(cd "$SCRIPT_DIR/../../docker" && pwd)"
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
# Check if ATLAS_URL is set
if [ -z "$ATLAS_URL" ]; then
echo -e "${RED}Error: ATLAS_URL is not set. Please set the ATLAS_URL environment variable.${NC}"
exit 1
fi
source "$DOCKER_DIR/.env"
echo "ATLAS_URL: $ATLAS_URL"
# check if atlas is installed
OS=$(uname -s)
if command -v atlas &>/dev/null; then
echo -e "${GREEN}Atlas is installed.${NC}"
else
if [ "$OS" = "Darwin" ]; then
# macOS prompt
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
echo -e "${RED}brew install ariga/tap/atlas${NC}"
exit 1
else
# Linux prompt
echo -e "${RED}Atlas is not installed. Please execute the following command to install:${NC}"
echo -e "${RED}curl -sSf https://atlasgo.sh | sh -s -- --community${NC}"
exit 1
fi
fi
cd $ATLAS_DIR
atlas migrate diff update --env local --to $ATLAS_URL
atlas schema inspect -u $ATLAS_URL --exclude "atlas_schema_revisions,table_*" >opencoze_latest_schema.hcl

81
scripts/setup/python.sh Executable file
View File

@@ -0,0 +1,81 @@
#!/usr/bin/env bash
SETUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(dirname "$SETUP_DIR")"
BASE_DIR="$(dirname "$SCRIPT_DIR")"
BACKEND_DIR="$BASE_DIR/backend"
BIN_DIR="$BASE_DIR/bin"
VENV_DIR="$BIN_DIR/.venv"
echo "Checking for Python virtual environment under $BIN_DIR"
if [ ! -f "$VENV_DIR/bin/activate" ]; then
echo "Virtual environment not found or incomplete. Re-creating..."
rm -rf "$VENV_DIR"
python3 -m venv "$VENV_DIR"
if [ $? -ne 0 ]; then
echo "Failed to create virtual environment - aborting startup"
exit 1
fi
echo "Virtual environment created successfully!"
else
echo "Virtual environment already exists. Skipping creation."
fi
echo "Installing required Python packages"
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
# If you want to use other third-party libraries, you can install them here.
pip install urllib3==1.26.16
REQUESTS_ASYNC_REPO_URL="https://gitcode.com/gh_mirrors/re/requests-async.git"
REQUESTS_ASYNC_DIR="$BIN_DIR/requests-async"
if [ ! -d "$REQUESTS_ASYNC_DIR/.git" ]; then
echo "Cloning requests-async repository..."
rm -rf "$REQUESTS_ASYNC_DIR"
git clone "$REQUESTS_ASYNC_REPO_URL" "$REQUESTS_ASYNC_DIR"
if [ $? -ne 0 ]; then
echo "Failed to clone requests-async repository - aborting startup"
deactivate
exit 1
fi
else
echo "requests-async repository already exists."
fi
pip install pillow==11.2.1 pdfplumber==0.11.7 python-docx==1.2.0 numpy==2.3.1 "$REQUESTS_ASYNC_DIR"
if [ $? -ne 0 ]; then
echo "Failed to install Python packages - aborting startup"
deactivate
exit 1
fi
echo "Python packages installed successfully!"
deactivate
PARSER_SCRIPT_ROOT="$BACKEND_DIR/infra/impl/document/parser/builtin"
PDF_PARSER="$PARSER_SCRIPT_ROOT/parse_pdf.py"
DOCX_PARSER="$PARSER_SCRIPT_ROOT/parse_docx.py"
if [ -f "$PDF_PARSER" ]; then
cp "$PDF_PARSER" "$BIN_DIR/parse_pdf.py"
else
echo "$PDF_PARSER file not found"
exit 1
fi
if [ -f "$DOCX_PARSER" ]; then
cp "$DOCX_PARSER" "$BIN_DIR/parse_docx.py"
else
echo "$DOCX_PARSER file not found"
exit 1
fi

71
scripts/setup/server.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BASE_DIR="$(cd "$SCRIPT_DIR/../../" && pwd)"
BACKEND_DIR="$BASE_DIR/backend"
BIN_DIR="$BASE_DIR/bin"
CONFIG_DIR="$BIN_DIR/resources/conf"
RESOURCES_DIR="$BIN_DIR/resources/"
DOCKER_DIR="$BASE_DIR/docker"
echo "🧹 Checking for goimports availability..."
if command -v goimports >/dev/null 2>&1; then
echo "🧹 Formatting Go files with goimports..."
find "$BACKEND_DIR" \
-path "$BACKEND_DIR/api/model" -prune -o \
-path "$BACKEND_DIR/api/router" -prune -o \
-path "*/dal/query*" -prune -o \
-path "*/mock/*" -prune -o \
-path "*_mock.go" -prune -o \
-path "*/dal/model*" -prune -o \
-name "*.go" -exec goimports -w -local "github.com/coze-dev/coze-studio" {} \;
else
echo "⚠️ goimports not found, skipping Go file formatting."
fi
echo "🛠 Building Go project..."
rm -rf "$BIN_DIR/opencoze"
cd $BACKEND_DIR &&
go build -ldflags="-s -w" -o "$BIN_DIR/opencoze" main.go
# 添加构建失败检查
if [ $? -ne 0 ]; then
echo "❌ Go build failed - aborting startup"
exit 1
fi
echo "✅ Build completed successfully!"
echo "📑 Copying environment file..."
if [ -f "$DOCKER_DIR/.env" ]; then
cp "$DOCKER_DIR/.env" "$BIN_DIR/.env"
else
echo "❌ .env file not found in $DOCKER_DIR"
exit 1
fi
if [ -f "$DOCKER_DIR/cert.pem" ]; then
cp "$DOCKER_DIR/cert.pem" "$BIN_DIR/cert.pem"
fi
if [ -f "$DOCKER_DIR/key.pem" ]; then
cp "$DOCKER_DIR/key.pem" "$BIN_DIR/key.pem"
fi
echo "📑 Cleaning configuration files..."
rm -rf "$CONFIG_DIR"
mkdir -p "$CONFIG_DIR"
echo "📑 Copying plugin configuration files..."
cp -r "$BACKEND_DIR/conf" "$RESOURCES_DIR"
cp -r "$BACKEND_DIR/static" "$RESOURCES_DIR"
for arg in "$@"; do
if [[ "$arg" == "-start" ]]; then
echo "🚀 Starting Go service..."
cd $BIN_DIR && ./opencoze "$@"
exit 0
fi
done