Skip to content

Commit e89da34

Browse files
committed
build(docker): optimize production build with bun runtime
Use pre-built database package dist files and existing bun user from oven/bun image. Remove npm dependency, fix migration path to use compiled JavaScript, and ensure drizzle artifacts are included in production build.
1 parent 81e262d commit e89da34

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ modules.config.local.ts
4343

4444
# Local dev files
4545
logs/
46-
drizzle/
4746
.npm/
4847
turbo/
4948

Dockerfile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ WORKDIR /app
5151
# and wget for healthcheck
5252
RUN apt-get update && apt-get install -y --no-install-recommends \
5353
nodejs \
54-
npm \
5554
wget \
5655
&& rm -rf /var/lib/apt/lists/*
5756

5857
# Copy built application from builder
5958
COPY --from=builder /app/build ./build
6059
COPY --from=builder /app/node_modules ./node_modules
6160
COPY --from=builder /app/package.json ./
62-
COPY --from=builder /app/packages/database ./packages/database
63-
COPY --from=builder /app/drizzle ./drizzle
61+
COPY --from=builder /app/packages/database/drizzle ./packages/database/drizzle
62+
COPY --from=builder /app/packages/database/dist ./packages/database/dist
6463
COPY --from=builder /app/modules ./modules
6564
COPY --from=builder /app/scripts/entrypoint.sh ./scripts/entrypoint.sh
6665

@@ -79,10 +78,9 @@ ENV MOLOS_MODULE_DATA_DIR=/data/modules
7978
# Expose port SvelteKit runs on
8079
EXPOSE 4173
8180

82-
# Security hardening - run as non-root user
83-
RUN useradd -m -u 1000 appuser && \
84-
chown -R appuser:appuser /app /data
85-
USER appuser
81+
# Security hardening - run as non-root user (bun user already exists in oven/bun image)
82+
RUN chown -R bun:bun /app /data
83+
USER bun
8684

8785
# Use the entrypoint script to handle migrations and start the server
8886
ENTRYPOINT ["/app/scripts/entrypoint.sh"]

scripts/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fi
5656

5757
# Run database migrations
5858
log "Running database migrations..."
59-
if npx tsx packages/database/src/migrate-unified.ts; then
59+
if bun /app/packages/database/dist/migrate-unified.js; then
6060
log "Database migrations completed successfully."
6161
else
6262
error "Database migrations failed. Cannot proceed without a properly initialized database."

scripts/link-modules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ async function registerModuleIfNeeded(moduleId: string, modulePath: string): Pro
252252
*/
253253
async function recordLinkResult(moduleId: string, result: ModuleLinkResult): Promise<void> {
254254
try {
255+
await loadDatabase();
255256
if (result.skipped) {
256257
// Record validation failures in the database for tracking
257258
if (result.validation && !result.validation.canProceed) {

0 commit comments

Comments
 (0)