Docker¶
The Docker image provides a complete Rust + WASM toolchain so you can compile Dilithia smart contracts without installing Rust locally. It is also designed as a small contract compilation service: by default it runs the Dilithia contract CLI against the mounted /workspace.
When to Use Docker¶
- You do not have (or do not want) a local Rust installation
- You need reproducible builds across different developer machines
- You are setting up CI/CD and want a consistent build environment
Build the Image¶
The image is based on rust:1.88.0-bookworm and includes:
- The
wasm32-unknown-unknownRust target - pinned upstream Binaryen (
wasm-opt) for WASM optimization - The
dilithia-contractCLI installed in the image - A pre-warmed Cargo cache to reduce the first build penalty
Compile a Contract¶
Mount your project directory into /workspace and run:
The default entrypoint runs:
Your compiled artifact will appear at:
Run Other CLI Commands¶
Because the image entrypoint is dilithia-contract, you can invoke any subcommand directly:
docker run --rm -v "$(pwd)":/workspace dilithia/contract-builder init --name my_contract
docker run --rm -v "$(pwd)":/workspace dilithia/contract-builder build --path /workspace --output json
Override the Entrypoint¶
To drop into a shell for debugging:
CI/CD Integration¶
GitHub Actions¶
name: Build Contract
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build contract WASM
run: |
docker build -f contract-tools/docker/Dockerfile -t dilithia/contract-builder .
docker run --rm -v ${{ github.workspace }}:/workspace dilithia/contract-builder
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: contract-wasm
path: target/wasm32-unknown-unknown/release/*.wasm
GitLab CI¶
build-contract:
image: docker:latest
services:
- docker:dind
script:
- docker build -f contract-tools/docker/Dockerfile -t dilithia/contract-builder .
- docker run --rm -v "$(pwd)":/workspace dilithia/contract-builder
artifacts:
paths:
- target/wasm32-unknown-unknown/release/*.wasm
Cache Mounts for Faster Rebuilds¶
The image stores Cargo and target caches under /cache, so you can persist them across runs:
docker run --rm \
-v "$(pwd)":/workspace \
-v dilithia-contract-cargo:/cache/cargo \
-v dilithia-contract-target:/cache/target \
dilithia/contract-builder
This is especially useful in CI runners or long-lived local environments.
Image Details¶
The Dockerfile performs the following steps:
- Starts from
rust:1.88.0-bookworm - Installs the
wasm32-unknown-unknowntarget viarustup - Installs build prerequisites via
apt - Downloads a pinned upstream Binaryen release and installs
wasm-opt - Copies
contract-toolsinto the image and resolvesdilithia-sdk-rustfrom crates.io during install - Installs the
dilithia-contractCLI into the image - Warms the Cargo cache with a minimal Dilithia contract build
- Sets
/workspaceas the working directory - Sets the entrypoint to
dilithia-contract - Sets the default command to
build --path /workspace