fix: 后台实现链接各个服务

This commit is contained in:
Tim
2025-09-29 15:16:32 +08:00
parent a12368602d
commit bb955c98ba
6 changed files with 135 additions and 9 deletions

View File

@@ -28,7 +28,7 @@ REDIS_HOST=redis
REDIS_DATABASE=0
# === RabbitMQ Configuration ===
RABBITMQ_HOST=localhost
RABBITMQ_HOST=local
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest

View File

@@ -47,7 +47,7 @@ app.snippet-length=${SNIPPET_LENGTH:200}
# OpenSearch integration
app.search.enabled=${SEARCH_ENABLED:true}
app.search.host=${OPENSEARCH_HOST:localhost}
app.search.host=${OPENSEARCH_HOST:opensearch}
app.search.port=${OPENSEARCH_PORT:9200}
app.search.scheme=${OPENSEARCH_SCHEME:http}
app.search.username=${OPENSEARCH_USERNAME:}

View File

@@ -13,12 +13,18 @@ services:
- ../backend/src/main/resources/db/init:/docker-entrypoint-initdb.d
networks:
- openisle-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "root", "-p$MYSQL_ROOT_PASSWORD"]
interval: 5s
timeout: 3s
retries: 30
start_period: 20s
# OpenSearch Service
opensearch:
build:
context: .
dockerfile: Dockerfile
dockerfile: opensearch.Dockerfile
container_name: opensearch
environment:
- cluster.name=os-single
@@ -38,6 +44,14 @@ services:
- "${OPENSEARCH_PORT:-9200}:9200"
- "${OPENSEARCH_METRICS_PORT:-9600}:9600"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9200/_cluster/health >/dev/null"]
interval: 10s
timeout: 5s
retries: 30
start_period: 60s
networks:
- openisle-network
dashboards:
image: opensearchproject/opensearch-dashboards:3.0.0
@@ -50,6 +64,8 @@ services:
depends_on:
- opensearch
restart: unless-stopped
networks:
- openisle-network
rabbitmq:
image: rabbitmq:3.13-management
@@ -85,16 +101,26 @@ services:
working_dir: /app
env_file:
- ../.env
environment:
- MYSQL_HOST=mysql
- OPENSEARCH_HOST=opensearch
- RABBITMQ_HOST=rabbitmq
ports:
- "${SERVER_PORT:-8080}:${SERVER_PORT:-8080}"
volumes:
- ../backend:/app
- maven-repo:/root/.m2
depends_on:
- mysql
- redis
- rabbitmq
- websocket-service
mysql:
condition: service_healthy
redis:
condition: service_started
rabbitmq:
condition: service_started
websocket-service:
condition: service_started
opensearch:
condition: service_healthy
command: mvn clean spring-boot:run -Dmaven.test.skip=true
networks:
- openisle-network
@@ -116,9 +142,9 @@ services:
networks:
- openisle-network
frontend:
frontend_dev:
image: node:20
container_name: openisle-frontend
container_name: openisle-frontend-dev
working_dir: /app
env_file:
- ../.env
@@ -133,6 +159,30 @@ services:
- websocket-service
networks:
- openisle-network
profiles:
- dev
frontend_service:
build:
context: ..
dockerfile: frontend-service.Dockerfile
container_name: openisle-frontend-service
working_dir: /app
env_file:
- ../.env
volumes:
- ../frontend_nuxt:/app
- frontend-service-node-modules:/app/node_modules
- frontend-static:/var/www/openisle
ports:
- "${FRONTEND_SERVICE_PORT:-3001}:3000"
depends_on:
- springboot
- websocket-service
networks:
- openisle-network
profiles:
- service
networks:
openisle-network:
@@ -145,3 +195,5 @@ volumes:
rabbitmq-data:
websocket-maven-repo:
frontend-node-modules:
frontend-service-node-modules:
frontend-static:

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env bash
set -euo pipefail
cd /app
echo "👉 Building frontend (Nuxt SSR)..."
if [ -f .env.production.example ] && [ ! -f .env ]; then
echo "📄 Copying .env.production.example to .env"
cp .env.production.example .env
fi
npm ci
npm run build
echo "🧪 Smoke-testing: nuxt generate (artifacts will NOT be used)..."
SSR_OUTPUT_DIR=".output"
SSR_OUTPUT_BAK=".output-ssr-backup-$$"
GEN_FAIL_MSG="❌ Generate smoke test failed"
if [ ! -d "${SSR_OUTPUT_DIR}" ]; then
echo "❌ 未发现 ${SSR_OUTPUT_DIR},请先确保 npm run build 成功执行"
exit 1
fi
mv "${SSR_OUTPUT_DIR}" "${SSR_OUTPUT_BAK}"
restore_on_fail() {
if [ -d ".output" ]; then
mv .output ".output-generate-failed-$(date +%s)" || true
fi
mv "${SSR_OUTPUT_BAK}" "${SSR_OUTPUT_DIR}"
}
trap 'restore_on_fail; echo "${GEN_FAIL_MSG}: unexpected error"; exit 1' ERR
NUXT_TELEMETRY_DISABLED=1 \
NITRO_PRERENDER_FAIL_ON_ERROR=1 \
npx nuxi generate --preset static
if [ ! -d ".output/public" ]; then
restore_on_fail
echo "${GEN_FAIL_MSG}: .output/public not found"
exit 1
fi
rm -rf ".output"
mv "${SSR_OUTPUT_BAK}" "${SSR_OUTPUT_DIR}"
trap - ERR
echo "✅ Generate smoke test passed."
if [ -d ".output/public" ]; then
mkdir -p /var/www/openisle
rsync -a --delete .output/public/ /var/www/openisle/
else
echo "❌ 未发现 .output/public检查 nuxt.config.ts/nitro preset"
exit 1
fi
echo "🚀 Starting Nuxt SSR server..."
exec node .output/server/index.mjs

View File

@@ -0,0 +1,12 @@
FROM node:20
RUN apt-get update \
&& apt-get install -y --no-install-recommends rsync \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY docker/frontend-service-entrypoint.sh /usr/local/bin/frontend-service-entrypoint.sh
RUN chmod +x /usr/local/bin/frontend-service-entrypoint.sh
CMD ["frontend-service-entrypoint.sh"]