Skip to content

Develop

Frank V. Castellucci edited this page Feb 6, 2018 · 16 revisions

Prerequisites

We use docker images for development so the definitions below assume Docker and Docker Compose have been installed.

Clone the sawtooth-core and sawtooth-eventchain repos:

$ git clone https://github.com/hyperledger/sawtooth-core.git
$ git clone https://github.com/hashblock/sawtooth-eventchain.git

Build the sawtooth-core python components.

cd ~/sawtooth-core
bin/build_all -l python

Docker for Windows (D4W) and Windows Subsystem for Linux (WSL)

WSL and D4w do not agree on the path structure. WSL ads /mnt to a folder path (e.g. /mnt/c) and D4W only understand folders that start with / e.g. /c. Add the following to your ~/.bashrc file to fix this problem. You do need to provide your password.

export DOCKER_HOST='tcp://0.0.0.0:2375'
export PATH=$PATH:~/bin

# mount /mnt/c to /c if not already done
if [ ! -d "/c" ] || [ ! "$(ls -A /c)" ]; then
  echo "Requiring root password to $(tput setaf 6)mount --bind /mnt/c /c$(tput sgr 0)"
  sudo mkdir -p /c
  sudo mount --bind /mnt/c /c
fi

# Change from /mnt/c/... to /c/...
if [ "$(pwd | cut -c -7)" == "/mnt/c/" ]; then
  cd "$(pwd | cut -c 5-)"
fi

# Provide docker for bash and docker-compose
docker() {
  docker.exe "$@"
}

Build

Run the following build command from the root folder. This will build the sawtooth-dev-python image and the sawtooth-units-tp image. The build will also create a container from the sawtooth-dev-python image and run build_python in the container to generate python protobuf files.

bin/build_all

You many need to clean your docker containers and images to build all. Add the following to your ~/.bash_aliases file and then run the dcclean and the diclean commands aliases.

alias diclean='docker images -a | grep '\'' [months|days|weeks]* ago'\'' | awk  '\''{print $3}'\'' | xargs docker rmi -f'
alias dclean='docker ps -a | grep -v '\''CONTAINER\|_config\|_data\|_run'\'' | cut -c-12 | xargs docker rm'

hashblock's docker-compose file naming guid

All mainstream docker-compose files are in docker/compose

We use a 3 part convention, where parts are separated by -, for naming the compose files:

prefix-lifecycle-context

  1. prefix = hashblock
  2. lifecycle = one of #{dev,int,dbg}
  3. context = one of #{units}

Composing and running a sawtooth validator and units transaction processor network

The following uses the hashblock-dev-units.yaml to compose a network of services for units transaction family development. The units-tp image mounts the source code on the host machine and includes the pudb debugger. This allows code inspection and problem solving with any changes to the source are save to the host machine.

;
; To initiate the setup of the units-tp image and bring up the network
;

cd ~/sawtooth-eventchain
docker-compose -f docker/compose/hashblock-dev-units.yaml up

Subsequent executions will not take as long to initialize unless you change the underlying docker files.

Any of the running components can be shelled into from additional bash shell windows:

docker exec -it [component name here] bash
root@2fd6faa664fc:/path#

To stop the processing, exit out of any shelled images, return to the composition terminal window and type Ctrl+C. When the shutdown completes clean up the docker-compose artifacts

; To stop the processing type Ctrl+C in the shell you started it from. 
; When the shutdown completes clean up the docker-compose artifacts

docker-compose -f docker/compose/hashblock-dev-units.yaml down