-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.local
More file actions
68 lines (47 loc) · 1.45 KB
/
Dockerfile.local
File metadata and controls
68 lines (47 loc) · 1.45 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
# Dockerfile for local development and testing with embedded SQLite (local.db)
# Build stage
FROM node:20-slim AS builder
# 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 . .
# Initialize database and index content for build
RUN pnpm db:init:local && pnpm index:local
# Build application
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 and local.db
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"]