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(cloud_storage): better docker caching for cloud storage (#152)

Will Hutchinsonf7938b433fe7
diff --git a/.github/workflows/build-cloud-storage-cache.yml b/.github/workflows/build-cloud-storage-cache.yml
new file mode 100644
index 0000000000..c07f0848e5
--- /dev/null
+++ b/.github/workflows/build-cloud-storage-cache.yml
@@ -0,0 +1,46 @@
+name: Build Cloud Storage Cache
+
+on:
+ push:
+ branches:
+ - main
+ paths:
+ - 'rust/cloud-storage/**'
+ - '.github/workflows/build-cloud-storage-cache.yml'
+
+jobs:
+ build-cache:
+ name: Build cache image
+ runs-on:
+ [
+ runs-on,
+ runner=16cpu-linux-x64,
+ hdd=40,
+ spot=false,
+ ssh=false,
+ 'run-id=${{github.run_id}}',
+ ]
+ steps:
+ - uses: actions/checkout@v4
+ - uses: docker/setup-buildx-action@v3
+ - uses: aws-actions/configure-aws-credentials@v4
+ with:
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
+ aws-region: us-east-1
+ - name: login to ecr
+ shell: bash
+ run: |
+ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 569036502058.dkr.ecr.us-east-1.amazonaws.com
+ - name: Build and push cache image
+ shell: bash
+ working-directory: rust/cloud-storage
+ run: |
+ docker buildx build \
+ --platform linux/amd64 \
+ --file Dockerfile.cache \
+ --cache-from type=registry,ref=569036502058.dkr.ecr.us-east-1.amazonaws.com/cloud-storage-cache:latest \
+ --cache-to type=registry,ref=569036502058.dkr.ecr.us-east-1.amazonaws.com/cloud-storage-cache:latest,mode=max \
+ --tag 569036502058.dkr.ecr.us-east-1.amazonaws.com/cloud-storage-cache:latest \
+ --push \
+ .
diff --git a/infra/bun.lock b/infra/bun.lock
index efb6d6f2d1..1181cb0080 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -49,6 +49,10 @@
"stacks/bulk-upload": {
"name": "bulk-upload-stack",
},
+ "stacks/cloud-storage-cache": {
+ "name": "cloud-storage-cache-stack",
+ "version": "0.0.0",
+ },
"stacks/cloud-storage-service": {
"name": "cloud-storage-service-stack",
"version": "0.0.0",
@@ -577,6 +581,8 @@
"clone-response": ["[email protected]", "", { "dependencies": { "mimic-response": "^1.0.0" } }, "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA=="],
+ "cloud-storage-cache-stack": ["cloud-storage-cache-stack@workspace:stacks/cloud-storage-cache"],
+
"cloud-storage-service-stack": ["cloud-storage-service-stack@workspace:stacks/cloud-storage-service"],
"cloud-storage-sha-cleanup-stack": ["cloud-storage-sha-cleanup-stack@workspace:stacks/sha-cleanup"],
diff --git a/infra/stacks/cloud-storage-cache/Pulumi.prod.yaml b/infra/stacks/cloud-storage-cache/Pulumi.prod.yaml
new file mode 100644
index 0000000000..1a38cefb17
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/Pulumi.prod.yaml
@@ -0,0 +1,2 @@
+config:
+ aws:region: us-east-1
diff --git a/infra/stacks/cloud-storage-cache/Pulumi.yaml b/infra/stacks/cloud-storage-cache/Pulumi.yaml
new file mode 100644
index 0000000000..3ac4e265be
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/Pulumi.yaml
@@ -0,0 +1,3 @@
+name: cloud-storage-cache
+runtime: nodejs
+description: Macro Cloud Storage Workspace Cache
diff --git a/infra/stacks/cloud-storage-cache/README.md b/infra/stacks/cloud-storage-cache/README.md
new file mode 100644
index 0000000000..6b627ba937
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/README.md
@@ -0,0 +1,7 @@
+# Cloud Storage Cache
+
+This stack creates an ECR repository for the Cloud Storage cache image.
+
+Note: This stack does not build the cache image itself. It only creates the ECR repository.
+The cache image is built by `.github/workflows/build-cloud-storage-cache.yml` on push to the `main` branch.
+This is because awsx is slow at building images and it's faster to use docker/buildx github action to build the image.
diff --git a/infra/stacks/cloud-storage-cache/index.ts b/infra/stacks/cloud-storage-cache/index.ts
new file mode 100644
index 0000000000..442f4c9e2a
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/index.ts
@@ -0,0 +1,19 @@
+import * as awsx from '@pulumi/awsx';
+import { stack } from '@shared';
+
+const tags = {
+ environment: stack,
+ tech_lead: 'hutch',
+ project: 'cloud-storage-cache',
+};
+
+const BASE_NAME = 'cloud-storage-cache';
+
+const ecrRepository = new awsx.ecr.Repository(`${BASE_NAME}-ecr`, {
+ name: `${BASE_NAME}`,
+ imageTagMutability: 'MUTABLE',
+ forceDelete: true,
+ tags: tags,
+});
+
+export const cloudStorageCacheEcrRepositoryUrl = ecrRepository.url;
diff --git a/infra/stacks/cloud-storage-cache/package.json b/infra/stacks/cloud-storage-cache/package.json
new file mode 100644
index 0000000000..c5c8a92baf
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "cloud-storage-cache-stack",
+ "version": "0.0.0",
+ "private": true,
+ "license": "MIT",
+ "main": "index.ts"
+}
diff --git a/infra/stacks/cloud-storage-cache/tsconfig.json b/infra/stacks/cloud-storage-cache/tsconfig.json
new file mode 100644
index 0000000000..4082f16a5d
--- /dev/null
+++ b/infra/stacks/cloud-storage-cache/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.json"
+}
diff --git a/rust/cloud-storage/.dockerignore b/rust/cloud-storage/.dockerignore
index b7031d801f..4f960ca87b 100644
--- a/rust/cloud-storage/.dockerignore
+++ b/rust/cloud-storage/.dockerignore
@@ -1,17 +1,39 @@
-target/
-infra/
-**/fixtures/*
-**/migrations/*
-**/load-test/*
-search_processing_service/helpers/*
-convert_service/helpers/*
+# Git
.gitignore
+
+# Docker
.dockerignore
Dockerfile*
+
+# Rust
+target/
Cross.toml
+deny.toml
+
+# SQLX
+**/fixtures/*
+**/migrations/*
+
+# build
+justfile
+*.just
+*.sh
Makefile
+scripts/
+
+# Helpers
+search_processing_service/helpers/*
+convert_service/helpers/*
+
+# Testing
+**/load-test/*
+**/test.rs
+
+# Documentation
README.md
-build-local.sh
+CLAUDE.md
+
+# Mac stuff
.DS_Store
*.swp
*.swo
diff --git a/rust/cloud-storage/Dockerfile b/rust/cloud-storage/Dockerfile
index f0675a032b..4aba1eec80 100644
--- a/rust/cloud-storage/Dockerfile
+++ b/rust/cloud-storage/Dockerfile
@@ -1,25 +1,32 @@
-FROM rust:latest AS chef
+# Set the cache image name
+ARG CACHE_IMAGE=569036502058.dkr.ecr.us-east-1.amazonaws.com/cloud-storage-cache:latest
+# Load the cache image
+FROM ${CACHE_IMAGE} AS cache
+
ARG SERVICE_NAME
ENV SQLX_OFFLINE=true
-# We only pay the installation cost once,
-# it will be cached from the second build onwards
-RUN cargo install cargo-chef cargo-strip
-WORKDIR /app
-FROM chef AS planner
-COPY . .
-RUN cargo chef prepare --recipe-path recipe.json --bin ${SERVICE_NAME}
+FROM rust:latest AS chef
+ARG SERVICE_NAME
+ENV SQLX_OFFLINE=true
+RUN cargo install cargo-strip
+WORKDIR /app
FROM chef AS builder
-COPY --from=planner /app/recipe.json recipe.json
-# Build dependencies - this is the caching Docker layer!
-RUN cargo chef cook --release --recipe-path recipe.json --bin ${SERVICE_NAME}
-# Build application
+ARG SERVICE_NAME
+
+# COPY the pre-built dependencies from cache image
+COPY --from=cache /app/target target
+COPY --from=cache /usr/local/cargo /usr/local/cargo
+
COPY . .
+
+# Build the service
RUN cargo build --release --bin ${SERVICE_NAME} && \
cargo strip && \
mv /app/target/release/${SERVICE_NAME} /app/svc
+# Create slim runner to run the service
FROM debian:trixie-slim AS runner
ARG SERVICE_NAME
WORKDIR /app
diff --git a/rust/cloud-storage/Dockerfile.cache b/rust/cloud-storage/Dockerfile.cache
new file mode 100644
index 0000000000..856fa48096
--- /dev/null
+++ b/rust/cloud-storage/Dockerfile.cache
@@ -0,0 +1,28 @@
+FROM rust:latest AS chef
+ENV SQLX_OFFLINE=true
+
+# We only pay the installation cost once,
+# it will be cached from the second build onwards
+RUN cargo install cargo-chef cargo-strip
+
+# Needed for convert service rs-libreoffice-bindings
+RUN apt-get update && apt-get install -y \
+ llvm \
+ libclang-dev \
+ clang \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /app
+
+FROM chef AS planner
+COPY . .
+
+# Prepare recipe for entire workspace
+RUN cargo chef prepare --recipe-path recipe.json
+
+FROM chef AS builder
+COPY --from=planner /app/recipe.json recipe.json
+
+# Cook all workspace dependencies
+RUN cargo chef cook --release --recipe-path recipe.json