refactor: 优化缓存目录配置和Dockerfile结构
修改缓存目录配置以支持环境变量覆盖,简化Dockerfile并优化镜像构建步骤 移除冗余权限设置,使用更精简的基础镜像
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -1,34 +1,20 @@
|
||||
FROM mcr.microsoft.com/devcontainers/javascript-node:22
|
||||
FROM node:22-slim
|
||||
|
||||
# Install ffmpeg for video thumbnail support
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV CACHE_DIR=/app/.cache
|
||||
WORKDIR /app
|
||||
|
||||
# Use Corepack to activate pnpm from package.json's packageManager field
|
||||
COPY package.json ./
|
||||
RUN corepack enable && pnpm --version && pnpm install --prod
|
||||
|
||||
# Copy application sources
|
||||
# 只复制必要源代码,避免把缓存等无关内容塞进镜像
|
||||
COPY . .
|
||||
|
||||
# Run as non-root for security
|
||||
RUN chown -R node:node /app
|
||||
USER node
|
||||
RUN useradd -m appuser && mkdir -p /app/.cache && chown -R appuser:appuser /app
|
||||
USER appuser
|
||||
|
||||
# 定义.cache目录. 支持用户自定义
|
||||
ENV CACHE_DIR=/app/.cache
|
||||
|
||||
# 确保.cache目录存在
|
||||
RUN mkdir -p $CACHE_DIR && chown -R node:node $CACHE_DIR
|
||||
|
||||
# 确保.cache目录可写
|
||||
RUN chmod -R 777 $CACHE_DIR
|
||||
|
||||
# index listens on 9520
|
||||
EXPOSE 9520
|
||||
|
||||
# Default command
|
||||
CMD ["node", "index.js"]
|
||||
2
index.js
2
index.js
@@ -18,7 +18,7 @@ const EventEmitter = require('events');
|
||||
// Configuration
|
||||
const PORT = 9520;
|
||||
const API_BASE = 'http://183.6.121.121:9558/api';
|
||||
const CACHE_DIR = path.join(__dirname, '.cache');
|
||||
const CACHE_DIR = process.env.CACHE_DIR ? path.resolve(process.env.CACHE_DIR) : path.join(__dirname, '.cache');
|
||||
|
||||
// Ensure cache directory exists
|
||||
if (!fs.existsSync(CACHE_DIR)) {
|
||||
|
||||
2
new.js
2
new.js
@@ -9,7 +9,7 @@ const EventEmitter = require('events');
|
||||
// Configuration
|
||||
const PORT = 9520;
|
||||
const API_BASE = 'http://127.0.0.1:9558/api';
|
||||
const CACHE_DIR = path.join(__dirname, '.cache');
|
||||
const CACHE_DIR = process.env.CACHE_DIR ? path.resolve(process.env.CACHE_DIR) : path.join(__dirname, '.cache');
|
||||
|
||||
// Ensure cache directory exists
|
||||
if (!fs.existsSync(CACHE_DIR)) {
|
||||
|
||||
Reference in New Issue
Block a user