-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (54 loc) · 1.81 KB
/
Dockerfile
File metadata and controls
77 lines (54 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Production Dockerfile - Uses Turso database
# Automatically indexes content to Turso during build
# Build stage
FROM node:20-slim AS builder
# Build arguments for Turso credentials (required for indexing and pre-rendering)
ARG TURSO_DB_URL
ARG TURSO_AUTH_TOKEN
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml* ./
# Install dependencies
RUN pnpm install --no-frozen-lockfile
# Copy source files
COPY . .
# Set environment variables for build
ENV TURSO_DB_URL=$TURSO_DB_URL
ENV TURSO_AUTH_TOKEN=$TURSO_AUTH_TOKEN
# Index content to Turso database (env vars already set via ENV directives)
RUN pnpm exec tsx scripts/init-db.ts && pnpm exec tsx scripts/index-content.ts
# Build application (queries Turso database for static pre-rendering)
RUN pnpm build
# Production stage
FROM node:20-slim AS runtime
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml* ./
# Install production dependencies only
RUN pnpm install --prod --no-frozen-lockfile
# Copy built application from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/local.db ./local.db
# Create non-root user
RUN groupadd -g 1001 nodejs && \
useradd -r -u 1001 -g nodejs astro
# Change ownership
RUN chown -R astro:nodejs /app
# Switch to non-root user
USER astro
# Expose port
EXPOSE 4321
# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=4321
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:4321/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start the server
CMD ["node", "./dist/server/entry.mjs"]