-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (39 loc) · 1.21 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (39 loc) · 1.21 KB
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
# ===== Build Stage =====
FROM node:22-alpine AS builder
WORKDIR /app
# 安装 git
RUN apk add --no-cache git
# Clone Astro basics 示例
RUN git clone --depth 1 https://github.com/withastro/astro.git /tmp/astro && \
cp -r /tmp/astro/examples/basics/. . && \
rm -rf /tmp/astro
# 安装依赖
RUN npm install
# 安装 Node adapter 和 SQLite ORM
RUN npx astro add node --yes
RUN npm install drizzle-orm better-sqlite3
# 复制自定义文件
COPY astro.config.mjs ./astro.config.mjs
COPY src/ ./src/
# 构建 Astro 项目(全 SSR)
RUN npm run build
# ===== Runtime Stage =====
FROM node:22-alpine AS runtime
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
# 创建数据目录
RUN mkdir -p /app/data
# 非 root 用户运行(安全)
RUN addgroup -g 1001 -S nodejs && \
adduser -S astro -u 1001 -G nodejs && \
chown -R astro:nodejs /app
USER astro
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:4321/ || exit 1
CMD ["node", "./dist/server/entry.mjs"]