github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/BUILD.md (about)

     1  
     2  ![Hyperledger Sawtooth](images/sawtooth_logo_light_blue-small.png)
     3  
     4  Hyperledger Sawtooth Core Developer's Setup Guide
     5  =============
     6  
     7  If you are planning to contribute code to the Sawtooth project, please review
     8  the contributing guide: [CONTRIBUTING.md]
     9  
    10  Supported operating systems: Ubuntu 16.04 and macOS
    11  
    12  If you want to use a Windows system, we recommend that you install Ubuntu 16.04
    13  in a virtual machine manager, such as Hyper-V or VirtualBox, and develop from
    14  the guest operating system.
    15  
    16  **Note:** All commands in this guide use the Bash shell. While the Bash shell
    17  is not strictly required as the command shell, many of the scripts in the build
    18  system are Bash scripts and require Bash to execute.
    19  
    20  Step One: Install Docker
    21  -------------
    22  The Sawtooth core requirements are:
    23  - Docker Community Edition (version 17.05.0-ce or newer)
    24  - Docker Compose (version 1.13.0 or newer)
    25  
    26  Install the Docker software.
    27  
    28  macOS:
    29  
    30  - Install the latest version of Docker Engine for macOS:
    31    <https://docs.docker.com/docker-for-mac/install/>
    32  
    33  - On macOS, Docker Compose is installed automatically when you install Docker Engine.
    34  
    35  Ubuntu:
    36  
    37  - Install the latest version of Docker Engine for Linux: <https://docs.docker.com/engine/installation/linux/ubuntu>
    38  
    39  - Install Docker Compose: <https://docs.docker.com/compose/install/>
    40  
    41  **Note:** The minimum version of Docker Engine necessary is 17.03.0-ce.
    42    Linux distributions often ship with older versions of Docker.
    43  
    44  Next, add your username to the group `docker` to avoid having to run every
    45  docker command as a `sudo`. (Otherwise, you will need to prefix each
    46  command in Step Four, Step Five, and Step Six with `sudo`.)
    47  Run the following command:
    48  
    49  ```bash
    50  $ sudo adduser $USER docker
    51  ```
    52  
    53  **Note:** If $USER is not set in the environment on your system, replace $USER in the previous command with your username.
    54  
    55  You will need to log out and log back in to your system for the change in group membership to take effect.
    56  
    57  Step Two: Configure Proxy (Optional)
    58  -------------
    59  
    60  If you are behind a network proxy, follow these steps before continuing.
    61  
    62  **Important:** The URLs and port numbers shown below are examples only.
    63  Use the actual URLs and port numbers for your environment.
    64  Contact your network administrator for this information if necessary.
    65  
    66  Run the following commands to set the environment variables `http_proxy`, `https_proxy`, and `no_proxy`.
    67  
    68  **Important:** Replace the example URLs and ports with the actual URLs and port numbers for your environment.
    69  
    70  ```bash
    71    $ export http_proxy=http://proxy-server.example:3128
    72    $ export https_proxy=http://proxy-server.example:3129
    73    $ export no_proxy=example.com,another-example.com,127.0.0.0
    74  ```
    75  
    76  **Note:** Add these commands to either your `.profile` or `.bashrc` file
    77  so you don't have to set them every time you open a new shell.
    78  
    79  **Docker Proxy Settings (Optional)**
    80  
    81  To configure Docker to work with an HTTP or HTTPS proxy server, follow the
    82  instructions for your operating system:
    83  
    84  * macOS - See the instructions for proxy configuration in
    85    "Get started with Docker for Mac": <https://docs.docker.com/docker-for-mac/>
    86  
    87  * Ubuntu - See the instructions for HTTP/HTTPS proxy configuration in
    88    "Control and configure Docker with systemd": <https://docs.docker.com/engine/admin/systemd/#httphttps-proxy>
    89  
    90  Create the file `/etc/systemd/system/docker.service.d/http-proxy.conf` with the
    91  following contents:
    92  
    93  **Important:** Replace the example URLs and ports with the actual URLs and port numbers for your environment.
    94  
    95  ```text
    96  [Service]
    97  Environment="HTTP_PROXY=http://proxy-server.example:3128" "HTTPS_PROXY=http://proxy-server.example:3129" "http_proxy=http://proxy-server.example:3128" "https_proxy=http://proxy-server.example:3129" "no_proxy=example.com,another-example.com,127.0.0.0"
    98  ```
    99  
   100  **Restart Docker**
   101  
   102  ```bash
   103  $ sudo systemctl daemon-reload
   104  $ sudo systemctl restart docker
   105  ```
   106  
   107  Verify that the configuration has been loaded:
   108  
   109  ```bash
   110  $ systemctl show --property=Environment docker
   111  Environment=HTTP_PROXY=http://proxy-server.example:80/
   112  ```
   113  
   114  **Docker DNS (Optional)**
   115  
   116  Docker build uses `/etc/resolv.conf` for setting up DNS servers for docker image
   117  builds. If you receive `Host not found` errors during docker build steps,
   118  you need to add nameserver entries to the `resolve.conf` file.
   119  
   120  **Note:** (Ubuntu only)
   121  Because `resolv.conf` is automatically generated on Ubuntu, you must
   122  install a configuration utility with this command:
   123  
   124  ```bash
   125    $ sudo apt-get install resolvconf
   126  ```
   127  
   128  Edit `/etc/resolvconf/resolv.conf.d/base` as root and add the DNS servers
   129  for your network.
   130  
   131  **Note:** If you are behind a firewall, you might need to use specific servers
   132  for your network.
   133  
   134  For example, to use Google's public DNS servers:
   135  
   136  ```
   137      nameserver 8.8.8.8
   138      nameserver 8.8.4.4
   139  ```
   140  
   141  Step Three: Clone the Repository
   142  -------------
   143  
   144  **Note:** You must have `git` installed in order to clone the Sawtooth source
   145  code repository. You can find up-to-date installation instructions
   146  at "Getting Started - Installing Git": <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>.
   147  
   148  Open a terminal and run the following commands:
   149  
   150  ```bash
   151     $ cd $HOME
   152     $ mkdir sawtooth
   153     $ cd sawtooth
   154     $ git clone https://github.com/hyperledger/sawtooth-core.git
   155  ```
   156  
   157  Step Four: Build Docker Images
   158  -------------
   159  
   160  The Sawtooth build and test infrastructure requires that the dependencies be built.
   161  These dependencies include the protocol buffers definitions (under the ``protos``
   162  directory) for the target languages and a set of docker images with
   163  the required build and runtime dependencies installed.
   164  
   165  To build all the dependencies for all Sawtooth components, run this command:
   166  
   167    ```bash
   168      $ bin/build_all
   169    ```
   170  
   171  By default, this command builds all the components for all modules and SDKs in
   172  the repository. This is a very slow process. We recommended that you build only
   173  the language dependencies that you need for your development purposes.
   174  
   175  The minimum requirement for running the Sawtooth validator is the Python build:
   176  
   177    ```bash
   178      $ bin/build_all -l python
   179    ```
   180  
   181  **Tip:** If you see `Host not found` errors in the output of `build_all`, see
   182  "Docker DNS (Optional)", above.
   183  
   184  To get details on all the options for the `build_all` script, run:
   185  
   186    ```bash
   187      $ bin/build_all -h
   188    ```
   189  
   190  If you are working on the core validator, only the Python language is
   191  required. If you are working on a particular language SDK, you must
   192  build the language for that SDK as well.
   193  
   194  **Note:** This build environment uses Docker to virtualize the build and
   195  to execute the code in the development directory. This allows you to
   196  build and test the changes made to the local source without installing local
   197  dependencies on your machine.
   198  
   199  If you wish to configure your development machine to do compilation
   200  directly on the host without Docker virtualization, see the dockerfiles in the
   201  `sawtooth-core/docker` directory. For example, the file
   202  `sawtooth-core/docker/sawtooth-dev-python`
   203  describes the configuration and components needed to build
   204  and run the Python components on a system.
   205  
   206  Step Five: Start a Validator Node
   207  -------------
   208  
   209  To run a full validator node from the local source:
   210  
   211  ```bash
   212    $ docker-compose -f docker/compose/sawtooth-local.yaml up
   213  ```
   214  
   215  This command starts a validator with the following components attached to it:
   216    - REST API (available on host port 8008)
   217    - IntKey transaction processor (Python implementation)
   218    - Settings transaction processor
   219    - XO transaction processor (Python implementation)
   220    - Shell (for running Sawtooth commands)
   221  
   222  From another console window, you can access the shell with this command:
   223  
   224  ```bash
   225    $ docker-compose -f docker/compose/sawtooth-local.yaml exec client bash
   226  ```
   227  
   228  This command uses Docker Compose and the development Docker images. These
   229  images have the runtime dependencies installed, but run Sawtooth
   230  from the source in your workspace. You can inspect
   231  `docker/compose/sawtooth-local.yaml` to see how the various components are
   232  launched and connected.
   233  
   234  Step Six: Run Automated Tests
   235  -------------
   236  
   237  **Note:** The automated tests rely on Docker to ensure reproducibility.
   238  You must have Docker images that were built with the `build_all` command,
   239  as described above.
   240  
   241  To run the automated tests for Python components, while excluding
   242  Java, JavaScript, Go, and Rust components:
   243  
   244  ```bash
   245    $ bin/run_tests -x java_sdk -x javascript_sdk -x go_sdk -x rust_sdk
   246  ```
   247  
   248  **Note:** The `run_tests` command provides the ``-x`` flag to allow you to exclude
   249  various components from the tests. You can also specify which tests to run
   250  with the ``-m`` flag. Run the command `run_tests -h` for help.