[refactored] update method of production environment
This commit is contained in:
parent
6d3b3435fe
commit
6f9dd0224c
@ -1,4 +1,10 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
## v0.0.1.20240925_alpha
|
||||||
|
### 🚀Refactored
|
||||||
|
- 修改next.config.mjs内的output为standalone模式,便于后面生产部署
|
||||||
|
- 优化编译部署命令
|
||||||
|
- 使用run.ps1辅助执行编译,部署等命令
|
||||||
|
|
||||||
|
|
||||||
## v0.0.1.20240912_base
|
## v0.0.1.20240912_base
|
||||||
|
|
||||||
|
@ -9,8 +9,10 @@ RUN npm config set registry https://registry.npmmirror.com &&\
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# 指定容器创建时的默认命令。(可以被覆盖)
|
# 指定容器创建时的默认命令。(可以被覆盖)
|
||||||
CMD ln -snf /env/node_modules /app &&\
|
CMD ln -snf /env/node_modules /app &&\
|
||||||
npm run dev
|
npm run start
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 声明容器运行时监听的特定网络端口。但不会真的映射到外面
|
# 声明容器运行时监听的特定网络端口。但不会真的映射到外面
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
21
README.md
21
README.md
@ -1,12 +1,13 @@
|
|||||||
## Getting Started
|
## 开发命令
|
||||||
|
注意:此命令依赖PowerShell 7
|
||||||
|
- `./run.ps1 build_docker`: 构建运行环境的容器
|
||||||
|
- `./run.ps1 dev`: 启动开发环境
|
||||||
|
- `./run.ps1 prod`: 启动生产环境
|
||||||
|
|
||||||
First, run the development server:
|
- `./run.ps1 remove_docker`: 删除相关容器
|
||||||
|
- `./run.ps1 release`:打包生产环境所需的文件
|
||||||
|
|
||||||
```bash
|
## 使用方法
|
||||||
docker compose up
|
1. 当更新docker运行环境后运行`./run.ps1 build_docker`重新编译镜像
|
||||||
```
|
2. 当开发时运行`./run.ps1 dev`即可,当文件修改后能够自动重新编译
|
||||||
|
2. 当需要发布时,运行`./run.ps1 release`即可得到相关文件,然后运行 `./run.ps1 prod`可直接尝试生成的文件是否好用
|
||||||
发布:
|
|
||||||
1. 在docker环境内编译,npm run build
|
|
||||||
2. 打包,Compress-Archive -Path .next/standalone/*,.next/static -DestinationPath ./release/tmp.zip
|
|
||||||
3. 运行 docker run -p 4000:3000 -v C:\SEMS-development\SEMS-on-device-server\release:/app sems-on-device-server-server:latest sh -c 'ln -snf /env/node_modules /app && npm run start'
|
|
@ -1,8 +0,0 @@
|
|||||||
services:
|
|
||||||
server:
|
|
||||||
build: ./
|
|
||||||
container_name: sems_on_device_server
|
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
volumes:
|
|
||||||
- ./:/app
|
|
@ -1,4 +1,4 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {};
|
const nextConfig = {output: 'standalone'};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
"./"
|
"./"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"NODE_ENV": "development",
|
"NODE_ENV": "development"
|
||||||
"RAW_DATA_DIR": "C:/tmp/"
|
|
||||||
},
|
},
|
||||||
"ext": "js,json"
|
"ext": "js,json"
|
||||||
}
|
}
|
65
run.ps1
Normal file
65
run.ps1
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
Param( [string]$cmd, [string]$version)
|
||||||
|
|
||||||
|
If($cmd -eq "build_docker"){
|
||||||
|
docker build -t sems-on-device-server:latest .
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
If($cmd -eq "dev"){
|
||||||
|
docker run --rm -p "22110:22110" -v "C:\SEMS-development\SEMS-on-device-server:/app" -v "C:\tmp:/data" --name sems-on-device-server sems-on-device-server:latest sh -c "ln -snf /env/node_modules /app && npm run dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
If($cmd -eq "prod"){
|
||||||
|
docker run --rm -p "22110:22110" -v "C:\SEMS-development\SEMS-on-device-server\build\latest:/app" -v "C:\tmp:/data" --name sems-on-device-server sems-on-device-server:latest
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
If($cmd -eq "remove_docker"){
|
||||||
|
docker stop sems-on-device-server
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
If($cmd -eq "release"){
|
||||||
|
|
||||||
|
# 提前删除.next文件夹,根据实测,应该会影响后面的编编译,原因未知
|
||||||
|
# 现象:单独在powershell命令行执行docker run没问题,但是在脚本中执行,完全一样的命令,就会报错
|
||||||
|
# 然后分别从命令行/脚本进入容器内docker run --rm -it -v "C:\SEMS-development\SEMS-on-device-server:/app" --name sems-on-device-server sems-on-device-server:latest sh
|
||||||
|
# 手动执行npm run build发现仍然时命令行可以编译,但是脚本会报错找不到库,
|
||||||
|
# 然后发现在脚本环境下,npm run build执行前node_model文件夹正常,但执行后,发现为空白了,node_model文件夹下什么都没了
|
||||||
|
# 猜测是因为脚本执行有安全限制,限制了资源使用?不是特别确定原因。
|
||||||
|
# 但发现删除了.next后就正常了
|
||||||
|
If(Test-Path "./.next"){
|
||||||
|
|
||||||
|
Remove-Item -Path "./.next" -Recurse
|
||||||
|
Write-Host "./.next is Removed"
|
||||||
|
}
|
||||||
|
#在docker容器内编译
|
||||||
|
docker run --rm -v "C:\SEMS-development\SEMS-on-device-server:/app" --name sems-on-device-server sems-on-device-server:latest sh -c "ln -snf /env/node_modules /app && npm run build"
|
||||||
|
|
||||||
|
#.next/static文件夹存在则证明编译完了
|
||||||
|
If (Test-Path ".next/static"){
|
||||||
|
#复制static文件夹
|
||||||
|
Copy-Item -Path .next/static -Destination .next/standalone/.next -Recurse -Force
|
||||||
|
#把.next/standalone文件夹下的所有文件与.next打包。之所以不用通配符.next/standalone/*是因为这个目录下还有node_modules是软连接,会报错。
|
||||||
|
Compress-Archive -Path .next/standalone/*.*,.next/standalone/.next -DestinationPath "./build/SEMS-on-device-server-$version.zip" -Force
|
||||||
|
|
||||||
|
Write-Host "Released /build/SEMS-on-device-server-$version.zip"
|
||||||
|
|
||||||
|
#直接解压一份,便于后面模拟生产环境测试
|
||||||
|
If(Test-Path "./build/latest"){ #如果当前目录下build文件夹存在
|
||||||
|
Remove-Item -Path "./build/latest" -Recurse #递归删除build文件夹
|
||||||
|
}
|
||||||
|
|
||||||
|
Expand-Archive -Path "./build/SEMS-on-device-server-$version.zip" -DestinationPath "./build/latest" -Force
|
||||||
|
|
||||||
|
Write-Host "Expanded SEMS-on-device-server-$version.zip to ./build/latest"
|
||||||
|
}else{
|
||||||
|
|
||||||
|
Write-Host "Build Error, Please retry"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -19,7 +19,7 @@ function get_latest_file_path(raw_spectral_data_dir){
|
|||||||
async function main(){
|
async function main(){
|
||||||
try {
|
try {
|
||||||
// process.send("child process started");
|
// process.send("child process started");
|
||||||
const raw_spectral_data_dir="C:/tmp/"
|
const raw_spectral_data_dir="/data"
|
||||||
|
|
||||||
let last_data_file=null
|
let last_data_file=null
|
||||||
let latest_data_file=null
|
let latest_data_file=null
|
||||||
@ -58,7 +58,7 @@ async function main(){
|
|||||||
let upload_data={"spectral_data_bin":spectral_buffer }
|
let upload_data={"spectral_data_bin":spectral_buffer }
|
||||||
let upload_data_compressed = pako.gzip(pack(upload_data))
|
let upload_data_compressed = pako.gzip(pack(upload_data))
|
||||||
|
|
||||||
let response=await fetch("http://127.0.0.1:5000/post", {
|
let response=await fetch("http://inference_server:8000/post", {
|
||||||
method: "post",
|
method: "post",
|
||||||
body: upload_data_compressed
|
body: upload_data_compressed
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ import {fork} from "node:child_process"
|
|||||||
|
|
||||||
const dev = process.env.NODE_ENV !== "production";
|
const dev = process.env.NODE_ENV !== "production";
|
||||||
const hostname = "0.0.0.0";
|
const hostname = "0.0.0.0";
|
||||||
const port = 3000;
|
const port = 22110;
|
||||||
// when using middleware `hostname` and `port` must be provided below
|
// when using middleware `hostname` and `port` must be provided below
|
||||||
const app = next({ dev, hostname, port });
|
const app = next({ dev, hostname, port });
|
||||||
const handler = app.getRequestHandler();
|
const handler = app.getRequestHandler();
|
||||||
|
Loading…
Reference in New Issue
Block a user