Skip to content

A desktop coding agent with free access to frontier models.

TypeScript
3.6 KB
Raw Blame
# The builder runs on the BUILD host's native platform and cross-compiles for
# the target: bun compiles omnirush-server via --target and the web build is
# arch-independent. This avoids emulating the whole toolchain under QEMU
# (node's libuv crashes under qemu-x86_64: uv__io_poll EEXIST assert).
FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS omnirush-builder

WORKDIR /src

RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates curl git unzip \
    python3 make g++ \
  && npm install -g [email protected] \
  && corepack enable \
  && rm -rf /var/lib/apt/lists/*

COPY . .

# python3/make/g++ above: better-sqlite3 v13 has no install script, but pnpm's
# implicit node-gyp build for packages with a binding.gyp still compiles it
# from source here, which needs a toolchain (v12 downloaded prebuilds instead).
RUN pnpm install --frozen-lockfile --filter omnirush-server... --filter @omnirush/app...

ARG TARGETARCH

RUN set -eux; \
  arch="${TARGETARCH:-$(dpkg --print-architecture)}"; \
  case "$arch" in \
    amd64) target="bun-linux-x64" ;; \
    arm64) target="bun-linux-arm64" ;; \
    *) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
  esac; \
  pnpm --filter omnirush-server build; \
  pnpm --filter omnirush-server exec bun ./script/build.ts --outdir dist/bin --target "$target"; \
  install -m 0755 "apps/server/dist/bin/omnirush-server-${target}" /tmp/omnirush-server; \
  pnpm --filter @omnirush/app build:web

FROM node:22-bookworm-slim

ARG OMNIRUSH_SERVER_VERSION=0.18.1
ARG OPENCODE_VERSION
ARG OPENCODE_DOWNLOAD_URL=

RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates curl tar unzip \
  && rm -rf /var/lib/apt/lists/*

COPY --from=omnirush-builder /tmp/omnirush-server /usr/local/bin/omnirush-server
COPY --from=omnirush-builder /src/apps/app/dist /opt/omnirush/web
COPY --from=omnirush-builder /src/apps/server/dist/opencode-plugins /opt/omnirush/opencode-plugins

RUN set -eux; \
  test -n "$OPENCODE_VERSION"; \
  arch="$(dpkg --print-architecture)"; \
  case "$arch" in \
    amd64) asset="opencode-linux-x64-baseline.tar.gz" ;; \
    arm64) asset="opencode-linux-arm64.tar.gz" ;; \
    *) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
  esac; \
  url="$OPENCODE_DOWNLOAD_URL"; \
  if [ -z "$url" ]; then \
    url="https://github.com/anomalyco/opencode/releases/download/v${OPENCODE_VERSION}/${asset}"; \
  fi; \
  tmpdir="$(mktemp -d)"; \
  curl -fsSL "$url" -o "$tmpdir/$asset"; \
  tar -xzf "$tmpdir/$asset" -C "$tmpdir"; \
  binary="$(find "$tmpdir" -type f -name opencode | head -n 1)"; \
  test -n "$binary"; \
  install -m 0755 "$binary" /usr/local/bin/opencode; \
  rm -rf "$tmpdir"

# Runtime asserts run the target-arch binaries. Keep them on in CI (native
# amd64 runners); disable only for local cross-builds, where bun binaries die
# with "Illegal instruction" under qemu-x86_64 even though they run fine on
# real hardware.
ARG RUNTIME_ASSERTS=1
RUN if [ "$RUNTIME_ASSERTS" = "1" ]; then \
    test -f /opt/omnirush/opencode-plugins/omnirush-extensions-preview.js \
    && test -f /opt/omnirush/opencode-plugins/omnirush-capabilities-knowledge.js \
    && test -f /opt/omnirush/opencode-plugins/omnirush-office-attachments.js \
    && test -f /opt/omnirush/opencode-plugins/omnirush-anthropic-adaptive-thinking.js \
    && test -f /opt/omnirush/opencode-plugins/omnirush-anthropic-tool-schema.js \
    && test "$(omnirush-server --version)" = "$OMNIRUSH_SERVER_VERSION" \
    && opencode --version; \
  else \
    echo "RUNTIME_ASSERTS disabled (cross-build); binaries must be verified on target hardware"; \
  fi

CMD ["sleep", "infinity"]