Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

2.3 KB
Raw Blame
FROM node:22-alpine AS build

ENV CI=true

RUN npm --fetch-retries=3 install -g corepack && corepack enable

COPY --from=golang:1.25.4-alpine /usr/local/go/ /usr/local/go/

ENV PATH="/usr/local/go/bin:${PATH}"

RUN --mount=type=bind,source=scripts/build,target=/build-scripts sh /build-scripts/install-apk.sh git build-base

WORKDIR /boxlite

# Yarn caching layer
COPY apps/package.json apps/yarn.lock apps/.yarnrc.yml ./
RUN YARN_HTTP_RETRY=3 yarn install --immutable

# Nx config
COPY apps/nx.json ./

# Go dependency layer (cached unless go.mod/go.sum change)
COPY apps/go.work apps/go.work.sum apps/
COPY apps/runner/go.mod apps/runner/go.sum apps/runner/
COPY apps/libs/common-go/go.mod apps/libs/common-go/go.sum apps/libs/common-go/
COPY apps/libs/api-client-go/go.mod apps/libs/api-client-go/go.sum apps/libs/api-client-go/
COPY sdks/go/go.mod sdks/go/

# Rewrite go.work to include only needed modules
RUN head -1 apps/go.work > apps/go.work.tmp && printf '\nuse (\n\t./runner\n\t./libs/common-go\n\t./libs/api-client-go\n\t../sdks/go\n)\n' >> apps/go.work.tmp && mv apps/go.work.tmp apps/go.work

ENV NX_DAEMON=false

RUN --mount=type=bind,source=scripts/build,target=/build-scripts \
    for module in apps/runner apps/libs/common-go apps/libs/api-client-go; do \
      sh /build-scripts/retry-fetch.sh go -C "$module" mod download || exit $?; \
    done

# BoxLite static library and headers
COPY sdks/go/ sdks/go/
COPY sdks/c/include/ sdks/c/include/

# Prebuilt libboxlite.a — built by CI or `make dist:runner`
ARG LIBBOXLITE_PATH=target/release/libboxlite.a
COPY ${LIBBOXLITE_PATH} sdks/go/libboxlite.a

# Go source
COPY apps/runner/ apps/runner/
COPY apps/libs/common-go/ apps/libs/common-go/
COPY apps/libs/api-client-go/ apps/libs/api-client-go/

ARG VERSION=0.0.1
RUN --mount=type=cache,target=/root/.cache/go-build \
  CGO_ENABLED=1 VERSION=$VERSION yarn nx build runner --configuration=production --nxBail=true

# Runtime — lightweight Linux with KVM support
FROM alpine:3.22 AS runner

RUN --mount=type=bind,source=scripts/build,target=/build-scripts sh /build-scripts/install-apk.sh curl

WORKDIR /usr/local/bin

COPY --from=build /boxlite/dist/apps/runner boxlite-runner

RUN chmod +x boxlite-runner

HEALTHCHECK CMD [ "curl", "-f", "http://localhost:3003/" ]

ENTRYPOINT ["boxlite-runner"]