Skip to content

Commit 847b504

Browse files
committed
Fixes to make all carts build 95% completion
1 parent 7ba7702 commit 847b504

File tree

1,378 files changed

+7623
-13114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,378 files changed

+7623
-13114
lines changed

.github/workflows/ci-enhanced.yml

Lines changed: 582 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/deploy-enhanced.yml

Lines changed: 643 additions & 0 deletions
Large diffs are not rendered by default.

crates/codegraph-api/src/enhanced_health.rs

Lines changed: 724 additions & 0 deletions
Large diffs are not rendered by default.

crates/codegraph-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod event_bus;
44
pub mod graphql;
55
pub mod handlers;
66
pub mod health;
7+
pub mod enhanced_health;
78
pub mod mutations;
89
pub mod service_registry;
910
pub mod queries;

crates/codegraph-api/src/routes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{handlers, health, service_registry, vector_handlers, versioning_handlers, streaming_handlers, http2_handlers, AppState, auth_middleware, create_schema, RateLimitManager, rest};
1+
use crate::{handlers, health, enhanced_health, service_registry, vector_handlers, versioning_handlers, streaming_handlers, http2_handlers, AppState, auth_middleware, create_schema, RateLimitManager, rest};
22
use axum::{
33
routing::{get, post},
44
Router,
@@ -29,6 +29,7 @@ pub fn create_router(state: AppState) -> Router {
2929
let mut app = Router::new()
3030
// Health and readiness checks
3131
.route("/health", get(health::comprehensive_health_check))
32+
.route("/health/enhanced", get(enhanced_health::enhanced_health_check))
3233
.route("/health/live", get(health::liveness_check))
3334
.route("/health/ready", get(health::readiness_check))
3435
.route("/metrics", get(handlers::metrics_handler))

deploy/k8s/deployment.yaml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
type: RollingUpdate
1111
rollingUpdate:
1212
maxUnavailable: 0
13-
maxSurge: 25%
13+
maxSurge: 1
1414
selector:
1515
matchLabels:
1616
app: codegraph-api
@@ -19,32 +19,46 @@ spec:
1919
labels:
2020
app: codegraph-api
2121
spec:
22+
securityContext:
23+
runAsNonRoot: true
24+
runAsUser: 1000
25+
fsGroup: 1000
2226
containers:
2327
- name: codegraph-api
2428
image: ghcr.io/OWNER/REPO:latest
25-
imagePullPolicy: IfNotPresent
29+
imagePullPolicy: Always
2630
ports:
27-
- containerPort: 3000
31+
- containerPort: 8080
32+
name: http
33+
protocol: TCP
34+
- containerPort: 9090
35+
name: metrics
36+
protocol: TCP
2837
env:
2938
- name: RUST_LOG
3039
value: info
31-
- name: DATABASE_PATH
32-
value: /app/data/codegraph.db
40+
- name: ROCKSDB_PATH
41+
value: /data/rocksdb
42+
- name: VECTOR_STORE_PATH
43+
value: /data/vectors
44+
- name: BIND_ADDRESS
45+
value: 0.0.0.0:8080
3346
readinessProbe:
3447
httpGet:
35-
path: /health
36-
port: 3000
48+
path: /ready
49+
port: 8080
3750
initialDelaySeconds: 5
38-
periodSeconds: 10
39-
timeoutSeconds: 5
40-
failureThreshold: 6
51+
periodSeconds: 5
52+
timeoutSeconds: 3
53+
failureThreshold: 3
4154
livenessProbe:
4255
httpGet:
4356
path: /health
44-
port: 3000
45-
initialDelaySeconds: 10
46-
periodSeconds: 20
57+
port: 8080
58+
initialDelaySeconds: 30
59+
periodSeconds: 10
4760
timeoutSeconds: 5
61+
failureThreshold: 3
4862
resources:
4963
requests:
5064
cpu: "100m"
@@ -54,8 +68,10 @@ spec:
5468
memory: "512Mi"
5569
volumeMounts:
5670
- name: data
57-
mountPath: /app/data
71+
mountPath: /data
5872
volumes:
5973
- name: data
6074
emptyDir: {}
75+
nodeSelector:
76+
kubernetes.io/arch: amd64
6177

deploy/k8s/service.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ spec:
99
app: codegraph-api
1010
ports:
1111
- name: http
12-
port: 3000
13-
targetPort: 3000
12+
port: 80
13+
targetPort: 8080
14+
protocol: TCP
15+
- name: metrics
16+
port: 9090
17+
targetPort: 9090
1418
protocol: TCP
1519
type: ClusterIP
1620

deployment/docker/Dockerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# CodeGraph production container (multi-stage, minimal runtime)
2+
3+
# --- Builder stage -----------------------------------------------------------
4+
FROM rust:1.75-slim AS builder
5+
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
build-essential \
9+
cmake \
10+
pkg-config \
11+
clang \
12+
libssl-dev \
13+
libclang-dev \
14+
zlib1g-dev \
15+
libbz2-dev \
16+
liblz4-dev \
17+
libzstd-dev \
18+
libsnappy-dev \
19+
librocksdb-dev \
20+
libfaiss-dev \
21+
ca-certificates \
22+
curl \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
WORKDIR /app
26+
27+
# Copy workspace manifests first to leverage Docker layer caching
28+
COPY Cargo.toml Cargo.lock ./
29+
COPY crates/ ./crates/
30+
31+
# Build dependencies (cache-friendly)
32+
RUN cargo fetch
33+
34+
# Build release binary for codegraph-api
35+
ENV RUSTFLAGS="-C target-cpu=native -C debuginfo=0"
36+
RUN cargo build --release -p codegraph-api && \
37+
strip target/release/codegraph-api || true
38+
39+
# Collect all dynamic library runtime deps for the binary
40+
RUN set -euo pipefail; \
41+
mkdir -p /opt/libs; \
42+
ldd target/release/codegraph-api | awk '{print $3}' | \
43+
grep -E '^/' | sort -u | \
44+
xargs -I '{}' cp -v '{}' /opt/libs/ || true; \
45+
# include libgcc_s & libstdc++ explicitly when present
46+
for f in /usr/lib/x86_64-linux-gnu/libstdc++.so.* /lib/x86_64-linux-gnu/libgcc_s.so.*; do \
47+
[ -e "$f" ] && cp -v "$f" /opt/libs/ || true; \
48+
done
49+
50+
# Copy production config (can be overridden by bind mount)
51+
COPY config/ /opt/config/
52+
53+
54+
# --- Runtime stage -----------------------------------------------------------
55+
FROM debian:bookworm-slim AS runtime
56+
57+
ARG DEBIAN_FRONTEND=noninteractive
58+
RUN apt-get update && apt-get install -y --no-install-recommends \
59+
ca-certificates \
60+
tini \
61+
wget \
62+
&& rm -rf /var/lib/apt/lists/*
63+
64+
# Non-root user
65+
RUN useradd -r -u 10001 -s /usr/sbin/nologin codegraph
66+
67+
WORKDIR /app
68+
69+
# Minimal runtime deps copied from builder to keep image small
70+
COPY --from=builder /opt/libs/ /usr/local/lib/
71+
ENV LD_LIBRARY_PATH=/usr/local/lib
72+
73+
# Copy binary and default config
74+
COPY --from=builder /app/target/release/codegraph-api /usr/local/bin/codegraph-api
75+
COPY --from=builder /opt/config/ /app/config/
76+
77+
# Data dir for RocksDB
78+
RUN mkdir -p /var/lib/codegraph && chown -R codegraph:codegraph /var/lib/codegraph
79+
80+
# Drop privileges and run as non-root
81+
USER codegraph:codegraph
82+
83+
# Expose production port (matches config/production.toml)
84+
EXPOSE 8080
85+
86+
# Security: read-only rootfs except for volumes
87+
VOLUME ["/var/lib/codegraph", "/app/config"]
88+
89+
ENV APP_ENV=production \
90+
RUST_LOG=info \
91+
RUST_BACKTRACE=1
92+
93+
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 \
94+
CMD wget -qO- http://127.0.0.1:8080/health/ready >/dev/null 2>&1 || exit 1
95+
96+
# Ensure tini is PID 1 for proper signal handling
97+
ENTRYPOINT ["/usr/bin/tini", "--"]
98+
CMD ["/usr/local/bin/codegraph-api"]

deployment/docker/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CodeGraph Production Deployment (Docker)
2+
3+
This directory contains a production-grade containerization setup for CodeGraph with:
4+
5+
- Multi-stage Dockerfile for minimal runtime images
6+
- Docker Compose stack: api, vector-maintainer, graph-backup, Prometheus, Grafana
7+
- Security hardening, health checks, and resource limits
8+
- Persistent volumes and automated backup strategy
9+
- Orchestration scripts and a deployment test harness
10+
11+
## Quick Start
12+
13+
- Build and start all services:
14+
- `deployment/docker/scripts/start.sh`
15+
- Stop services:
16+
- `deployment/docker/scripts/stop.sh`
17+
- Scale API replicas (Compose):
18+
- `deployment/docker/scripts/scale.sh 3`
19+
20+
API runs on `http://localhost:8080`.
21+
22+
## Volumes
23+
24+
- `graph-data`: persists RocksDB at `/var/lib/codegraph/graph.db`
25+
- `backups`: periodic compressed backups (`.tar.zst`) created by `graph-backup`
26+
27+
Backups are created every 4 hours by default and the latest 10 are retained. Adjust via env in `docker-compose.yml`.
28+
29+
## Health & Monitoring
30+
31+
- API health: `/health`, `/health/ready`, `/health/live`
32+
- Prometheus (9090) scrapes API metrics at `/metrics`
33+
- Grafana (3000) provides dashboards (anonymous access enabled by default)
34+
35+
## Security Hardening
36+
37+
- Containers drop all Linux capabilities and enforce `no-new-privileges`
38+
- Non-root user (UID 10001) for runtime
39+
- Read-only root FS with explicit writable volumes
40+
- Minimal runtime image with only required shared libraries
41+
42+
## Configuration
43+
44+
- Defaults from `config/production.toml` are copied into the image
45+
- Override via env (e.g., `CODEGRAPH__SERVER__PORT`) or by bind-mounting `config/`
46+
47+
## Tests
48+
49+
A deployment test harness is included:
50+
51+
- `deployment/docker/tests/run_tests.sh`
52+
- Static checks over Compose/Dockerfile
53+
- Optional image size test: `RUN_BUILD_TEST=1`
54+
- Optional integration health check: `RUN_INTEGRATION=1`
55+
56+
Example:
57+
58+
```
59+
RUN_BUILD_TEST=1 RUN_INTEGRATION=1 bash deployment/docker/tests/run_tests.sh
60+
```
61+
62+
## Backups
63+
64+
- Sidecar service `graph-backup` tars `/var/lib/codegraph` to `backups` volume
65+
- `deployment/docker/scripts/restore.sh` restores a selected archive
66+
67+
## Notes
68+
69+
- Vector operations are in-process within the API. `vector-maintainer` sidecar periodically triggers `/vector/index/rebuild` to keep indexes fresh.
70+
- Ensure Docker Desktop or engine has sufficient resources (CPU/RAM) for the stack.
71+

0 commit comments

Comments
 (0)