mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-09-03 14:30:23 +08:00
调整部分代码
This commit is contained in:
2
.env
2
.env
@@ -4,7 +4,7 @@
|
||||
NEXT_PUBLIC_CACHING_TIME=300
|
||||
|
||||
# 项目后端API
|
||||
NEXT_PUBLIC_PROJECT_API=http://server.thrive.site:9003/api
|
||||
NEXT_PUBLIC_PROJECT_API=https://你的后端域名/api
|
||||
|
||||
# 高德地图API(可选)
|
||||
# 配置教程:https://docs.liuyuyang.net/docs/项目部署/API/高德地图.html
|
||||
|
||||
54
Dockerfile
54
Dockerfile
@@ -1,40 +1,26 @@
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/liuyi778/nginx-npm
|
||||
LABEL authors="坐公交也用券"
|
||||
LABEL HOME="https://gitee.com/liumou_site"
|
||||
LABEL PROJECT="https://github.com/LiuYuYang01/ThriveX-Blog"
|
||||
LABEL BUILD_DATE="2025-01-14"
|
||||
ENV TZ=Asia/Shanghai
|
||||
ARG HTML_VERSION=2.1.5
|
||||
ENV HTML_VERSION=${HTML_VERSION}
|
||||
# 定义后端地址
|
||||
ARG BACKEND_HOST
|
||||
# 定义后端端口
|
||||
ARG BACKEND_PORT=9004
|
||||
ENV BACKEND_PORT=${BACKEND_PORT}
|
||||
# 定义管理后台地址
|
||||
ARG ADMIN_HOST
|
||||
# 设置apt不交互
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
# 设置APT不显示详情
|
||||
ENV DEBCONF_NONINTERACTIVE_SEEN=true
|
||||
# 设置时区
|
||||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
# 设置工作目录
|
||||
# 使用官方的Node.js镜像作为基础镜像
|
||||
FROM node:20-alpine
|
||||
|
||||
# # 设置工作目录
|
||||
WORKDIR /thrive
|
||||
# 复制所有文件到工作目录
|
||||
COPY ../package*.json .
|
||||
COPY docker/thrive.conf /etc/nginx/conf.d/default.conf
|
||||
COPY docker/run.sh /thrive/run.sh
|
||||
COPY src /thrive/src
|
||||
COPY public /thrive/public
|
||||
COPY *s /thrive/
|
||||
COPY p* /thrive/
|
||||
|
||||
# 配置 npm 镜像源
|
||||
RUN npm config set registry https://registry.npmmirror.com
|
||||
|
||||
# 复制package.json和package-lock.json
|
||||
COPY package*.json .
|
||||
|
||||
# 安装依赖
|
||||
RUN npm install
|
||||
# 修改权限
|
||||
RUN chmod 777 /thrive/run.sh
|
||||
|
||||
# 复制所有文件到工作目录
|
||||
COPY . .
|
||||
|
||||
# 构建Next.js应用
|
||||
RUN npm run build
|
||||
|
||||
# 暴露应用运行的端口
|
||||
EXPOSE 80
|
||||
EXPOSE 9001
|
||||
|
||||
CMD ["/thrive/run.sh"]
|
||||
# 启动Next.js应用
|
||||
CMD ["npm", "start"]
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
# 打包vue 项目
|
||||
echo "start build"
|
||||
# 设置npm镜像源为国内源,以加快依赖安装速度
|
||||
npm config set registry https://registry.npmmirror.com
|
||||
# 安装项目依赖
|
||||
npm install
|
||||
# 运行构建命令,生成dist目录
|
||||
npm run build
|
||||
echo "build success"
|
||||
# 删除旧的docker/html目录
|
||||
rm -rf ./docker/html
|
||||
# 将新构建的dist目录复制到docker/html
|
||||
cp -rf ./dist ../docker/html
|
||||
echo "copy success"
|
||||
echo "start docker build"
|
||||
# 进入docker目录
|
||||
pushd ./docker
|
||||
# 检查env.sh文件是否存在
|
||||
if [[ ! -e env.sh ]];then
|
||||
echo "env.sh not found"
|
||||
exit 1
|
||||
fi
|
||||
# 加载环境变量
|
||||
source env.sh
|
||||
# 检查环境变量
|
||||
if [[ -z "${images}" ]];then
|
||||
echo "images not Set, Please set env.sh"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "${version}" ]];then
|
||||
echo "version not Set, Please set env.sh"
|
||||
exit 1
|
||||
fi
|
||||
# 判断 server.conf是否存在
|
||||
if [[ ! -e server.conf ]];then
|
||||
echo "server.conf not found"
|
||||
exit 1
|
||||
fi
|
||||
# 判断 ./html目录是否存在
|
||||
if [[ ! -e ./html ]];then
|
||||
echo "html directory not found"
|
||||
exit 1
|
||||
fi
|
||||
# 判断 Dockerfile是否存在
|
||||
if [[ ! -e Dockerfile ]];then
|
||||
echo "Dockerfile not found"
|
||||
exit 1
|
||||
fi
|
||||
# 构建docker镜像
|
||||
docker build -t ${images}:latest .
|
||||
if [[ $? -ne 0 ]];then
|
||||
echo "build failed"
|
||||
exit 1
|
||||
fi
|
||||
# 给镜像打标签
|
||||
docker tag ${images}:latest ${images}:${version}
|
||||
|
||||
# 如果server.conf存在,则运行容器
|
||||
if [[ -e server.conf ]];then
|
||||
c="docker run -d --name nginx -P -v $(pwd)/server.conf:/etc/nginx/conf.d/server.conf -v $(pwd)/html:/usr/share/nginx/html ${images}:latest"
|
||||
$c
|
||||
if [[ $? -ne 0 ]];then
|
||||
echo $c
|
||||
echo "run failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "Run Success"
|
||||
fi
|
||||
# 如果设置了push变量,则推送镜像到仓库
|
||||
if [[ "${push}" == "1" ]];then
|
||||
docker push ${images}:latest
|
||||
docker push ${images}:${version}
|
||||
fi
|
||||
# 删除打包数据
|
||||
rm -rf ./dist ./docker/html
|
||||
echo "Success"
|
||||
@@ -1,6 +0,0 @@
|
||||
# 定义镜像
|
||||
images=registry.cn-hangzhou.aliyuncs.com/liuyi778/thrive-nginx
|
||||
# 定义版本号变量
|
||||
version=2.2.1
|
||||
# 定义是否推送镜像变量: 0(不推送) 1(推送)
|
||||
push=0
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# 启用调试模式
|
||||
set -x
|
||||
# 如果BACKEND_PORT环境变量已设置,则将其值赋给PORT变量
|
||||
if [[ -n "${BACKEND_PORT}" ]];then
|
||||
export PORT=${BACKEND_PORT}
|
||||
fi
|
||||
|
||||
# 如果BACKEND_HOST环境变量已设置,则将其值赋给HOST变量,否则使用默认值9003
|
||||
if [[ -n "${BACKEND_HOST}" ]];then
|
||||
export HOST=${BACKEND_HOST}
|
||||
else
|
||||
echo "HOST is not set, use default value: 9003"
|
||||
fi
|
||||
|
||||
# 确保BACKEND_HOST已设置,如果未设置则提示用户并退出脚本
|
||||
if [[ -n "${BACKEND_HOST}" ]];then
|
||||
# 检查/etc/hosts文件中是否存在BACKEND_HOST,如果不存在则将其添加到文件中
|
||||
grep "${BACKEND_HOST}" /etc/hosts >/dev/null 2>&1 || echo "${BACKEND_HOST} $(hostname)" >> /etc/hosts
|
||||
echo "HOST is set to ${BACKEND_HOST}"
|
||||
else
|
||||
echo "Please set BACKEND_HOST, Use -e BACKEND_HOST=x.x.x.x"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 修改后端地址
|
||||
sed -i "s@thrive.Server.demo;@${BACKEND_HOST}:${BACKEND_PORT};@" /etc/nginx/conf.d/*.conf
|
||||
sed -i "s@thrive.admin.demo@${ADMIN_HOST}@" /etc/nginx/conf.d/*.conf
|
||||
|
||||
# 更新前端请求的后端地址
|
||||
if [[ -e /thrive/src/utils/request.ts ]];then
|
||||
sed -i "s@http://.*:.*;@${BACKEND_HOST}:${BACKEND_PORT}@" /thrive/src/utils/request.ts
|
||||
else
|
||||
echo "/thrive/src/utils/request.ts not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查后台网页源码是否存在
|
||||
if [[ -e /thrive/admin ]];then
|
||||
echo "thrive admin page exists"
|
||||
else
|
||||
echo "Please set up data volume mapping, for example: -v /data/ThriveX-Admin/dist:/thrive/admin "
|
||||
exit 1
|
||||
fi
|
||||
# 检查 index.html是否存在
|
||||
if [[ -e /thrive/admin/index.html ]];then
|
||||
echo "index.html detection successful"
|
||||
else
|
||||
echo "index.html detection failed"
|
||||
echo "Please set up data volume mapping, for example: -v /data/ThriveX-Admin/dist:/thrive/admin "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查nginx配置文件的正确性
|
||||
nginx -t
|
||||
if [ $? -ne 0 ];then
|
||||
echo "nginx config error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 进入项目目录并启动开发服务器
|
||||
cd /thrive
|
||||
npm run dev&
|
||||
|
||||
# 启动Nginx
|
||||
nginx -g "daemon off;"
|
||||
@@ -1,35 +0,0 @@
|
||||
upstream Server {
|
||||
server thrive.Server.demo:9004;
|
||||
}
|
||||
upstream Admin {
|
||||
server thrive.admin.demo:80;
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
client_max_body_size 1024m;
|
||||
# 处理 /api 开头的路径,走反向代理
|
||||
location /api {
|
||||
proxy_pass http://Server;
|
||||
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;
|
||||
}
|
||||
# 处理 /admin 开头的路径,走反向代理
|
||||
localhost /admin {
|
||||
proxy_pass http://Admin;
|
||||
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;
|
||||
}
|
||||
# 处理网页,走npm反向代理
|
||||
location / {
|
||||
proxy_pass http://localhost:9003;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// 最新调整:在 .env 文件中配置项目后端 API 地址
|
||||
const url = "https://api.liuyuyang.net/api"
|
||||
const url = process.env.NEXT_PUBLIC_PROJECT_API
|
||||
// 配置页面缓存时间
|
||||
const cachingTime = +process.env.NEXT_PUBLIC_CACHING_TIME!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user