diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..bcff8c82 --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +# NOFX Environment Variables Template +# Copy this file to .env and modify the values as needed + +# Ports Configuration +# Backend API server port (internal: 8080, external: configurable) +NOFX_BACKEND_PORT=8080 + +# Frontend web interface port (Nginx listens on port 80 internally) +NOFX_FRONTEND_PORT=3000 + +# Timezone Setting +# System timezone for container time synchronization +NOFX_TIMEZONE=Asia/Shanghai diff --git a/.gitignore b/.gitignore index 384b3f41..d501f8dd 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ Thumbs.db *.log *.tmp *.bak +*.backup # ็Žฏๅขƒๅ˜้‡ .env diff --git a/DOCKER_DEPLOY.en.md b/DOCKER_DEPLOY.en.md index 1b9c42f2..bf8adf63 100644 --- a/DOCKER_DEPLOY.en.md +++ b/DOCKER_DEPLOY.en.md @@ -15,22 +15,33 @@ Before you begin, ensure your system has: Download and install [Docker Desktop](https://www.docker.com/products/docker-desktop/) #### Linux (Ubuntu/Debian) + +> #### Docker Compose Version Notes +> +> **New User Recommendation:** +> - **Use Docker Desktop**: Automatically includes latest Docker Compose, no separate installation needed +> - Simple installation, one-click setup, provides GUI management +> - Supports macOS, Windows, and some Linux distributions +> +> **Upgrading User Note:** +> - **Deprecating standalone docker-compose**: No longer recommended to download the independent Docker Compose binary +> - **Use built-in version**: Docker 20.10+ includes `docker compose` command (with space) +> - If still using old `docker-compose`, please upgrade to new syntax + +*Recommended: Use Docker Desktop (if available) or Docker CE with built-in Compose* + ```bash -# Install Docker +# Install Docker (includes compose) curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh -# Install Docker Compose -sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -sudo chmod +x /usr/local/bin/docker-compose - -# Add current user to docker group +# Add user to docker group sudo usermod -aG docker $USER newgrp docker -# Verify installation +# Verify installation (new command) docker --version -docker-compose --version +docker compose --version # Docker 24+ includes this, no separate installation needed ``` ## ๐Ÿš€ Quick Start (3 Steps) @@ -69,10 +80,10 @@ nano config.json # or use any other editor ```bash # Build and start all services (first run) -docker-compose up -d --build +docker compose up -d --build # Subsequent starts (without rebuilding) -docker-compose up -d +docker compose up -d ``` **Startup options:** @@ -91,49 +102,49 @@ Once deployed, open your browser and visit: ### View Running Status ```bash # View all container status -docker-compose ps +docker compose ps # View service health status -docker-compose ps --format json | jq +docker compose ps --format json | jq ``` ### View Logs ```bash # View all service logs -docker-compose logs -f +docker compose logs -f # View backend logs only -docker-compose logs -f backend +docker compose logs -f backend # View frontend logs only -docker-compose logs -f frontend +docker compose logs -f frontend # View last 100 lines -docker-compose logs --tail=100 +docker compose logs --tail=100 ``` ### Stop Services ```bash # Stop all services (keep data) -docker-compose stop +docker compose stop # Stop and remove containers (keep data) -docker-compose down +docker compose down # Stop and remove containers and volumes (clear all data) -docker-compose down -v +docker compose down -v ``` ### Restart Services ```bash # Restart all services -docker-compose restart +docker compose restart # Restart backend only -docker-compose restart backend +docker compose restart backend # Restart frontend only -docker-compose restart frontend +docker compose restart frontend ``` ### Update Services @@ -142,7 +153,7 @@ docker-compose restart frontend git pull # Rebuild and restart -docker-compose up -d --build +docker compose up -d --build ``` ## ๐Ÿ”ง Advanced Configuration @@ -226,14 +237,14 @@ tar -xzf backup_20241029.tar.gz ```bash # View detailed error messages -docker-compose logs backend -docker-compose logs frontend +docker compose logs backend +docker compose logs frontend # Check container status -docker-compose ps -a +docker compose ps -a # Rebuild (clear cache) -docker-compose build --no-cache +docker compose build --no-cache ``` ### Port Already in Use @@ -273,10 +284,10 @@ curl http://localhost:3000/health ```bash # Check network connectivity -docker-compose exec frontend ping backend +docker compose exec frontend ping backend # Check if backend service is running -docker-compose exec frontend wget -O- http://backend:8080/health +docker compose exec frontend wget -O- http://backend:8080/health ``` ### Clean Docker Resources @@ -321,8 +332,8 @@ docker system prune -a --volumes 4. **Regularly update images** ```bash - docker-compose pull - docker-compose up -d + docker compose pull + docker compose up -d ``` ## ๐ŸŒ Production Deployment @@ -391,7 +402,7 @@ logging: max-file: "3" # View log statistics -docker-compose logs --timestamps | wc -l +docker compose logs --timestamps | wc -l ``` ### Monitoring Tool Integration @@ -424,28 +435,28 @@ services: ```bash # Start -docker-compose up -d --build # Build and start -docker-compose up -d # Start (without rebuilding) +docker compose up -d --build # Build and start +docker compose up -d # Start (without rebuilding) # Stop -docker-compose stop # Stop services -docker-compose down # Stop and remove containers -docker-compose down -v # Stop and remove containers and data +docker compose stop # Stop services +docker compose down # Stop and remove containers +docker compose down -v # Stop and remove containers and data # View -docker-compose ps # View status -docker-compose logs -f # View logs -docker-compose top # View processes +docker compose ps # View status +docker compose logs -f # View logs +docker compose top # View processes # Restart -docker-compose restart # Restart all services -docker-compose restart backend # Restart backend +docker compose restart # Restart all services +docker compose restart backend # Restart backend # Update -git pull && docker-compose up -d --build +git pull && docker compose up -d --build # Clean -docker-compose down -v # Clear all data +docker compose down -v # Clear all data docker system prune -a # Clean Docker resources ``` diff --git a/DOCKER_DEPLOY.md b/DOCKER_DEPLOY.md index f48b005e..536ee159 100644 --- a/DOCKER_DEPLOY.md +++ b/DOCKER_DEPLOY.md @@ -11,26 +11,42 @@ ### ๅฎ‰่ฃ… Docker +> #### ๆ็คบ๏ผšDocker Compose ็‰ˆๆœฌ่ฏดๆ˜Ž +> +> **ๆ–ฐ็”จๆˆทๅปบ่ฎฎ**๏ผš +> - **ๆŽจ่ไฝฟ็”จ Docker Desktop**๏ผš่‡ชๅŠจๅŒ…ๅซๆœ€ๆ–ฐ Docker Compose๏ผŒๆ— ้œ€ๅ•็‹ฌๅฎ‰่ฃ… +> - ๅฎ‰่ฃ…็ฎ€ๅ•๏ผŒไธ€้”ฎๆžๅฎš๏ผŒๆไพ›ๅ›พๅฝข็•Œ้ข็ฎก็† +> - ๆ”ฏๆŒ macOSใ€Windowsใ€้ƒจๅˆ† Linux ๅ‘่กŒ็‰ˆ +> +> **ๆ—ง็”จๆˆทๆ้†’**๏ผš +> - **ๅผƒ็”จ็‹ฌ็ซ‹ docker-compose**๏ผšไธๅ†ๆŽจ่ไธ‹่ฝฝ็‹ฌ็ซ‹็š„ Docker Compose ไบŒ่ฟ›ๅˆถๆ–‡ไปถ +> - **ไฝฟ็”จๅ†…็ฝฎ็‰ˆ**๏ผšDocker 20.10+ ่‡ชๅธฆ `docker compose` ๅ‘ฝไปค๏ผˆๆณจๆ„ๆ˜ฏ็ฉบๆ ผ๏ผ‰ +> - ๅฆ‚ๆžœ่ฟ˜ๅœจไฝฟ็”จๆ—ง็š„ `docker-compose`๏ผŒ่ฏทๅ‡็บงๅˆฐๆ–ฐ่ฏญๆณ• + #### macOS / Windows ไธ‹่ฝฝๅนถๅฎ‰่ฃ… [Docker Desktop](https://www.docker.com/products/docker-desktop/) -#### Linux (Ubuntu/Debian) +**ๅฎ‰่ฃ…ๅŽ้ชŒ่ฏ๏ผš** ```bash -# ๅฎ‰่ฃ… Docker +docker --version +docker compose --version # ๆณจๆ„๏ผšไฝฟ็”จ็ฉบๆ ผ๏ผŒไธๅ†ๆ˜ฏ่ฟžๅญ—็ฌฆ +``` + +#### Linux (Ubuntu/Debian) +**ๆŽจ่ๆ–นๅผ๏ผšไฝฟ็”จ Docker Desktop๏ผˆๅฆ‚ๆžœๅฏ็”จ๏ผ‰ๆˆ– Docker CE** + +```bash +# ๅฎ‰่ฃ… Docker (่‡ชๅŠจๅŒ…ๅซ compose) curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh -# ๅฎ‰่ฃ… Docker Compose -sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -sudo chmod +x /usr/local/bin/docker-compose - # ๅฐ†ๅฝ“ๅ‰็”จๆˆทๅŠ ๅ…ฅ docker ็ป„ sudo usermod -aG docker $USER newgrp docker -# ้ชŒ่ฏๅฎ‰่ฃ… +# ้ชŒ่ฏๅฎ‰่ฃ…๏ผˆๆ–ฐๅ‘ฝไปค๏ผ‰ docker --version -docker-compose --version +docker compose --version # Docker 24+ ่‡ชๅธฆ๏ผŒๆ— ้œ€ๅ•็‹ฌๅฎ‰่ฃ… ``` ## ๐Ÿš€ ๅฟซ้€Ÿๅผ€ๅง‹๏ผˆ3ๆญฅๅฎŒๆˆ้ƒจ็ฝฒ๏ผ‰ @@ -69,10 +85,10 @@ nano config.json # ๆˆ–ไฝฟ็”จๅ…ถไป–็ผ–่พ‘ๅ™จ ```bash # ๆž„ๅปบๅนถๅฏๅŠจๆ‰€ๆœ‰ๆœๅŠก๏ผˆ้ฆ–ๆฌก่ฟ่กŒ๏ผ‰ -docker-compose up -d --build +docker compose up -d --build # ๅŽ็ปญๅฏๅŠจ๏ผˆไธ้‡ๆ–ฐๆž„ๅปบ๏ผ‰ -docker-compose up -d +docker compose up -d ``` **ๅฏๅŠจ่ฟ‡็จ‹่ฏดๆ˜Ž๏ผš** @@ -91,49 +107,49 @@ docker-compose up -d ### ๆŸฅ็œ‹่ฟ่กŒ็Šถๆ€ ```bash # ๆŸฅ็œ‹ๆ‰€ๆœ‰ๅฎนๅ™จ็Šถๆ€ -docker-compose ps +docker compose ps # ๆŸฅ็œ‹ๆœๅŠกๅฅๅบท็Šถๆ€ -docker-compose ps --format json | jq +docker compose ps --format json | jq ``` ### ๆŸฅ็œ‹ๆ—ฅๅฟ— ```bash # ๆŸฅ็œ‹ๆ‰€ๆœ‰ๆœๅŠกๆ—ฅๅฟ— -docker-compose logs -f +docker compose logs -f # ๅชๆŸฅ็œ‹ๅŽ็ซฏๆ—ฅๅฟ— -docker-compose logs -f backend +docker compose logs -f backend # ๅชๆŸฅ็œ‹ๅ‰็ซฏๆ—ฅๅฟ— -docker-compose logs -f frontend +docker compose logs -f frontend # ๆŸฅ็œ‹ๆœ€่ฟ‘ 100 ่กŒๆ—ฅๅฟ— -docker-compose logs --tail=100 +docker compose logs --tail=100 ``` ### ๅœๆญขๆœๅŠก ```bash # ๅœๆญขๆ‰€ๆœ‰ๆœๅŠก๏ผˆไฟ็•™ๆ•ฐๆฎ๏ผ‰ -docker-compose stop +docker compose stop # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จ๏ผˆไฟ็•™ๆ•ฐๆฎ๏ผ‰ -docker-compose down +docker compose down # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จๅ’Œๅท๏ผˆๆธ…้™คๆ‰€ๆœ‰ๆ•ฐๆฎ๏ผ‰ -docker-compose down -v +docker compose down -v ``` ### ้‡ๅฏๆœๅŠก ```bash # ้‡ๅฏๆ‰€ๆœ‰ๆœๅŠก -docker-compose restart +docker compose restart # ๅช้‡ๅฏๅŽ็ซฏ -docker-compose restart backend +docker compose restart backend # ๅช้‡ๅฏๅ‰็ซฏ -docker-compose restart frontend +docker compose restart frontend ``` ### ๆ›ดๆ–ฐๆœๅŠก @@ -142,7 +158,7 @@ docker-compose restart frontend git pull # ้‡ๆ–ฐๆž„ๅปบๅนถ้‡ๅฏ -docker-compose up -d --build +docker compose up -d --build ``` ## ๐Ÿ”ง ้ซ˜็บง้…็ฝฎ @@ -226,14 +242,14 @@ tar -xzf backup_20241029.tar.gz ```bash # ๆŸฅ็œ‹่ฏฆ็ป†้”™่ฏฏไฟกๆฏ -docker-compose logs backend -docker-compose logs frontend +docker compose logs backend +docker compose logs frontend # ๆฃ€ๆŸฅๅฎนๅ™จ็Šถๆ€ -docker-compose ps -a +docker compose ps -a # ้‡ๆ–ฐๆž„ๅปบ๏ผˆๆธ…้™ค็ผ“ๅญ˜๏ผ‰ -docker-compose build --no-cache +docker compose build --no-cache ``` ### ็ซฏๅฃ่ขซๅ ็”จ @@ -273,10 +289,10 @@ curl http://localhost:3000/health ```bash # ๆฃ€ๆŸฅ็ฝ‘็ปœ่ฟžๆŽฅ -docker-compose exec frontend ping backend +docker compose exec frontend ping backend # ๆฃ€ๆŸฅๅŽ็ซฏๆœๅŠกๆ˜ฏๅฆๆญฃๅธธ -docker-compose exec frontend wget -O- http://backend:8080/health +docker compose exec frontend wget -O- http://backend:8080/health ``` ### ๆธ…็† Docker ่ต„ๆบ @@ -321,8 +337,8 @@ docker system prune -a --volumes 4. **ๅฎšๆœŸๆ›ดๆ–ฐ้•œๅƒ** ```bash - docker-compose pull - docker-compose up -d + docker compose pull + docker compose up -d ``` ## ๐ŸŒ ็”Ÿไบง็Žฏๅขƒ้ƒจ็ฝฒ @@ -391,7 +407,7 @@ logging: max-file: "3" # ๆŸฅ็œ‹ๆ—ฅๅฟ—็ปŸ่ฎก -docker-compose logs --timestamps | wc -l +docker compose logs --timestamps | wc -l ``` ### ็›‘ๆŽงๅทฅๅ…ท้›†ๆˆ @@ -424,28 +440,28 @@ services: ```bash # ๅฏๅŠจ -docker-compose up -d --build # ๆž„ๅปบๅนถๅฏๅŠจ -docker-compose up -d # ๅฏๅŠจ๏ผˆไธ้‡ๆ–ฐๆž„ๅปบ๏ผ‰ +docker compose up -d --build # ๆž„ๅปบๅนถๅฏๅŠจ +docker compose up -d # ๅฏๅŠจ๏ผˆไธ้‡ๆ–ฐๆž„ๅปบ๏ผ‰ # ๅœๆญข -docker-compose stop # ๅœๆญขๆœๅŠก -docker-compose down # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จ -docker-compose down -v # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จๅ’Œๆ•ฐๆฎ +docker compose stop # ๅœๆญขๆœๅŠก +docker compose down # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จ +docker compose down -v # ๅœๆญขๅนถๅˆ ้™คๅฎนๅ™จๅ’Œๆ•ฐๆฎ # ๆŸฅ็œ‹ -docker-compose ps # ๆŸฅ็œ‹็Šถๆ€ -docker-compose logs -f # ๆŸฅ็œ‹ๆ—ฅๅฟ— -docker-compose top # ๆŸฅ็œ‹่ฟ›็จ‹ +docker compose ps # ๆŸฅ็œ‹็Šถๆ€ +docker compose logs -f # ๆŸฅ็œ‹ๆ—ฅๅฟ— +docker compose top # ๆŸฅ็œ‹่ฟ›็จ‹ # ้‡ๅฏ -docker-compose restart # ้‡ๅฏๆ‰€ๆœ‰ๆœๅŠก -docker-compose restart backend # ้‡ๅฏๅŽ็ซฏ +docker compose restart # ้‡ๅฏๆ‰€ๆœ‰ๆœๅŠก +docker compose restart backend # ้‡ๅฏๅŽ็ซฏ # ๆ›ดๆ–ฐ -git pull && docker-compose up -d --build +git pull && docker compose up -d --build # ๆธ…็† -docker-compose down -v # ๆธ…้™คๆ‰€ๆœ‰ๆ•ฐๆฎ +docker compose down -v # ๆธ…้™คๆ‰€ๆœ‰ๆ•ฐๆฎ docker system prune -a # ๆธ…็† Docker ่ต„ๆบ ``` diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4a8d8fb4..00000000 --- a/Dockerfile +++ /dev/null @@ -1,123 +0,0 @@ -# Multi-stage build for NOFX AI Trading System -FROM golang:1.25-alpine AS backend-builder - -# Install build dependencies including TA-Lib -RUN apk update && \ - apk add --no-cache \ - git \ - make \ - gcc \ - g++ \ - musl-dev \ - wget \ - tar \ - autoconf \ - automake - -# Install TA-Lib -RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \ - tar -xzf ta-lib-0.4.0-src.tar.gz && \ - cd ta-lib && \ - if [ "$(uname -m)" = "aarch64" ]; then \ - CONFIG_GUESS=$(find /usr/share -name config.guess | head -1) && \ - CONFIG_SUB=$(find /usr/share -name config.sub | head -1) && \ - cp "$CONFIG_GUESS" config.guess && \ - cp "$CONFIG_SUB" config.sub && \ - chmod +x config.guess config.sub; \ - fi && \ - ./configure --prefix=/usr && \ - make && \ - make install && \ - cd .. && \ - rm -rf ta-lib ta-lib-0.4.0-src.tar.gz - -# Set working directory -WORKDIR /app - -# Copy go mod files -COPY go.mod go.sum ./ - -# Download dependencies -RUN go mod download - -# Copy backend source code -COPY . . - -# Build the application -RUN CGO_ENABLED=1 GOOS=linux go build -trimpath -ldflags="-s -w" -o nofx . - -# Frontend build stage -FROM node:18-alpine AS frontend-builder - -WORKDIR /app/web - -# Copy package files -COPY web/package*.json ./ - -# Install dependencies -RUN npm ci - -# Copy frontend source -COPY web/ ./ - -# Build frontend -RUN npm run build - -# Final stage -FROM alpine:latest - -# Update package index and install runtime dependencies -RUN apk update && \ - apk add --no-cache \ - ca-certificates \ - tzdata \ - wget \ - tar \ - make \ - gcc \ - g++ \ - musl-dev \ - autoconf \ - automake - -# Install TA-Lib runtime -RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \ - tar -xzf ta-lib-0.4.0-src.tar.gz && \ - cd ta-lib && \ - if [ "$(uname -m)" = "aarch64" ]; then \ - CONFIG_GUESS=$(find /usr/share -name config.guess | head -1) && \ - CONFIG_SUB=$(find /usr/share -name config.sub | head -1) && \ - cp "$CONFIG_GUESS" config.guess && \ - cp "$CONFIG_SUB" config.sub && \ - chmod +x config.guess config.sub; \ - fi && \ - ./configure --prefix=/usr && \ - make && \ - make install && \ - cd .. && \ - rm -rf ta-lib ta-lib-0.4.0-src.tar.gz - -# Set timezone to UTC -ENV TZ=UTC - -WORKDIR /app - -# Copy backend binary from builder -COPY --from=backend-builder /app/nofx . - -# Copy frontend build from builder -COPY --from=frontend-builder /app/web/dist ./web/dist - -# Create directories for logs and data -RUN mkdir -p /app/decision_logs - -# Expose ports -# 8080 for backend API -EXPOSE 8080 - -# Health check -HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 - -# Run the application -CMD ["./nofx"] diff --git a/README.md b/README.md index 1e6c15f7..ba9305fa 100644 --- a/README.md +++ b/README.md @@ -260,8 +260,14 @@ nano config.json # or use any editor chmod +x start.sh ./start.sh start --build -# Option 2: Use docker-compose directly -docker-compose up -d --build +> #### Docker Compose Version Notes +> +> **This project uses Docker Compose V2 syntax (with spaces)** +> +> If you have the older standalone `docker-compose` installed, please upgrade to Docker Desktop or Docker 20.10+ + +# Option 2: Use docker compose directly +docker compose up -d --build ``` #### Step 3: Access Dashboard diff --git a/README.ru.md b/README.ru.md index 874c478a..51d8054a 100644 --- a/README.ru.md +++ b/README.ru.md @@ -196,8 +196,10 @@ nano config.json # ะธะปะธ ะธัะฟะพะปัŒะทัƒะนั‚ะต ะปัŽะฑะพะน ั€ะตะดะฐะบั‚ะพั€ chmod +x start.sh ./start.sh start --build -# ะ’ะฐั€ะธะฐะฝั‚ 2: ะ˜ัะฟะพะปัŒะทัƒะนั‚ะต docker-compose ะฝะฐะฟั€ัะผัƒัŽ -docker-compose up -d --build +# ะ’ะฐั€ะธะฐะฝั‚ 2: ะ˜ัะฟะพะปัŒะทัƒะนั‚ะต docker compose ะฝะฐะฟั€ัะผัƒัŽ +# ะญั‚ะพั‚ ะฟั€ะพะตะบั‚ ะธัะฟะพะปัŒะทัƒะตั‚ ัะธะฝั‚ะฐะบัะธั Docker Compose V2 (ั ะฟั€ะพะฑะตะปะฐะผะธ) +# ะ•ัะปะธ ัƒ ะฒะฐั ัƒัั‚ะฐะฝะพะฒะปะตะฝะฐ ัั‚ะฐั€ะฐั ะฒะตั€ัะธั `docker-compose`, ะพะฑะฝะพะฒะธั‚ะตััŒ ะดะพ Docker Desktop ะธะปะธ Docker 20.10+ +docker compose up -d --build ``` #### ะจะฐะณ 3: ะ”ะพัั‚ัƒะฟ ะบ ะฟะฐะฝะตะปะธ diff --git a/README.uk.md b/README.uk.md index 8c955c59..d47c5921 100644 --- a/README.uk.md +++ b/README.uk.md @@ -196,8 +196,10 @@ nano config.json # ะฐะฑะพ ะฒะธะบะพั€ะธัั‚ะฐะนั‚ะต ะฑัƒะดัŒ-ัะบะธะน ั€ะตะดะฐะบ chmod +x start.sh ./start.sh start --build -# ะ’ะฐั€ั–ะฐะฝั‚ 2: ะ’ะธะบะพั€ะธัั‚ะฐะนั‚ะต docker-compose ะฑะตะทะฟะพัะตั€ะตะดะฝัŒะพ -docker-compose up -d --build +# ะ’ะฐั€ั–ะฐะฝั‚ 2: ะ’ะธะบะพั€ะธัั‚ะฐะนั‚ะต docker compose ะฑะตะทะฟะพัะตั€ะตะดะฝัŒะพ +# ะฆะตะน ะฟั€ะพะตะบั‚ ะฒะธะบะพั€ะธัั‚ะพะฒัƒั” ัะธะฝั‚ะฐะบัะธั Docker Compose V2 (ะท ะฟั€ะพะฑั–ะปะฐะผะธ) +# ะฏะบั‰ะพ ัƒ ะฒะฐั ะฒัั‚ะฐะฝะพะฒะปะตะฝะฐ ัั‚ะฐั€ะฐ ะฒะตั€ัั–ั `docker-compose`, ะพะฝะพะฒั–ั‚ัŒ ะดะพ Docker Desktop ะฐะฑะพ Docker 20.10+ +docker compose up -d --build ``` #### ะšั€ะพะบ 3: ะ”ะพัั‚ัƒะฟ ะดะพ ะฟะฐะฝะตะปั– diff --git a/README.zh-CN.md b/README.zh-CN.md index 91447973..9b47fa04 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -260,8 +260,10 @@ nano config.json # ๆˆ–ไฝฟ็”จๅ…ถไป–็ผ–่พ‘ๅ™จ chmod +x start.sh ./start.sh start --build -# ๆ–นๅผ2๏ผš็›ดๆŽฅไฝฟ็”จdocker-compose -docker-compose up -d --build + +# ๆ–นๅผ2๏ผš็›ดๆŽฅไฝฟ็”จdocker compose +# ๅฆ‚ๆžœๆ‚จ่ฟ˜ๅœจไฝฟ็”จๆ—ง็š„็‹ฌ็ซ‹ `docker-compose`๏ผŒ่ฏทๅ‡็บงๅˆฐ Docker Desktop ๆˆ– Docker 20.10+ +docker compose up -d --build ``` #### ๆญฅ้ชค3๏ผš่ฎฟ้—ฎๆŽงๅˆถๅฐ diff --git a/docker-compose.yml b/docker-compose.yml index 96260ca7..dad8b7a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,21 @@ version: '3.8' services: - # NOFX Trading Backend + # Backend service (API and core logic) nofx: build: context: . - dockerfile: Dockerfile + dockerfile: ./docker/Dockerfile.backend container_name: nofx-trading restart: unless-stopped ports: - - "8080:8080" + - "${NOFX_BACKEND_PORT:-8080}:8080" volumes: - ./config.json:/app/config.json:ro - ./decision_logs:/app/decision_logs - - /etc/localtime:/etc/localtime:ro # ๅŒๆญฅไธปๆœบๆ—ถ้—ด - - frontend-dist:/app/web/dist-shared:rw # ๅ…ฑไบซๅ‰็ซฏๆ–‡ไปถ + - /etc/localtime:/etc/localtime:ro # Sync host time environment: - - TZ=Asia/Shanghai # ไฝฟ็”จไธญๅ›ฝๆ—ถๅŒบ + - TZ=${NOFX_TIMEZONE:-Asia/Shanghai} # Set timezone networks: - nofx-network healthcheck: @@ -25,26 +24,27 @@ services: timeout: 10s retries: 3 start_period: 60s - command: sh -c "cp -r /app/web/dist/* /app/web/dist-shared/ 2>/dev/null || true && exec ./nofx" - # Frontend (Nginx) + # Frontend service (static serving and proxy) nofx-frontend: - image: nginx:alpine + build: + context: . + dockerfile: ./docker/Dockerfile.frontend container_name: nofx-frontend restart: unless-stopped ports: - - "3000:80" - volumes: - - frontend-dist:/usr/share/nginx/html:ro - - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + - "${NOFX_FRONTEND_PORT:-3000}:80" networks: - nofx-network depends_on: - nofx - -volumes: - frontend-dist: + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 5s networks: nofx-network: - driver: bridge + driver: bridge \ No newline at end of file diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend new file mode 100644 index 00000000..18387f67 --- /dev/null +++ b/docker/Dockerfile.backend @@ -0,0 +1,68 @@ +# docker/backend/Dockerfile + +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• +# NOFX Backend Dockerfile (Go + TA-Lib) +# Multi-stage build with shared TA-Lib compilation stage +# Versions extracted as ARGs for maintainability +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + +ARG GO_VERSION=1.25-alpine +ARG ALPINE_VERSION=latest +ARG TA_LIB_VERSION=0.4.0 + +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +# TA-Lib Build Stage (shared across builds) +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +FROM alpine:${ALPINE_VERSION} AS ta-lib-builder +ARG TA_LIB_VERSION + +RUN apk update && apk add --no-cache \ + wget tar make gcc g++ musl-dev autoconf automake + +RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-${TA_LIB_VERSION}-src.tar.gz && \ + tar -xzf ta-lib-${TA_LIB_VERSION}-src.tar.gz && \ + cd ta-lib && \ + if [ "$(uname -m)" = "aarch64" ]; then \ + CONFIG_GUESS=$(find /usr/share -name config.guess | head -1) && \ + CONFIG_SUB=$(find /usr/share -name config.sub | head -1) && \ + cp "$CONFIG_GUESS" config.guess && \ + cp "$CONFIG_SUB" config.sub && \ + chmod +x config.guess config.sub; \ + fi && \ + ./configure --prefix=/usr/local && \ + make && make install && \ + cd .. && rm -rf ta-lib ta-lib-${TA_LIB_VERSION}-src.tar.gz + +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +# Backend Build Stage (Go Application) +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +FROM golang:${GO_VERSION} AS backend-builder + +RUN apk update && apk add --no-cache git make gcc g++ musl-dev + +COPY --from=ta-lib-builder /usr/local /usr/local + +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN CGO_ENABLED=1 GOOS=linux go build -trimpath -ldflags="-s -w" -o nofx . + +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +# Runtime Stage (Minimal Executable Environment) +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +FROM alpine:${ALPINE_VERSION} + +RUN apk update && apk add --no-cache ca-certificates tzdata + +COPY --from=ta-lib-builder /usr/local /usr/local +WORKDIR /app +COPY --from=backend-builder /app/nofx . + +EXPOSE 8080 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 + +CMD ["./nofx"] diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend new file mode 100644 index 00000000..75098bd1 --- /dev/null +++ b/docker/Dockerfile.frontend @@ -0,0 +1,36 @@ +# docker/frontend/Dockerfile + +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• +# NOFX Frontend Dockerfile (Node Build โ†’ Nginx Runtime) +# Versions extracted as ARGs for consistency +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + +ARG NODE_VERSION=20-alpine +ARG NGINX_VERSION=alpine + +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +# Build Stage (Node) +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +FROM node:${NODE_VERSION} AS builder +WORKDIR /build + +COPY web/package*.json ./ +RUN npm ci + +COPY web/ ./ +RUN npm run build + +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +# Runtime Stage (Nginx) +# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +FROM nginx:${NGINX_VERSION} + +COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /build/dist /usr/share/nginx/html + +EXPOSE 80 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 1 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx/nginx.conf similarity index 67% rename from nginx.conf rename to nginx/nginx.conf index 4c5abf81..e09eec2c 100644 --- a/nginx.conf +++ b/nginx/nginx.conf @@ -1,3 +1,6 @@ +# nginx.conf - Extracted Nginx configuration for NOFX Frontend +# This configuration merges enhancements from provided variants: improved gzip, static asset caching, adjusted API proxy (preserving /api/ path), extended timeouts, and a static health response for frontend independence. + server { listen 80; server_name localhost; @@ -6,13 +9,13 @@ server { root /usr/share/nginx/html; index index.html; - # Gzip compression + # Gzip compression (enhanced) gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json; - # Frontend routes (SPA) + # Frontend routes (SPA) with static asset caching location / { try_files $uri $uri/ /index.html; @@ -23,9 +26,9 @@ server { } } - # Proxy API requests to backend + # Proxy API requests to backend (preserves /api/ path, with timeouts) location /api/ { - proxy_pass http://nofx-trading:8080; + proxy_pass http://nofx:8080/api/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -41,9 +44,10 @@ server { proxy_read_timeout 300s; } - # Health check endpoint + # Health check endpoint (static response for frontend health, independent of backend) location /health { return 200 "OK\n"; add_header Content-Type text/plain; + access_log off; } -} +} \ No newline at end of file diff --git a/start.sh b/start.sh index 1a4971e5..f4589f96 100755 --- a/start.sh +++ b/start.sh @@ -1,18 +1,24 @@ #!/bin/bash +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• # NOFX AI Trading System - Docker Quick Start Script -# ไฝฟ็”จๆ–นๆณ•: ./start.sh [command] +# Usage: ./start.sh [command] +# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• set -e -# ้ขœ่‰ฒๅฎšไน‰ +# ------------------------------------------------------------------------ +# Color Definitions +# ------------------------------------------------------------------------ RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color -# ๆ‰“ๅฐๅธฆ้ขœ่‰ฒ็š„ๆถˆๆฏ +# ------------------------------------------------------------------------ +# Utility Functions: Colored Output +# ------------------------------------------------------------------------ print_info() { echo -e "${BLUE}[INFO]${NC} $1" } @@ -29,22 +35,51 @@ print_error() { echo -e "${RED}[ERROR]${NC} $1" } -# ๆฃ€ๆŸฅ Docker ๆ˜ฏๅฆๅฎ‰่ฃ… +# ------------------------------------------------------------------------ +# Detection: Docker Compose Command (Backward Compatible) +# ------------------------------------------------------------------------ +detect_compose_cmd() { + if command -v docker compose &> /dev/null; then + COMPOSE_CMD="docker compose" + elif command -v docker-compose &> /dev/null; then + COMPOSE_CMD="docker-compose" + else + print_error "Docker Compose ๆœชๅฎ‰่ฃ…๏ผ่ฏทๅ…ˆๅฎ‰่ฃ… Docker Compose" + exit 1 + fi + print_info "ไฝฟ็”จ Docker Compose ๅ‘ฝไปค: $COMPOSE_CMD" +} + +# ------------------------------------------------------------------------ +# Validation: Docker Installation +# ------------------------------------------------------------------------ check_docker() { if ! command -v docker &> /dev/null; then print_error "Docker ๆœชๅฎ‰่ฃ…๏ผ่ฏทๅ…ˆๅฎ‰่ฃ… Docker: https://docs.docker.com/get-docker/" exit 1 fi - if ! command -v docker-compose &> /dev/null; then - print_error "Docker Compose ๆœชๅฎ‰่ฃ…๏ผ่ฏทๅ…ˆๅฎ‰่ฃ… Docker Compose" - exit 1 - fi - + detect_compose_cmd print_success "Docker ๅ’Œ Docker Compose ๅทฒๅฎ‰่ฃ…" } -# ๆฃ€ๆŸฅ้…็ฝฎๆ–‡ไปถ +# ------------------------------------------------------------------------ +# Validation: Environment File (.env) +# ------------------------------------------------------------------------ +check_env() { + if [ ! -f ".env" ]; then + print_warning ".env ไธๅญ˜ๅœจ๏ผŒไปŽๆจกๆฟๅคๅˆถ..." + cp .env.example .env + print_info "่ฏท็ผ–่พ‘ .env ๅกซๅ…ฅไฝ ็š„็Žฏๅขƒๅ˜้‡้…็ฝฎ" + print_info "่ฟ่กŒ: nano .env ๆˆ–ไฝฟ็”จๅ…ถไป–็ผ–่พ‘ๅ™จ" + exit 1 + fi + print_success "็Žฏๅขƒๅ˜้‡ๆ–‡ไปถๅญ˜ๅœจ" +} + +# ------------------------------------------------------------------------ +# Validation: Configuration File (config.json) +# ------------------------------------------------------------------------ check_config() { if [ ! -f "config.json" ]; then print_warning "config.json ไธๅญ˜ๅœจ๏ผŒไปŽๆจกๆฟๅคๅˆถ..." @@ -56,15 +91,53 @@ check_config() { print_success "้…็ฝฎๆ–‡ไปถๅญ˜ๅœจ" } -# ๅฏๅŠจๆœๅŠก +# ------------------------------------------------------------------------ +# Build: Frontend (Node.js Based) +# ------------------------------------------------------------------------ +# build_frontend() { +# print_info "ๆฃ€ๆŸฅๅ‰็ซฏๆž„ๅปบ็Žฏๅขƒ..." + +# if ! command -v node &> /dev/null; then +# print_error "Node.js ๆœชๅฎ‰่ฃ…๏ผ่ฏทๅ…ˆๅฎ‰่ฃ… Node.js" +# exit 1 +# fi + +# if ! command -v npm &> /dev/null; then +# print_error "npm ๆœชๅฎ‰่ฃ…๏ผ่ฏทๅ…ˆๅฎ‰่ฃ… npm" +# exit 1 +# fi + +# print_info "ๆญฃๅœจๆž„ๅปบๅ‰็ซฏ..." +# cd web + +# print_info "ๅฎ‰่ฃ… Node.js ไพ่ต–..." +# npm install + +# print_info "ๆž„ๅปบๅ‰็ซฏๅบ”็”จ..." +# npm run build + +# cd .. +# print_success "ๅ‰็ซฏๆž„ๅปบๅฎŒๆˆ" +# } + +# ------------------------------------------------------------------------ +# Service Management: Start +# ------------------------------------------------------------------------ start() { print_info "ๆญฃๅœจๅฏๅŠจ NOFX AI Trading System..." + # Auto-build frontend if missing or forced + # if [ ! -d "web/dist" ] || [ "$1" == "--build" ]; then + # build_frontend + # fi + + # Rebuild images if flag set if [ "$1" == "--build" ]; then print_info "้‡ๆ–ฐๆž„ๅปบ้•œๅƒ..." - docker-compose up -d --build + $COMPOSE_CMD up -d --build else - docker-compose up -d + print_info "ๅฏๅŠจๅฎนๅ™จ..." + $COMPOSE_CMD up -d fi print_success "ๆœๅŠกๅทฒๅฏๅŠจ๏ผ" @@ -75,60 +148,74 @@ start() { print_info "ๅœๆญขๆœๅŠก: ./start.sh stop" } -# ๅœๆญขๆœๅŠก +# ------------------------------------------------------------------------ +# Service Management: Stop +# ------------------------------------------------------------------------ stop() { print_info "ๆญฃๅœจๅœๆญขๆœๅŠก..." - docker-compose stop + $COMPOSE_CMD stop print_success "ๆœๅŠกๅทฒๅœๆญข" } -# ้‡ๅฏๆœๅŠก +# ------------------------------------------------------------------------ +# Service Management: Restart +# ------------------------------------------------------------------------ restart() { print_info "ๆญฃๅœจ้‡ๅฏๆœๅŠก..." - docker-compose restart + $COMPOSE_CMD restart print_success "ๆœๅŠกๅทฒ้‡ๅฏ" } -# ๆŸฅ็œ‹ๆ—ฅๅฟ— +# ------------------------------------------------------------------------ +# Monitoring: Logs +# ------------------------------------------------------------------------ logs() { if [ -z "$2" ]; then - docker-compose logs -f + $COMPOSE_CMD logs -f else - docker-compose logs -f "$2" + $COMPOSE_CMD logs -f "$2" fi } -# ๆŸฅ็œ‹็Šถๆ€ +# ------------------------------------------------------------------------ +# Monitoring: Status +# ------------------------------------------------------------------------ status() { print_info "ๆœๅŠก็Šถๆ€:" - docker-compose ps + $COMPOSE_CMD ps echo "" print_info "ๅฅๅบทๆฃ€ๆŸฅ:" curl -s http://localhost:8080/health | jq '.' || echo "ๅŽ็ซฏๆœชๅ“ๅบ”" } -# ๆธ…็† +# ------------------------------------------------------------------------ +# Maintenance: Clean (Destructive) +# ------------------------------------------------------------------------ clean() { print_warning "่ฟ™ๅฐ†ๅˆ ้™คๆ‰€ๆœ‰ๅฎนๅ™จๅ’Œๆ•ฐๆฎ๏ผ" read -p "็กฎ่ฎคๅˆ ้™ค๏ผŸ(yes/no): " confirm if [ "$confirm" == "yes" ]; then print_info "ๆญฃๅœจๆธ…็†..." - docker-compose down -v + $COMPOSE_CMD down -v print_success "ๆธ…็†ๅฎŒๆˆ" else print_info "ๅทฒๅ–ๆถˆ" fi } -# ๆ›ดๆ–ฐ +# ------------------------------------------------------------------------ +# Maintenance: Update +# ------------------------------------------------------------------------ update() { print_info "ๆญฃๅœจๆ›ดๆ–ฐ..." git pull - docker-compose up -d --build + $COMPOSE_CMD up -d --build print_success "ๆ›ดๆ–ฐๅฎŒๆˆ" } -# ๆ˜พ็คบๅธฎๅŠฉ +# ------------------------------------------------------------------------ +# Help: Usage Information +# ------------------------------------------------------------------------ show_help() { echo "NOFX AI Trading System - Docker ็ฎก็†่„šๆœฌ" echo "" @@ -150,12 +237,15 @@ show_help() { echo " ./start.sh status # ๆŸฅ็œ‹็Šถๆ€" } -# ไธปๅ‡ฝๆ•ฐ +# ------------------------------------------------------------------------ +# Main: Command Dispatcher +# ------------------------------------------------------------------------ main() { check_docker case "${1:-start}" in start) + check_env check_config start "$2" ;; @@ -188,5 +278,5 @@ main() { esac } -# ่ฟ่กŒไธปๅ‡ฝๆ•ฐ -main "$@" +# Execute Main +main "$@" \ No newline at end of file diff --git a/web/.dockerignore b/web/.dockerignore index 2d8c3534..651c8af9 100644 --- a/web/.dockerignore +++ b/web/.dockerignore @@ -1,8 +1,5 @@ # Dependencies node_modules/ -package-lock.json -yarn.lock -pnpm-lock.yaml # Build output (will be regenerated) dist/ diff --git a/web/Dockerfile b/web/Dockerfile deleted file mode 100644 index f7614cad..00000000 --- a/web/Dockerfile +++ /dev/null @@ -1,72 +0,0 @@ -# ๆž„ๅปบ้˜ถๆฎต -FROM node:20-alpine AS builder - -# ่ฎพ็ฝฎๅทฅไฝœ็›ฎๅฝ• -WORKDIR /app - -# ๅคๅˆถ package ๆ–‡ไปถ -COPY package*.json ./ - -# ๅฎ‰่ฃ…ไพ่ต– -RUN npm ci --only=production=false - -# ๅคๅˆถๆบไปฃ็  -COPY . . - -# ๆž„ๅปบๅบ”็”จ -RUN npm run build - -# ่ฟ่กŒ้˜ถๆฎต -FROM nginx:alpine - -# ๅคๅˆถ่‡ชๅฎšไน‰ nginx ้…็ฝฎ -COPY <