File size: 1,943 Bytes
cd87182
17b2812
71d6c09
17b2812
 
 
 
 
 
 
 
cd87182
17b2812
 
cd87182
17b2812
cf44c14
 
 
17b2812
 
cf44c14
17b2812
 
cf44c14
17b2812
 
 
cd87182
17b2812
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf44c14
17b2812
 
 
 
 
cf44c14
17b2812
71d6c09
cd87182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17b2812
cf44c14
17b2812
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 使用 Node.js 官方镜像作为基础
FROM node:20-alpine AS builder

WORKDIR /app

# 复制项目文件
COPY . .

# 安装依赖
RUN npm ci --omit=dev || npm install

# 构建项目
RUN npm run build || echo "Build will run at runtime"

# 运行阶段
FROM node:20-alpine

WORKDIR /app

# 安装 nginx 和运行时依赖
RUN apk add --no-cache nginx

# 复制构建产物和源码
COPY --from=builder /app /app

# 创建必要的目录
RUN mkdir -p /app/dist /app/config /app/bookmarks /run/nginx /var/log/nginx

# 配置 nginx
RUN cat > /etc/nginx/nginx.conf << 'EOF'
pid /tmp/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log /tmp/access.log;
    error_log /tmp/error.log;
    
    server {
        listen 7860;
        server_name localhost;
        root /app/dist;
        index index.html;
        
        location / {
            try_files $uri $uri/ /index.html;
        }
        
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
            expires 1y;
            add_header Cache-Control "public, immutable";
        }
    }
}
EOF

# 设置环境变量
ENV PORT=7860
ENV MENAV_PORT=7860
ENV MENAV_ENABLE_SYNC=false
ENV MENAV_IMPORT_BOOKMARKS=false

EXPOSE 7860

# 创建 entrypoint.sh
RUN cat > /entrypoint.sh << 'EOF'
#!/bin/sh
set -e

echo "[$(date)] Starting Menav..."

if [ "$MENAV_IMPORT_BOOKMARKS" = "true" ] && [ -d /app/bookmarks ]; then
    echo "[$(date)] Importing bookmarks..."
    npm run import-bookmarks || echo "Import failed, continuing"
fi

if [ "$MENAV_ENABLE_SYNC" = "true" ]; then
    echo "[$(date)] Syncing data..."
    npm run sync-all || echo "Sync failed, continuing"
fi

echo "[$(date)] Building project..."
npm run build

echo "[$(date)] Starting nginx on port 7860..."
nginx -c /etc/nginx/nginx.conf

tail -f /dev/null
EOF

RUN chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]