|
| 1 | +--- |
| 2 | +title: Building from source |
| 3 | +sidebar_position: 0 |
| 4 | +--- |
| 5 | + |
| 6 | +The Nethermind's source code can be obtained from [our repository](https://github.com/NethermindEth/nethermind) on |
| 7 | +GitHub: |
| 8 | + |
| 9 | +```bash |
| 10 | +git clone --recursive https://github.com/nethermindeth/nethermind.git |
| 11 | +``` |
| 12 | + |
| 13 | +There are two options building Nethermind from source code: |
| 14 | + |
| 15 | +- [Standalone binaries](#building-standalone-binaries) |
| 16 | +- [Docker image](#building-docker-image) |
| 17 | + |
| 18 | +:::tip |
| 19 | +For reproducible builds, the following conditions must be met: |
| 20 | + |
| 21 | +- Environment variable `CI` must be set to `true`. |
| 22 | +- Environment variable [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/docs/source-date-epoch/) must be set to the same Unix epoch for each build. |
| 23 | +- The `SourceRevisionId` MSBuild property must be set to the same Git commit hash for each build. This is handled automatically if the `.git` directory is available in the project root. |
| 24 | + |
| 25 | +::: |
| 26 | + |
| 27 | +## Building standalone binaries |
| 28 | + |
| 29 | +### Prerequisites |
| 30 | + |
| 31 | +To build Nethermind from source, install [.NET SDK](https://aka.ms/dotnet/download) 10 or later. |
| 32 | + |
| 33 | +### Building |
| 34 | + |
| 35 | +To build both the client and tests, run the following command from the project's root directory: |
| 36 | + |
| 37 | +```bash |
| 38 | +dotnet build src/Nethermind/Nethermind.slnx -c release |
| 39 | +``` |
| 40 | + |
| 41 | +To simply run the client with a specific configuration without building tests, see below. |
| 42 | + |
| 43 | +:::info |
| 44 | +Before running the client or tests, ensure the |
| 45 | +platform-specific [prerequisites](../get-started/installing-nethermind#prerequisites) are met. |
| 46 | +::: |
| 47 | + |
| 48 | +#### Running |
| 49 | + |
| 50 | +Nethermind can be launched immediately without compiling explicitly (thus, the previous step can be skipped). The following command builds Nethermind if needed and runs it: |
| 51 | + |
| 52 | +```bash |
| 53 | +cd src/Nethermind/Nethermind.Runner |
| 54 | +dotnet run -c release -- -c mainnet |
| 55 | +``` |
| 56 | + |
| 57 | +All Nethermind-specific parameters can be specified after `--`. For instance, the command above specifies the Mainnet |
| 58 | +configuration only. |
| 59 | + |
| 60 | +The build artifacts can be found in the `src/Nethermind/artifacts/bin/Nethermind.Runner/release` directory. By default, the logs and database directories are located here as well. |
| 61 | + |
| 62 | +For more info, see [Running a node](../get-started/running-node/running-node.md). |
| 63 | + |
| 64 | +#### Testing |
| 65 | + |
| 66 | +There are two test suites — Nethermind and Ethereum Foundation. Tests can be run with the following commands (the |
| 67 | +initial step of the build is not required): |
| 68 | + |
| 69 | +```bash |
| 70 | +cd src/Nethermind |
| 71 | + |
| 72 | +# Run Nethermind tests |
| 73 | +dotnet test --solution Nethermind.slnx -c release |
| 74 | + |
| 75 | +# Run Ethereum Foundation tests |
| 76 | +dotnet test --solution EthereumTests.slnx -c release |
| 77 | +``` |
| 78 | + |
| 79 | +## Building Docker image |
| 80 | + |
| 81 | +:::tip |
| 82 | +Building a Nethermind Docker image does not require cloning the Nethermind source code since Docker can build it directly from the repository. For more information, see the [Docker Docs](https://docs.docker.com/build/concepts/context/#remote-context). |
| 83 | +::: |
| 84 | + |
| 85 | +Currently, there are three Docker images available in the project's root directory: |
| 86 | + |
| 87 | +- `Dockerfile`: the default Nethermind Docker image. |
| 88 | +- `Dockerfile.chiseled`: the rootless and [chiseled](https://ubuntu.com/engage/chiselled-ubuntu-images-for-containers) version of the Nethermind Docker image. |
| 89 | +- `Dockerfile.diag`: an image with pre-installed .NET diagnostics and tracing tools. This image is intended for internal use and is not distributed via public channels. |
| 90 | + |
| 91 | +All Docker images have the following optional arguments: |
| 92 | + |
| 93 | +- `BUILD_CONFIG`: the build configuration that is either `release` or `debug`. Defaults to `release`. |
| 94 | +- `CI`: this is mostly used for CI builds determining whether the build is deterministic. Must be either `true` or `false`. Defaults to `true`. |
| 95 | +- `COMMIT_HASH`: the Git commit hash to use as a part of the version string. |
| 96 | +- `SOURCE_DATE_EPOCH`: the build time as a Unix timestamp. Defaults to the current time. |
| 97 | + |
| 98 | +Given the above, the following command builds the Nethermind chiseled Docker image from the project's root directory: |
| 99 | + |
| 100 | +```bash |
| 101 | +docker build . \ |
| 102 | + -f Dockerfile.chiseled \ |
| 103 | + -t nethermind-chiseled \ |
| 104 | + --build-arg COMMIT_HASH=$(git rev-parse HEAD) \ |
| 105 | + --build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) |
| 106 | +``` |
| 107 | + |
| 108 | +For quick testing images, the above arguments can be omitted if not needed: |
| 109 | + |
| 110 | +```bash |
| 111 | +docker build . -t nethermind |
| 112 | +``` |
| 113 | + |
| 114 | +An even faster approach is to build the image directly from the repository. The following command builds the version 1.27.0: |
| 115 | + |
| 116 | +```bash |
| 117 | +docker build "https://github.com/nethermindeth/nethermind.git#1.27.0" -t nethermind |
| 118 | +``` |
| 119 | + |
| 120 | +The above optional arguments can be specified as well if needed. |
| 121 | + |
| 122 | +For more info about running Docker containers, |
| 123 | +see [Installing Nethermind](../get-started/installing-nethermind#docker-container). |
0 commit comments