Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build artifacts - exclude to reduce context size
target/
!target/docker/Dockerfile
!target/docker/build.sh
!target/docker/README.md

# Git files
.git
.gitignore

# IDE and editor files
.vscode
.idea
*.swp
*.swo
*~
.DS_Store

# Documentation (README at root is kept)
docs/

# Cache and temporary files
.cache
tmp/
*.tmp

# Claude and user-specific files
.claude
.channels_cache_v2.json
.users_cache.json

# Logs
*.log

# Environment files
.env
.env.local
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mork-frontend = {path = "./frontend"}
mork = {path = "./kernel"}

# External to MORK
#freeze = { version="0.1.1", git="https://github.com/luketpeterson/Freeze.git" } #Fixes build on MacOS
freeze = {version="0.1.1", git="https://github.com/luketpeterson/Freeze.git"} #Fixes build on MacOS
gxhash = {version="3.4.1", git="https://github.com/luketpeterson/gxhash/"} # for dag_serialization

[workspace.dependencies.pathmap]
Expand Down
67 changes: 67 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Dockerfile for MORK Environment
# Multi-architecture support: linux/amd64, linux/arm64
# Base: Ubuntu with Rust, CMake, and all required dependencies

# Declare platform arguments (automatically provided by buildx)
ARG TARGETPLATFORM
ARG BUILDPLATFORM

FROM --platform=$TARGETPLATFORM ubuntu:22.04

# Re-declare for use in this stage
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
curl \
ca-certificates \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Install Rust (nightly toolchain with pinned version for stability)
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_MIN_STACK=16777216 \
CARGO_NET_GIT_FETCH_WITH_CLI=true

# Use latest nightly for full edition2024 support
ARG RUST_VERSION=nightly

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
sh -s -- -y --default-toolchain ${RUST_VERSION} --profile minimal && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME

# Set working directory
WORKDIR /build

# Clone PathMap dependency
ARG PATHMAP_REPO=https://github.com/Adam-Vandervorst/PathMap.git
ARG PATHMAP_BRANCH=master
RUN git clone --depth 1 --branch ${PATHMAP_BRANCH} ${PATHMAP_REPO} PathMap

# Copy MORK source code
COPY . /build/MORK

# Build MORK in release mode with increased stack size and optimization for smaller code
WORKDIR /build/MORK
RUN cargo build --release --verbose

# Set the entrypoint to the built binary
CMD ["/build/MORK/target/release/mork", "--help"]

# Metadata
LABEL maintainer="MORK Team"
LABEL description="MeTTa Optimal Reduction Kernel - Multi-architecture support"
LABEL version="0.1.0"
LABEL org.opencontainers.image.source="https://github.com/trueagi-io/mork"
216 changes: 216 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# MORK Docker Environment

This directory contains Docker configuration for running MORK (MeTTa Optimal Reduction Kernel) in a containerized environment.

**Key Feature**: This Docker setup uses your **local MORK repository** for building, so any local changes will be included in the image. PathMap is cloned from git during the build.

## Contents

- `Dockerfile` - Multi-stage Dockerfile for building MORK
- `build.sh` - Build script with multi-platform support
- `../.dockerignore` - Files to exclude from Docker build context (at MORK root)

## Quick Start

### Building the Image

Build for all platforms (AMD64 and ARM64):
```bash
./target/docker/build.sh all
```

Build for specific platform:
```bash
# For AMD64/Intel systems
./target/docker/build.sh amd64 --load

# For ARM64/Apple Silicon
./target/docker/build.sh arm64 --load
```

The `--load` flag loads the image into your local Docker daemon (required for single-platform builds if you want to run locally).

### Running MORK in Docker

Once built and loaded, run MORK:
```bash
docker run --rm mork:latest
```

Run with specific command:
```bash
docker run --rm mork:latest mork [your-args]
```

Mount a volume for data persistence:
```bash
docker run --rm -v $(pwd)/data:/mork/data mork:latest
```

## Build Script Options

```bash
./target/docker/build.sh [PLATFORM] [OPTIONS]
```

### Platform Options
- `amd64` - Build for AMD64/Intel 64-bit systems (linux/amd64)
- `arm64` - Build for ARM64/Apple Silicon (linux/arm64)
- `all` - Build for all platforms (default)

### Build Options
- `--no-cache` - Build without using Docker cache
- `--push` - Push image to container registry (requires `docker login`)
- `--load` - Load image into local Docker (single platform only)
- `-h, --help` - Display help message

### Environment Variables
- `MORK_IMAGE_NAME` - Docker image name (default: `mork`)
- `MORK_IMAGE_TAG` - Docker image tag (default: `latest`)
- `PATHMAP_BRANCH` - Git branch/tag for PathMap repository (default: `master`)

## Examples

### Build for local development (Apple Silicon)
```bash
./target/docker/build.sh arm64 --load
```

### Build for local development (Intel Mac or Linux)
```bash
./target/docker/build.sh amd64 --load
```

### Build and push to registry
```bash
export MORK_IMAGE_NAME=myregistry/mork
export MORK_IMAGE_TAG=v0.1.0
docker login myregistry
./target/docker/build.sh all --push
```

### Build without cache (clean build)
```bash
./target/docker/build.sh arm64 --no-cache --load
```

### Build with specific PathMap branch
```bash
export PATHMAP_BRANCH=experimental
./target/docker/build.sh arm64 --load
```

## Architecture

### Multi-Stage Build

The Dockerfile uses a multi-stage build process:

1. **Builder Stage**:
- Based on `debian:bookworm-slim`
- Installs Rust nightly toolchain via rustup
- Installs build dependencies (gcc, cmake, libssl, etc.)
- **Clones PathMap from git** (https://github.com/Adam-Vandervorst/PathMap.git)
- **Copies local MORK repository** (including any uncommitted changes)
- Builds MORK with `--release` flag

2. **Runtime Stage**:
- Based on minimal `debian:bookworm-slim`
- Includes only runtime dependencies
- Runs as non-root user (`mork`)
- Contains only the compiled binaries

This approach:
- Minimizes the final image size (builder artifacts are discarded)
- Uses your local MORK code (perfect for development and testing)
- Ensures PathMap dependency is always up-to-date from git
- Includes all local changes (even uncommitted ones)

### Multi-Platform Support

The build script uses Docker Buildx to support multiple platforms:
- **linux/amd64** - For Intel/AMD 64-bit systems
- **linux/arm64** - For ARM64 systems (Apple Silicon, ARM servers)

## Requirements

- Docker with buildx support (Docker Desktop includes this)
- Internet connection (to clone PathMap)
- Sufficient disk space for build artifacts (~2GB during build, ~200MB final image)

**Important**: The build uses your local MORK files, so make sure you're in the MORK directory when running the build script.

## Troubleshooting

### Git clone fails for PathMap
If you see errors cloning PathMap:
- Check your internet connection
- Verify https://github.com/Adam-Vandervorst/PathMap.git is accessible
- Try building with a specific branch:
```bash
export PATHMAP_BRANCH=master
./target/docker/build.sh arm64 --load
```

### Buildx not available
Install or enable Docker Buildx:
```bash
docker buildx version
```

If not available, update Docker Desktop or install the buildx plugin.

### Build fails with memory error
Increase Docker's memory allocation in Docker Desktop settings (Preferences → Resources → Memory).

### Multi-platform build not loading
Multi-platform builds cannot be loaded directly into Docker. Either:
- Build for a single platform with `--load`:
```bash
./target/docker/build.sh arm64 --load
```
- Or push to a registry and pull back:
```bash
./target/docker/build.sh all --push
docker pull mork:latest
```

### Build context is too large
If the build is slow due to large context:
- Check that `target/` directory is excluded (via `.dockerignore`)
- Remove any large files from the MORK directory
- The `.dockerignore` file should already exclude build artifacts

## Image Details

- **Base Image**: debian:bookworm-slim (both builder and runtime stages)
- **Rust Version**: Nightly (installed via rustup in builder stage)
- **User**: Non-root user `mork` (UID 1000)
- **Working Directory**: `/mork`
- **Data Directory**: `/mork/data` (for mounting volumes)
- **Binaries**: Installed in `/usr/local/bin/`

## Notes

- The Dockerfile installs Rust nightly due to MORK's use of edition 2024 features
- PathMap dependency is cloned from git during build
- **Local MORK files** (including uncommitted changes) are included in the build
- Build artifacts from local builds are excluded via `.dockerignore`
- The image runs as a non-root user for security

## Development Workflow

This Docker setup is ideal for development:

1. **Make changes** to MORK code locally
2. **Build the image** with your changes:
```bash
./target/docker/build.sh arm64 --load
```
3. **Test** the changes in the container:
```bash
docker run --rm mork:latest mork [test-args]
```
4. **Iterate** - repeat steps 1-3 as needed

Since the build uses local files, you can test changes before committing them to git.
Loading