-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
125 lines (95 loc) · 3.29 KB
/
Dockerfile
File metadata and controls
125 lines (95 loc) · 3.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Code Buddy - Official Docker Image
# Multi-stage build for optimized production image
# Supports AMD64 and ARM64 architectures
# ============================================================================
# Stage 1: Build
# ============================================================================
FROM node:20-bookworm AS builder
WORKDIR /app
# Install build dependencies for native modules
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Copy package files
COPY package*.json ./
# Install dependencies (including devDependencies for build)
RUN npm ci
# Copy source code
COPY . .
# Build TypeScript
RUN npm run build
# Prune dev dependencies
RUN npm prune --production
# ============================================================================
# Stage 2: Production
# ============================================================================
FROM node:20-bookworm-slim AS production
# Labels for container registry
LABEL org.opencontainers.image.title="Code Buddy"
LABEL org.opencontainers.image.description="AI-powered terminal assistant using Grok API (xAI)"
LABEL org.opencontainers.image.version="2.0.0"
LABEL org.opencontainers.image.vendor="phuetz"
LABEL org.opencontainers.image.source="https://github.com/phuetz/code-buddy"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.documentation="https://github.com/phuetz/code-buddy#readme"
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ripgrep \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN useradd -m -s /bin/bash -u 1001 codebuddy
# Copy built application from builder stage
COPY --from=builder --chown=codebuddy:codebuddy /app/dist ./dist
COPY --from=builder --chown=codebuddy:codebuddy /app/node_modules ./node_modules
COPY --from=builder --chown=codebuddy:codebuddy /app/package.json ./
# Create directories for config and data
RUN mkdir -p /home/codebuddy/.codebuddy /home/codebuddy/data \
&& chown -R codebuddy:codebuddy /home/codebuddy
# Set environment
ENV NODE_ENV=production
ENV HOME=/home/codebuddy
ENV CODEBUDDY_HOME=/home/codebuddy/.codebuddy
# Switch to non-root user
USER codebuddy
# Set working directory for projects
WORKDIR /workspace
# Health check for server mode
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/api/health 2>/dev/null || exit 0
# Expose server port (for server mode)
EXPOSE 3000
# Entry point
ENTRYPOINT ["node", "/app/dist/index.js"]
# Default command (show help)
CMD ["--help"]
# ============================================================================
# Stage 3: Development
# ============================================================================
FROM node:20-bookworm AS development
WORKDIR /app
# Install dev dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ripgrep \
python3 \
make \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy package files and install
COPY package*.json ./
RUN npm ci
# Copy source
COPY . .
# Environment
ENV NODE_ENV=development
# Expose for dev server
EXPOSE 3000 5173
# Dev entry point
CMD ["npm", "run", "dev:node"]