-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
171 lines (122 loc) · 3.57 KB
/
Dockerfile
File metadata and controls
171 lines (122 loc) · 3.57 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Multi-stage build for development environment
FROM oven/bun:1.1.2-alpine AS base
# Install system dependencies
RUN apk add --no-cache \
git \
python3 \
make \
g++ \
curl \
docker
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json bun.lock* turbo.json biome.jsonc ./
# Install dependencies
RUN bun install --frozen-lockfile
# Copy source code
COPY . .
# Development stage
FROM base AS development
# Expose ports for all services
EXPOSE 3000 8000 6379 1883 9001 6333
# Default command for development
CMD ["bun", "run", "dev"]
# Build stage
FROM base AS build
# Build all applications
RUN turbo run build
# Production stage for backend
FROM oven/bun:1.1.2-alpine AS production-backend
# Install system dependencies
RUN apk add --no-cache \
curl \
dumb-init
# Set working directory
WORKDIR /app
# Copy built artifacts from build stage
COPY --from=build /apps/backend/dist ./backend/dist
COPY --from=build /apps/backend/package.json ./backend/
# Copy root dependencies needed for runtime
COPY package.json ./
# Install production dependencies
RUN bun install --production --frozen-lockfile
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S backend -u 1001
# Change ownership
RUN chown -R backend:nodejs /app
USER backend
# Expose port
EXPOSE 8000
# Start the backend
CMD ["dumb-init", "bun", "run", "start"]
# Production stage for web app
FROM node:20-alpine AS production-webapp
# Install system dependencies
RUN apk add --no-cache \
dumb-init
# Set working directory
WORKDIR /app
# Copy built artifacts from build stage
COPY --from=build /apps/tablet/dist ./webapp/dist
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S webapp -u 1001
# Change ownership
RUN chown -R webapp:nodejs /app
USER webapp
# Expose port
EXPOSE 3000
# Serve the web app using a simple HTTP server
CMD ["dumb-init", "python3", "-m", "http.server", "3000", "-d", "/app/webapp/dist"]
# ESP32 build stage
FROM alpine/esp32-build-base:latest AS esp32-builder
# Set working directory
WORKDIR /app
# Copy ESP32 firmware
COPY apps/esp32-firmware/ ./esp32-firmware/
# Build the firmware
RUN cd esp32-firmware && \
arduino-cli compile --fqbn esp32:esp32:esp32 ./
# Production ESP32 firmware
FROM alpine:latest AS production-esp32
# Copy built firmware
COPY --from=esp32-builder /app/esp32-firmware/*.bin ./firmware/
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD echo "ESP32 firmware container healthy"
# Final development image (combines all services)
FROM base AS dev-environment
# Install additional development tools
RUN bun add -g @biomejs/biome eslint prettier turbo
# Copy development scripts
RUN mkdir -p /scripts
COPY deployment/scripts/ /scripts/
# Make scripts executable
RUN chmod +x /scripts/*.sh
# Expose all ports
EXPOSE 3000 8000 6379 1883 9001 6333
# Default command
CMD ["/scripts/start-dev.sh"]
# Production stage with all services
FROM production-backend AS production
# Copy webapp
COPY --from=production-webapp /app/webapp/dist ./webapp/dist
# Copy ESP32 firmware
COPY --from=production-esp32 /app/firmware ./firmware
# Copy deployment scripts
COPY deployment/scripts/ /scripts/
RUN chmod +x /scripts/*.sh
# Create non-root user for production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S orbit -u 1001
RUN chown -R orbit:nodejs /app
USER orbit
# Expose ports
EXPOSE 3000 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Start all services
CMD ["/scripts/start-prod.sh"]