Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(run_local): running local performance optimizations (#2829)

teof2c0166d67b1
diff --git a/docker-compose.yml b/docker-compose.yml
index 67466e9d02..e1e3307c1a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,17 +7,30 @@ x-common-env: &common-env
env_file:
- .env
+x-rust-services-image: &rust-services-image
+ image: macro-local-rust-services:dev
+ build:
+ context: ./rust/cloud-storage
+ dockerfile: Dockerfile.dev
+ target: services_bundle
+
services:
+ rust_services_image:
+ profiles:
+ - build-helper
+ build:
+ context: ./rust/cloud-storage
+ dockerfile: Dockerfile.dev
+ target: services_bundle
+ image: macro-local-rust-services:dev
+
# ============================================================================
# authentication-service (Port 8080)
# Primary auth service - depends on FusionAuth, Redis, MacroDB
# ============================================================================
authentication-service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: authentication_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/authentication_service"]
ports:
- "8080:8080"
depends_on:
@@ -40,11 +53,8 @@ services:
# WebSocket gateway - Redis only
# ============================================================================
connection_gateway:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: connection_gateway_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/connection_gateway_service"]
ports:
- "8082:8080"
depends_on:
@@ -64,11 +74,8 @@ services:
# Contact management - ContactsDB
# ============================================================================
contacts_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: contacts_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/contacts_service"]
ports:
- "8083:8080"
networks:
@@ -86,11 +93,8 @@ services:
# Document analysis and processing
# ============================================================================
document_cognition_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: document_cognition_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/document_cognition_service"]
ports:
- "8085:8080"
depends_on:
@@ -112,11 +116,8 @@ services:
# Main document storage API
# ============================================================================
document_storage_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: document_storage_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/document_storage_service"]
ports:
- "8086:8080"
depends_on:
@@ -138,11 +139,8 @@ services:
# Email processing and management
# ============================================================================
email_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: email_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/email_service"]
ports:
- "8087:8080"
depends_on:
@@ -166,11 +164,8 @@ services:
# User notifications - NotificationDB
# ============================================================================
notification_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: notification_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/notification_service"]
ports:
- "8089:8080"
depends_on:
@@ -197,6 +192,9 @@ services:
profiles:
- processors
<<: *common-env
+ # Pinned because search_processing_service/pdfium-lib/linux/libpdfium.so is amd64-only;
+ # on Apple Silicon this forces QEMU emulation for build and runtime.
+ platform: linux/amd64
build:
context: ./rust/cloud-storage
dockerfile: Dockerfile.search_processing_service.dev
@@ -219,11 +217,8 @@ services:
# Static file serving - DynamoDB
# ============================================================================
static_file_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: static_file_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/static_file_service"]
ports:
- "8094:8080"
networks:
@@ -257,11 +252,8 @@ services:
# URL unfurling - no dependencies
# ============================================================================
unfurl_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: unfurl_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/unfurl_service"]
ports:
- "8095:8080"
networks:
@@ -278,11 +270,8 @@ services:
# Proxies external images to avoid CORS issues and IP leakage
# ============================================================================
image_proxy_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: image_proxy_service
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/image_proxy_service"]
ports:
- "8097:8080"
networks:
diff --git a/justfile b/justfile
index 877fee309a..616b6eb878 100644
--- a/justfile
+++ b/justfile
@@ -1,3 +1,5 @@
+set positional-arguments
+
# Creates global networks that are shared across docker-compose files
create_networks:
docker network create databases 2>/dev/null || true -- db network
@@ -51,9 +53,54 @@ docker_up *ARGS:
# Requires .env file (from `just get_environment`) and FusionAuth setup (from `just setup`).
# Automatically patches .env with local FusionAuth values before starting services.
run_local *ARGS:
+ #!/usr/bin/env bash
+ set -euo pipefail
+
just create_networks
just patch_local_fusionauth_env
- just docker_up {{ ARGS }}
+
+ do_build=false
+ build_processors=false
+ filtered_args=()
+ expecting_profile_name=false
+ for arg in "$@"; do
+ if [ "$expecting_profile_name" = true ]; then
+ if [ "$arg" = "processors" ]; then
+ build_processors=true
+ fi
+ expecting_profile_name=false
+ filtered_args+=("$arg")
+ continue
+ fi
+
+ if [ "$arg" = "--build" ]; then
+ do_build=true
+ elif [ "$arg" = "--profile" ]; then
+ expecting_profile_name=true
+ filtered_args+=("$arg")
+ elif [ "$arg" = "search_processing_service" ]; then
+ build_processors=true
+ filtered_args+=("$arg")
+ else
+ filtered_args+=("$arg")
+ fi
+ done
+
+ docker compose build rust_services_image
+
+ if [ "$do_build" = true ]; then
+ docker compose build websocket_service sync_service lexical_service
+ if [ "$build_processors" = true ]; then
+ docker compose build search_processing_service
+ fi
+ fi
+
+ echo "startup docker compose"
+ if [ "${#filtered_args[@]}" -gt 0 ]; then
+ docker compose up "${filtered_args[@]}"
+ else
+ docker compose up
+ fi
# Patches .env with local FusionAuth values if the Pulumi stack exists.
# Requires FusionAuth to be running — starts it temporarily if needed.
diff --git a/rust/cloud-storage/Dockerfile.dev b/rust/cloud-storage/Dockerfile.dev
index f33afffbc8..661355219c 100644
--- a/rust/cloud-storage/Dockerfile.dev
+++ b/rust/cloud-storage/Dockerfile.dev
@@ -1,16 +1,20 @@
# syntax=docker/dockerfile:1
FROM rust:latest AS chef
ENV SQLX_OFFLINE=true
+ENV CARGO_PROFILE_DEV_DEBUG=0
WORKDIR /app
FROM chef AS builder
+ARG CARGO_BUILD_JOBS=0
COPY . .
# Build ALL standard service binaries at once (with BuildKit cache mounts for incremental builds)
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=shared \
--mount=type=cache,target=/usr/local/cargo/git/db,sharing=shared \
--mount=type=cache,target=/app/target,id=rust-target-dev-debug,sharing=locked \
- cargo build -j 2 \
+ jobs="${CARGO_BUILD_JOBS:-0}" \
+ && if [ -z "${jobs}" ] || [ "${jobs}" = "0" ]; then jobs="$(nproc)"; fi \
+ && cargo build -j "${jobs}" \
--bin authentication_service \
--bin connection_gateway_service \
--bin contacts_service \
@@ -42,53 +46,38 @@ WORKDIR /app
ENV PORT=8080
EXPOSE 8080
+FROM base AS services_bundle
+COPY --from=builder /app/out/ /app/out/
+RUN chmod +x /app/out/*
+ENTRYPOINT ["dumb-init", "--"]
+
# Individual service targets
-FROM base AS authentication_service
-COPY --from=builder /app/out/authentication_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS authentication_service
+CMD ["/app/out/authentication_service"]
-FROM base AS connection_gateway_service
-COPY --from=builder /app/out/connection_gateway_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS connection_gateway_service
+CMD ["/app/out/connection_gateway_service"]
-FROM base AS contacts_service
-COPY --from=builder /app/out/contacts_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS contacts_service
+CMD ["/app/out/contacts_service"]
-FROM base AS document_cognition_service
-COPY --from=builder /app/out/document_cognition_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS document_cognition_service
+CMD ["/app/out/document_cognition_service"]
-FROM base AS document_storage_service
-COPY --from=builder /app/out/document_storage_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS document_storage_service
+CMD ["/app/out/document_storage_service"]
-FROM base AS email_service
-COPY --from=builder /app/out/email_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS email_service
+CMD ["/app/out/email_service"]
-FROM base AS notification_service
-COPY --from=builder /app/out/notification_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS notification_service
+CMD ["/app/out/notification_service"]
-FROM base AS static_file_service
-COPY --from=builder /app/out/static_file_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS static_file_service
+CMD ["/app/out/static_file_service"]
-FROM base AS unfurl_service
-COPY --from=builder /app/out/unfurl_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS unfurl_service
+CMD ["/app/out/unfurl_service"]
-FROM base AS image_proxy_service
-COPY --from=builder /app/out/image_proxy_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
+FROM services_bundle AS image_proxy_service
+CMD ["/app/out/image_proxy_service"]
diff --git a/rust/cloud-storage/Dockerfile.search_processing_service.dev b/rust/cloud-storage/Dockerfile.search_processing_service.dev
index 1c7fe6bd16..354bcdb38a 100644
--- a/rust/cloud-storage/Dockerfile.search_processing_service.dev
+++ b/rust/cloud-storage/Dockerfile.search_processing_service.dev
@@ -1,6 +1,7 @@
# syntax=docker/dockerfile:1
FROM rust:latest AS chef
ENV SQLX_OFFLINE=true
+ENV CARGO_PROFILE_DEV_DEBUG=0
RUN cargo install cargo-strip
WORKDIR /app
diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfile
index 57461e8862..90c15b420f 100644
--- a/rust/cloud-storage/justfile
+++ b/rust/cloud-storage/justfile
@@ -24,10 +24,10 @@ clean:
build:
SQLX_OFFLINE=true cargo build
-# Build all dev service Docker images (pre-warms cache for run_local_build)
+# Build dev service Docker images to pre-warm the cache used by root `run_local`.
build_dev_service_images:
- docker build -f Dockerfile.dev --target builder -t local-services .
- docker build -f Dockerfile.search_processing_service.dev --target builder -t local-search-processing-service .
+ docker build -f Dockerfile.dev --target services_bundle -t macro-local-rust-services:dev .
+ docker build -f Dockerfile.search_processing_service.dev --target search_processing_service -t macro-local-search-processing-service:dev .
# Build all lambda functions
build_lambdas:
diff --git a/rust/sync-service/.dockerignore b/rust/sync-service/.dockerignore
new file mode 100644
index 0000000000..0c18de5f04
--- /dev/null
+++ b/rust/sync-service/.dockerignore
@@ -0,0 +1,10 @@
+target
+node_modules
+.wrangler
+data
+dist
+build
+.dev.vars
+.claude
+README.md
+justfile
diff --git a/rust/sync-service/Dockerfile b/rust/sync-service/Dockerfile
index e63a47b915..f3dda888ac 100644
--- a/rust/sync-service/Dockerfile
+++ b/rust/sync-service/Dockerfile
@@ -2,8 +2,9 @@ FROM rust:1.90-bookworm
# Install Node.js 22.x
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
- apt-get install -y nodejs && \
- npm install -g npm@latest
+ apt-get update && \
+ apt-get install -y --no-install-recommends nodejs && \
+ apt-get clean && rm -rf /var/lib/apt/lists/*
# Install llvm/clang for ring crate compilation
RUN apt-get update && apt-get install -y \
@@ -13,7 +14,7 @@ RUN apt-get update && apt-get install -y \
# Install wasm32 target and worker-build once
RUN rustup target add wasm32-unknown-unknown && \
- cargo install worker-build --locked
+ cargo install worker-build@^0.8 --locked
WORKDIR /app