sandbox-agent/docker/release/macos-aarch64.Dockerfile
Nathan Flurry 553f249836
fix: add postinstall chmod for npm binary permissions (#43)
* fix: add postinstall chmod for npm binary permissions

* fix: report npm package version instead of compiled binary version

The --version flag now reports the version from package.json instead of the
version compiled into the Rust binary. This ensures the version matches what
was installed via npm, even when binaries are reused from previous releases.

* fix: bake version into binary at build time

Instead of hacking around the version in the Node.js wrapper script,
properly pass the version at build time via SANDBOX_AGENT_VERSION env var.

Changes:
- build.rs: Generate version.rs with VERSION constant from env var
- main.rs: Use generated version constant for clap --version
- Dockerfiles: Accept SANDBOX_AGENT_VERSION as build arg
- build.sh: Pass version as second argument to Docker builds
- release.yaml: Pass version to build script during CI
- Remove version hack from sdks/cli/bin/sandbox-agent wrapper

The version is now baked into the binary during the release build,
ensuring --version reports the correct npm package version.
2026-02-02 00:45:31 -08:00

103 lines
3.5 KiB
Docker

# syntax=docker/dockerfile:1.10.0
# Build inspector frontend
FROM node:22-alpine AS inspector-build
WORKDIR /app
RUN npm install -g pnpm
# Copy package files for workspaces
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY frontend/packages/inspector/package.json ./frontend/packages/inspector/
COPY sdks/typescript/package.json ./sdks/typescript/
# Install dependencies
RUN pnpm install --filter @sandbox-agent/inspector...
# Copy SDK source (with pre-generated types from docs/openapi.json)
COPY docs/openapi.json ./docs/
COPY sdks/typescript ./sdks/typescript
# Build SDK (just tsup, skip generate since types are pre-generated)
RUN cd sdks/typescript && SKIP_OPENAPI_GEN=1 pnpm exec tsup
# Copy inspector source and build
COPY frontend/packages/inspector ./frontend/packages/inspector
RUN cd frontend/packages/inspector && pnpm exec vite build
FROM rust:1.88.0 AS base
# Install dependencies
RUN apt-get update && apt-get install -y \
clang \
cmake \
patch \
libxml2-dev \
wget \
xz-utils \
curl \
git && \
rm -rf /var/lib/apt/lists/*
# Install osxcross
RUN git config --global --add safe.directory '*' && \
git clone https://github.com/tpoechtrager/osxcross /root/osxcross && \
cd /root/osxcross && \
wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz && \
mv MacOSX11.3.sdk.tar.xz tarballs/ && \
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
# Add osxcross to PATH
ENV PATH="/root/osxcross/target/bin:$PATH"
# Tell Clang/bindgen to use the macOS SDK, and nudge Clang to prefer osxcross binutils.
ENV OSXCROSS_SDK=MacOSX11.3.sdk \
SDKROOT=/root/osxcross/target/SDK/MacOSX11.3.sdk \
BINDGEN_EXTRA_CLANG_ARGS_aarch64_apple_darwin="--sysroot=/root/osxcross/target/SDK/MacOSX11.3.sdk -isystem /root/osxcross/target/SDK/MacOSX11.3.sdk/usr/include" \
CFLAGS_aarch64_apple_darwin="-B/root/osxcross/target/bin" \
CXXFLAGS_aarch64_apple_darwin="-B/root/osxcross/target/bin" \
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \
CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \
CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ \
AR_aarch64_apple_darwin=aarch64-apple-darwin20.4-ar \
RANLIB_aarch64_apple_darwin=aarch64-apple-darwin20.4-ranlib \
MACOSX_DEPLOYMENT_TARGET=10.14 \
CARGO_INCREMENTAL=0 \
CARGO_NET_GIT_FETCH_WITH_CLI=true
# Set working directory
WORKDIR /build
# Build for ARM64 macOS
FROM base AS aarch64-builder
# Accept version as build arg
ARG SANDBOX_AGENT_VERSION
ENV SANDBOX_AGENT_VERSION=${SANDBOX_AGENT_VERSION}
# Install macOS ARM64 target
RUN rustup target add aarch64-apple-darwin
# Configure Cargo for cross-compilation (ARM64)
RUN mkdir -p /root/.cargo && \
echo '\
[target.aarch64-apple-darwin]\n\
linker = "aarch64-apple-darwin20.4-clang"\n\
ar = "aarch64-apple-darwin20.4-ar"\n\
' > /root/.cargo/config.toml
# Copy the source code
COPY . .
# Copy pre-built inspector frontend
COPY --from=inspector-build /app/frontend/packages/inspector/dist ./frontend/packages/inspector/dist
# Build for ARM64 macOS
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/build/target \
cargo build -p sandbox-agent --release --target aarch64-apple-darwin && \
mkdir -p /artifacts && \
cp target/aarch64-apple-darwin/release/sandbox-agent /artifacts/sandbox-agent-aarch64-apple-darwin
# Default command to show help
CMD ["ls", "-la", "/artifacts"]