# syntax=docker/dockerfile:1.7 FROM oven/bun:1.3.5-alpine AS deps WORKDIR /app COPY package.json bun.lock ./ RUN --mount=type=cache,target=/root/.bun/install/cache \ bun install --frozen-lockfile FROM rust:1.93-alpine AS rust-builder WORKDIR /app COPY rust ./rust RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/rust/target \ cargo build --manifest-path rust/Cargo.toml --release --bin fiscal-xbrl \ && mkdir -p /app/bin \ && cp /app/rust/target/release/fiscal-xbrl /app/bin/fiscal-xbrl FROM deps AS builder ARG NEXT_PUBLIC_API_URL= ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} ENV DATABASE_URL=file:/tmp/fiscal-build.sqlite ENV BETTER_AUTH_SECRET=fiscal-docker-build-secret-fiscal-docker-build-secret ENV BETTER_AUTH_BASE_URL=http://127.0.0.1:3000 ENV BETTER_AUTH_TRUSTED_ORIGINS=http://127.0.0.1:3000,http://localhost:3000 ENV NEXT_TELEMETRY_DISABLED=1 ENV SKIP_NEXT_TYPECHECK_ON_BUILD=true ENV NEXT_BUILD_CPUS=1 ENV WORKFLOW_TARGET_WORLD=local ENV WORKFLOW_LOCAL_DATA_DIR=/tmp/.workflow-data ENV RUN_WORKFLOW_SETUP_ON_START=false ENV RUN_DB_MIGRATIONS_ON_START=false # Force the Rust sidecar build to complete before the Next.js build starts. # BuildKit otherwise runs these independent stages in parallel and can OOM locally. COPY --from=rust-builder /app/bin/fiscal-xbrl /tmp/fiscal-xbrl COPY next.config.js tsconfig.json postcss.config.js tailwind.config.js drizzle.config.ts instrumentation.ts next-env.d.ts ./ COPY app ./app COPY components ./components COPY contracts ./contracts COPY drizzle ./drizzle COPY hooks ./hooks COPY lib ./lib COPY rust ./rust COPY scripts ./scripts RUN --mount=type=cache,target=/app/.next/cache \ mkdir -p data public /tmp/.workflow-data /app/.output \ && rm -f /tmp/fiscal-xbrl \ && bun run generate \ && bun --smol --bun next build --turbopack \ && bun build --target=bun --outfile /app/.output/bootstrap-production.js scripts/bootstrap-production.ts FROM oven/bun:1.3.5-alpine AS runner WORKDIR /app ENV NODE_ENV=production ENV HOSTNAME=0.0.0.0 ARG NEXT_PUBLIC_API_URL= ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} ENV DATABASE_URL=file:/app/data/fiscal.sqlite ENV NEXT_TELEMETRY_DISABLED=1 ENV WORKFLOW_TARGET_WORLD=@workflow/world-postgres ENV WORKFLOW_LOCAL_DATA_DIR=/app/.workflow-data ENV RUN_WORKFLOW_SETUP_ON_START=true ENV RUN_DB_MIGRATIONS_ON_START=true COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/.output/bootstrap-production.js ./bootstrap-production.js COPY --from=builder /app/drizzle ./drizzle COPY --from=builder /app/rust/taxonomy ./rust/taxonomy COPY --from=deps /app/node_modules/@workflow/world-postgres/src/drizzle/migrations ./workflow-migrations COPY --from=rust-builder /app/bin/fiscal-xbrl ./bin/fiscal-xbrl RUN mkdir -p /app/data /app/.workflow-data /app/bin /app/.cache/xbrl && chmod +x /app/bin/fiscal-xbrl EXPOSE 3000 ENV PORT=3000 ENV FISCAL_XBRL_BIN=/app/bin/fiscal-xbrl ENV FISCAL_XBRL_CACHE_DIR=/app/.cache/xbrl ENV XBRL_ENGINE_TIMEOUT_MS=45000 ENV WORKFLOW_MIGRATIONS_DIR=/app/workflow-migrations CMD ["sh", "-c", "if [ ! -x \"${FISCAL_XBRL_BIN:-/app/bin/fiscal-xbrl}\" ]; then echo \"Missing Rust XBRL sidecar at ${FISCAL_XBRL_BIN:-/app/bin/fiscal-xbrl}\" >&2; exit 1; fi; bun /app/bootstrap-production.js && exec bun /app/server.js"]