From 1ea863cb2c603944087f7b7f219a97502f1a36b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Sun, 31 May 2026 20:11:38 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=20Dockerfile=20?= =?UTF-8?q?=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 14 +- easyflow-ui-admin/package.json | 2 +- easyflow-ui-admin/scripts/deploy/Dockerfile | 27 +-- .../deploy/build-local-docker-image.sh | 55 ----- easyflow-ui-admin/scripts/deploy/nginx.conf | 191 ++++++++---------- 5 files changed, 105 insertions(+), 184 deletions(-) delete mode 100644 easyflow-ui-admin/scripts/deploy/build-local-docker-image.sh diff --git a/Dockerfile b/Dockerfile index 64489d9..e49e93e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# 后端构建脚本 FROM --platform=linux/amd64 swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/eclipse-temurin:17-jre ENV LANG=C.UTF-8 @@ -18,9 +19,18 @@ RUN useradd --system --create-home easyflow && \ apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates \ + curl \ + gnupg && \ + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource.gpg.key && \ + gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource.gpg.key && \ + chmod 644 /etc/apt/keyrings/nodesource.gpg && \ + printf "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main\n" > /etc/apt/sources.list.d/nodesource.list && \ + rm -f /tmp/nodesource.gpg.key && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ inotify-tools \ nodejs \ - npm \ python3 \ python3-pip \ python3-venv \ @@ -29,7 +39,7 @@ RUN useradd --system --create-home easyflow && \ ln -sf /usr/bin/pip3 /usr/local/bin/pip && \ npm config set registry "${NPM_CONFIG_REGISTRY}" && \ printf "registry=%s\n" "${NPM_CONFIG_REGISTRY}" > /etc/npmrc && \ - npm install -g pnpm && \ + npm install -g pnpm@10.17.1 && \ pnpm config set registry "${NPM_CONFIG_REGISTRY}" && \ mkdir -p /etc/pip && \ printf "[global]\nindex-url = %s\ntrusted-host = %s\n" "${PIP_INDEX_URL}" "${PIP_TRUSTED_HOST}" > /etc/pip.conf && \ diff --git a/easyflow-ui-admin/package.json b/easyflow-ui-admin/package.json index 4bb9261..d630db2 100644 --- a/easyflow-ui-admin/package.json +++ b/easyflow-ui-admin/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build", "build:analyze": "turbo build:analyze", - "build:docker": "./scripts/deploy/build-local-docker-image.sh", + "build:docker": "docker buildx build --platform linux/amd64 -f scripts/deploy/Dockerfile -t easyflow-frontend:0.1 --load .", "build:app": "pnpm run build --filter=@easyflow/app", "changeset": "pnpm exec changeset", "check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type && pnpm check:cspell", diff --git a/easyflow-ui-admin/scripts/deploy/Dockerfile b/easyflow-ui-admin/scripts/deploy/Dockerfile index 99d7bf3..ab567eb 100644 --- a/easyflow-ui-admin/scripts/deploy/Dockerfile +++ b/easyflow-ui-admin/scripts/deploy/Dockerfile @@ -1,38 +1,29 @@ -FROM node:22-slim AS builder +# 前端构建脚本 +FROM --platform=$BUILDPLATFORM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:24-slim AS builder -# --max-old-space-size ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" ENV NODE_OPTIONS=--max-old-space-size=8192 ENV TZ=Asia/Shanghai -RUN npm i -g corepack +RUN npm install -g pnpm@10.17.1 WORKDIR /app -# copy package.json and pnpm-lock.yaml to workspace COPY . /app -# 安装依赖 -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile +RUN --mount=type=cache,id=easyflow-admin-pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN pnpm run build -RUN echo "Builder Success 🎉" +FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stable-alpine AS production -FROM nginx:stable-alpine AS production +RUN rm -f /etc/nginx/conf.d/default.conf -# 配置 nginx -RUN echo "types { application/javascript js mjs; }" > /etc/nginx/conf.d/mjs.conf \ - && rm -rf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/app/dist/ /usr/share/nginx/html/flow/ +COPY scripts/deploy/nginx.conf /etc/nginx/nginx.conf -# 复制构建产物 -COPY --from=builder /app/app/dist /usr/share/nginx/html RUN chown -R nginx:nginx /usr/share/nginx/html -# 复制 nginx 配置 -COPY --from=builder /app/scripts/deploy/nginx.conf /etc/nginx/nginx.conf +EXPOSE 80 -EXPOSE 8080 - -# 启动 nginx CMD ["nginx", "-g", "daemon off;"] diff --git a/easyflow-ui-admin/scripts/deploy/build-local-docker-image.sh b/easyflow-ui-admin/scripts/deploy/build-local-docker-image.sh deleted file mode 100644 index 42c928c..0000000 --- a/easyflow-ui-admin/scripts/deploy/build-local-docker-image.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -LOG_FILE=${SCRIPT_DIR}/build-local-docker-image.log -ERROR="" -IMAGE_NAME="easyflow-admin-local" - -function stop_and_remove_container() { - # Stop and remove the existing container - docker stop ${IMAGE_NAME} >/dev/null 2>&1 - docker rm ${IMAGE_NAME} >/dev/null 2>&1 -} - -function remove_image() { - # Remove the existing image - docker rmi easyflow-admin-pro >/dev/null 2>&1 -} - -function install_dependencies() { - # Install all dependencies - cd ${SCRIPT_DIR} - pnpm install || ERROR="install_dependencies failed" -} - -function build_image() { - # build docker - docker build ../../ -f Dockerfile -t ${IMAGE_NAME} || ERROR="build_image failed" -} - -function log_message() { - if [[ ${ERROR} != "" ]]; - then - >&2 echo "build failed, Please check build-local-docker-image.log for more details" - >&2 echo "ERROR: ${ERROR}" - exit 1 - else - echo "docker image with tag '${IMAGE_NAME}' built sussessfully. Use below sample command to run the container" - echo "" - echo "docker run -d -p 8010:8080 --name ${IMAGE_NAME} ${IMAGE_NAME}" - fi -} - -echo "Info: Stopping and removing existing container and image" | tee ${LOG_FILE} -stop_and_remove_container -remove_image - -echo "Info: Installing dependencies" | tee -a ${LOG_FILE} -install_dependencies 1>> ${LOG_FILE} 2>> ${LOG_FILE} - -if [[ ${ERROR} == "" ]]; then - echo "Info: Building docker image" | tee -a ${LOG_FILE} - build_image 1>> ${LOG_FILE} 2>> ${LOG_FILE} -fi - -log_message | tee -a ${LOG_FILE} diff --git a/easyflow-ui-admin/scripts/deploy/nginx.conf b/easyflow-ui-admin/scripts/deploy/nginx.conf index 11285b7..9d3b2d2 100644 --- a/easyflow-ui-admin/scripts/deploy/nginx.conf +++ b/easyflow-ui-admin/scripts/deploy/nginx.conf @@ -1,123 +1,98 @@ - -#user nobody; -worker_processes 1; - -#error_log logs/error.log; -#error_log logs/error.log notice; -#error_log logs/error.log info; - -#pid logs/nginx.pid; - +worker_processes auto; events { - worker_connections 1024; + worker_connections 1024; } - http { - include mime.types; - default_type application/octet-stream; + include /etc/nginx/mime.types; + default_type application/octet-stream; - sendfile on; - # tcp_nopush on; + sendfile on; + keepalive_timeout 65; + client_max_body_size 500m; - #keepalive_timeout 0; - # keepalive_timeout 65; - - # gzip on; - # gzip_buffers 32 16k; - # gzip_comp_level 6; - # gzip_min_length 1k; - # gzip_static on; - # gzip_types text/plain - # text/css - # application/javascript - # application/json - # application/x-javascript - # text/xml - # application/xml - # application/xml+rss - # text/javascript; #设置压缩的文件类型 - # gzip_vary on; - - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } - - # 如需多机负载均衡,在此增加多个后端地址 - upstream easyflow_api { - server easyflow-api:8080; - keepalive 64; - } - - server { - listen 8080; - server_name localhost; - - location / { - root /usr/share/nginx/html; - try_files $uri $uri/ /index.html; - index index.html; - # Enable CORS - add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; - add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain charset=UTF-8'; - add_header 'Content-Length' 0; - return 204; - } + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; } - # WebSocket(语音链路) - location /api/v1/bot/ws/audio { - proxy_pass http://easyflow_api; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - } + resolver 127.0.0.11 valid=30s ipv6=off; - # SSE/HTTP API - location /api/ { - proxy_pass http://easyflow_api; - proxy_http_version 1.1; - proxy_set_header Connection ""; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - proxy_buffering off; - proxy_cache off; - } + server { + listen 80; + server_name _; - location /userCenter/ { - proxy_pass http://easyflow_api; - proxy_http_version 1.1; - proxy_set_header Connection ""; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - proxy_buffering off; - proxy_cache off; - } + location = / { + return 302 /flow/; + } - error_page 500 502 503 504 /50x.html; + location = /flow { + return 301 /flow/; + } - location = /50x.html { - root /usr/share/nginx/html; + location = /flow/api { + return 301 /flow/api/; + } + + location = /flow/storage { + return 301 /flow/storage/; + } + + location = /flow/api/v1/bot/ws/audio { + set $easyflow_backend http://backend:8111; + rewrite ^/flow/(.*)$ /$1 break; + proxy_pass $easyflow_backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header X-Forwarded-Prefix /flow; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_redirect off; + } + + location ^~ /flow/api/ { + set $easyflow_backend http://backend:8111; + rewrite ^/flow/api/(.*)$ /api/$1 break; + proxy_pass $easyflow_backend; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header X-Forwarded-Prefix /flow; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_buffering off; + proxy_cache off; + proxy_redirect off; + } + + location ^~ /flow/storage/ { + set $easyflow_minio http://minio-shared:9000; + rewrite ^/flow/storage/(.*)$ /easyflow/$1 break; + proxy_pass $easyflow_minio; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + } + + location ^~ /flow/ { + root /usr/share/nginx/html; + try_files $uri $uri/ /flow/index.html; + } } - } }