Skip to content

Instantly share code, notes, and snippets.

@aludvik
Created September 19, 2018 15:54
Show Gist options
  • Save aludvik/20eff98140efb7d84af3bd4c39c3b895 to your computer and use it in GitHub Desktop.
Save aludvik/20eff98140efb7d84af3bd4c39c3b895 to your computer and use it in GitHub Desktop.
Saving time using Rust and Docker with Sawtooth

This guide will help you save time building Sawtooth Core using the official development build tooling.

Prerequisites:

  • You have docker installed and setup
  • You have already built the docker image you are using, I use sawtooth-validator as an example, but this works with other docker containers that build Rust code

Step 1 - Named Persistent Docker Volumes

First, you want to create a persistent Docker volume where all the libraries cargo downloads will live so you don't have to re-download them over and over:

$ docker volume create cargo-registry
cargo-registry

Step 2 - Mount Persistent Volume in Long-Lived Container

We want to start an interactive container and mount our volume and our project on the container's file system so we can use them:

$ docker run -it \
    -v $(pwd):/project/sawtooth-core \
    -v cargo-registry:/root/.cargo/registry 
    sawtooth-vaidator-local
    bash
root@cad7d4019d14:/#

Step 3 - Build

You can now build your code:

$ cd /project/sawtooth-core/validator
$ cargo check # or `build` or `build --release`

NOTE: Take a look at the command directive in the Dockerfile you are starting from to know what you should be doing here. For example, with the validator package, you need to do:

$ cargo build --release \
    && cp ./target/release/sawtooth-validator bin/sawtooth-validator \
    && cp ./target/release/libsawtooth_validator.so lib/libsawtooth_validator.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment