-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
154 lines (119 loc) · 5.29 KB
/
Copy pathDockerfile
File metadata and controls
154 lines (119 loc) · 5.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
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
# Simple multi-stage Dockerfile for backend and worker
# ============================================================================
# BASE STAGE
# ============================================================================
FROM oven/bun:1.3.10 AS base
# Install system deps
RUN apt-get update && \
apt-get install -y ca-certificates curl gnupg lsb-release procps python3 make g++ && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" > /etc/apt/sources.list.d/docker.list && \
curl -fsSL https://deb.nodesource.com/setup_current.x | bash - && \
apt-get update && \
apt-get install -y nodejs docker-ce-cli && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Create user
RUN groupadd -g 1001 sentris && useradd -u 1001 -g sentris -m sentris
# Copy all files
COPY --chown=sentris:sentris bun.lock package.json bunfig.toml ./
COPY --chown=sentris:sentris packages/ packages/
COPY --chown=sentris:sentris backend/ backend/
COPY --chown=sentris:sentris frontend/ frontend/
COPY --chown=sentris:sentris worker/ worker/
COPY --chown=sentris:sentris scripts/lib/local-script-runtime.ts scripts/lib/local-script-runtime.ts
# Install ALL dependencies (no filtering)
RUN bun install --frozen-lockfile
# ============================================================================
# BACKEND SERVICE
# ============================================================================
FROM base AS backend
# Switch to user
USER sentris
# Set working directory for backend
WORKDIR /app/backend
# Bun's bundler emits the legacy decorator metadata required by NestJS.
RUN bun run build
# Expose port
EXPOSE 3211
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:3211/api/v1/health || exit 1
# Run migrations first, then start the verified bundle.
CMD ["bun", "run", "start:prod"]
# ============================================================================
# WORKER SERVICE
# ============================================================================
FROM base AS worker
# Switch to user
USER sentris
# Set working directory for worker
WORKDIR /app/worker
# Worker liveness/readiness endpoint
EXPOSE 9100 9101 9301
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD curl -sf http://localhost:9100/health/ready || exit 1
# Run worker with Node + tsx (not bun, due to SWC binding issues)
CMD ["node", "--import", "tsx/esm", "src/temporal/workers/dev.worker.ts"]
# ============================================================================
# FRONTEND SERVICE
# ============================================================================
FROM base AS frontend
# Build provenance is image-specific. Operator configuration is injected at startup.
ARG VITE_GIT_SHA=unknown
ENV VITE_GIT_SHA=${VITE_GIT_SHA}
# Set working directory for frontend
USER sentris
WORKDIR /app/frontend
# Build TypeScript declarations for workspace packages first (project references require this)
RUN cd /app && bunx tsc --build packages/shared packages/backend-client
# Build one profile-independent production bundle.
RUN bun run build
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:8080 || exit 1
# Generate the whitelisted public config from container env, then serve the same bundle.
CMD ["sh", "-c", "bun src/scripts/generate-runtime-config.ts && exec bun run preview --host 0.0.0.0 --port 8080"]
# ============================================================================
# FRONTEND DEBUG SERVICE (non-minified for debugging)
# ============================================================================
FROM base AS frontend-debug
# Frontend build-time configuration
ARG VITE_AUTH_PROVIDER=local
ARG VITE_CLERK_PUBLISHABLE_KEY=""
ARG VITE_API_URL=http://localhost:3211
ARG VITE_BACKEND_URL=http://localhost:3211
ARG VITE_DEFAULT_ORG_ID=local-dev
ARG VITE_GIT_SHA=unknown
ARG VITE_PUBLIC_POSTHOG_KEY=""
ARG VITE_PUBLIC_POSTHOG_HOST=""
ARG VITE_OPENSEARCH_DASHBOARDS_URL=""
ENV VITE_AUTH_PROVIDER=${VITE_AUTH_PROVIDER}
ENV VITE_CLERK_PUBLISHABLE_KEY=${VITE_CLERK_PUBLISHABLE_KEY}
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_BACKEND_URL=${VITE_BACKEND_URL}
ENV VITE_DEFAULT_ORG_ID=${VITE_DEFAULT_ORG_ID}
ENV VITE_GIT_SHA=${VITE_GIT_SHA}
ENV VITE_PUBLIC_POSTHOG_KEY=${VITE_PUBLIC_POSTHOG_KEY}
ENV VITE_PUBLIC_POSTHOG_HOST=${VITE_PUBLIC_POSTHOG_HOST}
ENV VITE_OPENSEARCH_DASHBOARDS_URL=${VITE_OPENSEARCH_DASHBOARDS_URL}
# Set working directory for frontend
USER sentris
WORKDIR /app/frontend
# Ensure sentris user can write to node_modules for Vite cache
USER root
RUN chown -R sentris:sentris /app/frontend/node_modules
USER sentris
# Expose port
EXPOSE 5173
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:5173 || exit 1
# Run development server (non-minified) for debugging
CMD ["bun", "run", "dev", "--host", "0.0.0.0", "--port", "5173"]