Skip to content

Commit 30f673d

Browse files
committed
Docker file setup for build and test
1 parent 6616355 commit 30f673d

12 files changed

Lines changed: 477 additions & 44 deletions

File tree

.cargo/config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Cargo configuration for Docker builds
2+
# Limits parallel jobs to reduce memory usage
3+
4+
[build]
5+
# Limit parallel compilation jobs to reduce memory pressure
6+
jobs = 2
7+
8+
[target.wasm32-unknown-unknown]
9+
# Optimize WASM builds
10+
rustflags = ["-C", "opt-level=z"]
11+

.dockerignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Rust
7+
target/
8+
# Cargo.lock - needed for reproducible builds
9+
# Cargo.lock
10+
11+
# IDE
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.swo
16+
*~
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Documentation
23+
*.md
24+
!README.md
25+
26+
# Tests - keep for build (needed for cargo build)
27+
# Commented out so tests are included in build context
28+
# tests/
29+
30+
# Temporary files
31+
*.tmp
32+
*.log
33+

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Multi-stage Dockerfile for Roxy Price (Linera Application)
2+
# Build stage
3+
FROM rust:1.86.0-slim as builder
4+
5+
# Install build dependencies
6+
RUN apt-get update && apt-get install -y \
7+
pkg-config \
8+
libssl-dev \
9+
protobuf-compiler \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Set working directory
13+
WORKDIR /app
14+
15+
# Copy manifest files
16+
COPY Cargo.toml Cargo.lock ./
17+
COPY rust-toolchain.toml ./
18+
19+
# Copy source code
20+
COPY src ./src
21+
22+
# Copy tests directory (needed for cargo build)
23+
COPY tests ./tests
24+
25+
# Install wasm32 target
26+
RUN rustup target add wasm32-unknown-unknown
27+
28+
# Build the project
29+
RUN cargo build --release --target wasm32-unknown-unknown
30+
31+
# Build native binaries for testing
32+
RUN cargo build --release
33+
34+
# Runtime stage - minimal image for running the application
35+
FROM debian:bookworm-slim
36+
37+
# Install runtime dependencies
38+
RUN apt-get update && apt-get install -y \
39+
ca-certificates \
40+
&& rm -rf /var/lib/apt/lists/*
41+
42+
# Create app directory
43+
WORKDIR /app
44+
45+
# Copy built artifacts from builder
46+
COPY --from=builder /app/target/wasm32-unknown-unknown/release/*.wasm ./
47+
COPY --from=builder /app/target/release/predictive_manager_contract ./
48+
COPY --from=builder /app/target/release/predictive_manager_service ./
49+
COPY --from=builder /app/config.json ./
50+
51+
# Set environment variables
52+
ENV RUST_LOG=info
53+
ENV RUST_BACKTRACE=1
54+
55+
# Default command (can be overridden)
56+
CMD ["./predictive_manager_service"]
57+

Dockerfile.dev

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Development Dockerfile for Roxy Price
2+
# This image includes all tools needed for development and testing
3+
4+
FROM rust:1.86.0-slim
5+
6+
# Install build dependencies
7+
RUN apt-get update && apt-get install -y \
8+
pkg-config \
9+
libssl-dev \
10+
protobuf-compiler \
11+
git \
12+
curl \
13+
build-essential \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Install wasm32 target
17+
RUN rustup target add wasm32-unknown-unknown
18+
19+
# Install additional Rust tools
20+
RUN rustup component add clippy rustfmt rust-src
21+
22+
# Set working directory
23+
WORKDIR /app
24+
25+
# Set environment variables
26+
ENV RUST_LOG=debug
27+
ENV RUST_BACKTRACE=1
28+
ENV CARGO_TERM_COLOR=always
29+
30+
# Default command (keep container running)
31+
CMD ["tail", "-f", "/dev/null"]
32+

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Makefile for Roxy Price Project
2+
.PHONY: help build test clean docker-build docker-up docker-down docker-dev docker-test
3+
4+
# Default target
5+
help:
6+
@echo "Roxy Price - Available commands:"
7+
@echo ""
8+
@echo "Local Development:"
9+
@echo " make build - Build the project (release mode)"
10+
@echo " make build-wasm - Build WASM binaries"
11+
@echo " make test - Run all tests"
12+
@echo " make clippy - Run clippy linter"
13+
@echo " make fmt - Format code"
14+
@echo " make clean - Clean build artifacts"
15+
@echo ""
16+
@echo "Docker:"
17+
@echo " make docker-build - Build Docker images"
18+
@echo " make docker-up - Start Docker containers"
19+
@echo " make docker-down - Stop Docker containers"
20+
@echo " make docker-dev - Start development container"
21+
@echo " make docker-test - Run tests in Docker"
22+
@echo " make docker-shell - Access development container shell"
23+
24+
# Local development
25+
build:
26+
cargo build --release
27+
28+
build-wasm:
29+
cargo build --release --target wasm32-unknown-unknown
30+
31+
test:
32+
cargo test --verbose
33+
34+
clippy:
35+
cargo clippy -- -D warnings
36+
37+
fmt:
38+
cargo fmt --all
39+
40+
fmt-check:
41+
cargo fmt --all -- --check
42+
43+
clean:
44+
cargo clean
45+
46+
# Docker commands
47+
docker-build:
48+
docker-compose build
49+
50+
docker-up:
51+
docker-compose up -d
52+
53+
docker-down:
54+
docker-compose down
55+
56+
docker-dev:
57+
docker-compose up -d roxy-dev
58+
@echo "Development container started. Use 'make docker-shell' to access it."
59+
60+
docker-shell:
61+
docker-compose exec roxy-dev bash
62+
63+
docker-test:
64+
docker-compose exec roxy-dev cargo test --verbose
65+
66+
docker-build-prod:
67+
docker build -t roxy:latest .
68+
69+
docker-run-prod:
70+
docker run -p 8080:8080 roxy:latest
71+
72+
# CI/CD helpers
73+
ci-build: fmt-check clippy build build-wasm test
74+

QUICK_START.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Quick Start Guide - Docker Setup
2+
3+
4+
5+
```bash
6+
# Build dev image (faster - just installs tools)
7+
docker build -f Dockerfile.dev -t roxy-dev .
8+
9+
# Run with volume mounting (instant rebuilds)
10+
docker run -it --rm \
11+
-v $(pwd):/app \
12+
-v cargo-cache:/usr/local/cargo/registry \
13+
-v target-cache:/app/target \
14+
roxy-dev bash
15+
16+
# Inside container, build and test
17+
cargo build
18+
cargo test
19+
```
20+
21+
## Using Docker Compose (Easiest)
22+
23+
```bash
24+
# Start development container (uses volumes - no rebuild needed)
25+
docker-compose up -d roxy-dev
26+
27+
# Access container shell
28+
docker-compose exec roxy-dev bash
29+
30+
# Build inside container (uses cached volumes)
31+
cargo build --release
32+
```
33+
# Access the container shell
34+
```bash
35+
docker-compose exec roxy-dev bash
36+
```
37+
38+
# Or run commands directly
39+
```bash
40+
docker-compose exec roxy-dev cargo build
41+
docker-compose exec roxy-dev cargo test
42+
docker-compose exec roxy-dev cargo check
43+
```
44+
45+
# Stop containers
46+
```bash
47+
docker-compose down
48+
```
49+
50+
# Start again
51+
```bash
52+
docker-compose up -d roxy-dev
53+
```
54+
55+
## Memory Issues? (Linker Killed)
56+
57+
If you see `ld terminated with signal 9 [Killed]`, it's an out-of-memory issue.
58+
59+
**Quick Fix:**
60+
```bash
61+
# Run tests with single job (uses less memory)
62+
docker-compose exec roxy-dev cargo test --jobs 1
63+
64+
# Or build in release mode (uses less memory)
65+
docker-compose exec roxy-dev cargo test --release --jobs 1
66+
```
67+
68+
**Better Solution:** Increase Docker Desktop memory limit:
69+
1. Docker Desktop → Settings → Resources → Advanced
70+
2. Increase Memory to 4GB+ (recommended: 6-8GB)
71+
3. Apply & Restart
72+
73+
See `DOCKER_TROUBLESHOOTING.md` for more solutions.
74+

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
services:
2+
# Development service - for building and testing
3+
roxy-dev:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
target: builder
8+
volumes:
9+
- .:/app
10+
- cargo-cache:/usr/local/cargo/registry
11+
- target-cache:/app/target
12+
working_dir: /app
13+
command: tail -f /dev/null # Keep container running for development
14+
environment:
15+
- RUST_LOG=debug
16+
- RUST_BACKTRACE=1
17+
# Limit parallel compilation to reduce memory usage
18+
- CARGO_BUILD_JOBS=2
19+
# Use incremental compilation
20+
- CARGO_INCREMENTAL=1
21+
stdin_open: true
22+
tty: true
23+
24+
25+
# Production service - runs the built application
26+
roxy:
27+
build:
28+
context: .
29+
dockerfile: Dockerfile
30+
ports:
31+
- "8080:8080" # Adjust port as needed for your service
32+
environment:
33+
- RUST_LOG=info
34+
- RUST_BACKTRACE=1
35+
volumes:
36+
- ./config.json:/app/config.json:ro
37+
restart: unless-stopped
38+
39+
volumes:
40+
cargo-cache:
41+
target-cache:
42+

0 commit comments

Comments
 (0)