Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +39 -13
Dockerfile
CHANGED
|
@@ -12,28 +12,54 @@ RUN git clone https://github.com/diegosouzapw/OmniRoute.git .
|
|
| 12 |
RUN sed -i '/"sqlite-vec/d' package.json || true
|
| 13 |
RUN sed -i '/"sqlite-vec-linux-x64/d' package.json || true
|
| 14 |
|
| 15 |
-
# 3. 【
|
| 16 |
-
#
|
| 17 |
RUN node -e " \
|
| 18 |
const fs = require('fs'); \
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
} \
|
| 25 |
-
fs.writeFileSync('next.config.mjs', content); \
|
| 26 |
"
|
| 27 |
|
| 28 |
-
# 4. 安装
|
| 29 |
RUN npm install --include=dev
|
| 30 |
|
| 31 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
ENV PORT=7860
|
| 33 |
ENV OMNIROUTE_PORT=7860
|
| 34 |
ENV HOST=0.0.0.0
|
| 35 |
-
ENV NODE_ENV=
|
| 36 |
EXPOSE 7860
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
CMD ["
|
|
|
|
| 12 |
RUN sed -i '/"sqlite-vec/d' package.json || true
|
| 13 |
RUN sed -i '/"sqlite-vec-linux-x64/d' package.json || true
|
| 14 |
|
| 15 |
+
# 3. 【降维打击】编写自动化脚本,扫描并把 messages 文件夹下所有 JSON 的扁平化带点 Key,
|
| 16 |
+
# 全部完美重构为带层级的对象(正如报错日志里 lodash.set 提示的那样)
|
| 17 |
RUN node -e " \
|
| 18 |
const fs = require('fs'); \
|
| 19 |
+
const path = require('path'); \
|
| 20 |
+
function unflatten(data) { \
|
| 21 |
+
const result = {}; \
|
| 22 |
+
for (const i in data) { \
|
| 23 |
+
if (i.includes('.')) { \
|
| 24 |
+
const keys = i.split('.'); \
|
| 25 |
+
keys.reduce((r, e, j) => { \
|
| 26 |
+
return r[e] || (r[e] = keys.length - 1 === j ? data[i] : {}); \
|
| 27 |
+
}, result); \
|
| 28 |
+
} else { \
|
| 29 |
+
result[i] = data[i]; \
|
| 30 |
+
} \
|
| 31 |
+
} \
|
| 32 |
+
return result; \
|
| 33 |
+
} \
|
| 34 |
+
const localesDir = path.join(process.cwd(), 'messages'); \
|
| 35 |
+
if (fs.existsSync(localesDir)) { \
|
| 36 |
+
fs.readdirSync(localesDir).forEach(file => { \
|
| 37 |
+
if (file.endsWith('.json')) { \
|
| 38 |
+
const filePath = path.join(localesDir, file); \
|
| 39 |
+
const json = JSON.parse(fs.readFileSync(filePath, 'utf8')); \
|
| 40 |
+
if (json.compliance && json.compliance.eventTypes) { \
|
| 41 |
+
json.compliance.eventTypes = unflatten(json.compliance.eventTypes); \
|
| 42 |
+
} \
|
| 43 |
+
fs.writeFileSync(filePath, JSON.stringify(json, null, 2)); \
|
| 44 |
+
console.log('Successfully patched translation file:', file); \
|
| 45 |
+
} \
|
| 46 |
+
}); \
|
| 47 |
} \
|
|
|
|
| 48 |
"
|
| 49 |
|
| 50 |
+
# 4. 干净安装所有依赖
|
| 51 |
RUN npm install --include=dev
|
| 52 |
|
| 53 |
+
# 5. 执行真正安全的生产构建(此时多语言 Key 已经合规,Next.js 绝不会拒绝打包)
|
| 54 |
+
ENV NEXT_TELEMETRY_DISABLED=1
|
| 55 |
+
RUN npm run build
|
| 56 |
+
|
| 57 |
+
# 锁死端口
|
| 58 |
ENV PORT=7860
|
| 59 |
ENV OMNIROUTE_PORT=7860
|
| 60 |
ENV HOST=0.0.0.0
|
| 61 |
+
ENV NODE_ENV=production
|
| 62 |
EXPOSE 7860
|
| 63 |
|
| 64 |
+
# 6. 用完全没有 webpack-hmr 跨域干扰的生产模式拉起!
|
| 65 |
+
CMD ["npm", "run", "start"]
|