Debian Codegraph @

contrib/gitian/README.md

raw symbols SCIP
1 Gitian building
2 ================
3
4 *Setup instructions for a Gitian build of Monero.*
5
6 Gitian is the deterministic build process that is used to build the Monero CLI
7 executables. It provides a way to be reasonably sure that the
8 executables are really built from the git source. It also makes sure that
9 the same, tested dependencies are used and statically built into the executable.
10
11 Multiple developers build the source code by following a specific descriptor
12 ("recipe"), cryptographically sign the result, and upload the resulting signature.
13 These results are compared and only if they match, the build is accepted and provided
14 for download.
15
16 Gitian runs compilation steps in an isolated container. It is flexible and gives you full
17 control over the build environment, while still ensuring reproducibility and consistent output
18 formats.
19
20 More independent Gitian builders are needed, which is why this guide exists.
21 It is preferred you follow these steps yourself instead of using someone else's
22 VM image to avoid 'contaminating' the build.
23
24 Preparing the Gitian builder host
25 ---------------------------------
26
27 The first step is to prepare the host environment that will be used to perform the Gitian builds.
28 This guide explains how to set up the environment, and how to start the builds.
29
30 * Gitian host OS should be Ubuntu 18.04 "Bionic Beaver". If you are on a mac or windows for example, you can run it in a VM but will be slower.
31
32 * Gitian gives you the option of using any of 3 different virtualization tools: `kvm`, `docker` or `lxc`. This documentation will only show how to build with `lxc` and `docker` (documentation for `kvm` is welcome). Building with `lxc` is the default, but is more complicated, so we recommend docker your first time.
33
34 * For a shortcut using `docker` follow the instructions in [DOCKRUN.md](DOCKRUN.md) instead
35 of following the rest of this document..
36
37 ## Create the gitianuser account
38
39 You need to create a new user called `gitianuser` and be logged in as that user. The user needs `sudo` access.
40
41 ```bash
42 sudo adduser gitianuser
43 sudo usermod -aG sudo gitianuser
44 ```
45
46 LXC
47 ---
48
49 LXC builds should be run on Ubuntu 18.04 "Bionic Beaver".
50
51 Note that a version of `lxc-execute` higher or equal to 2.1.1 is required.
52 You can check the version with `lxc-execute --version`.
53
54 First we need to set up dependencies. Type/paste the following in the terminal:
55
56 ```bash
57 sudo apt-get install git ruby apt-cacher-ng qemu-utils debootstrap lxc python-cheetah parted kpartx bridge-utils make ubuntu-archive-keyring curl firewalld
58 ```
59
60 Then set up LXC and the rest with the following, which is a complex jumble of settings and workarounds:
61
62 ```bash
63 sudo -s
64 # the version of lxc-start in Debian needs to run as root, so make sure
65 # that the build script can execute it without providing a password
66 echo "%sudo ALL=NOPASSWD: /usr/bin/lxc-start" > /etc/sudoers.d/gitian-lxc
67 echo "%sudo ALL=NOPASSWD: /usr/bin/lxc-execute" >> /etc/sudoers.d/gitian-lxc
68 # make /etc/rc.local script that sets up bridge between guest and host
69 echo '#!/bin/sh -e' > /etc/rc.local
70 echo 'brctl addbr br0' >> /etc/rc.local
71 echo 'ip addr add 10.0.2.2/24 broadcast 10.0.2.255 dev br0' >> /etc/rc.local
72 echo 'ip link set br0 up' >> /etc/rc.local
73 echo 'firewall-cmd --zone=trusted --add-interface=br0' >> /etc/rc.local
74 echo 'exit 0' >> /etc/rc.local
75 chmod +x /etc/rc.local
76 # make sure that USE_LXC is always set when logging in as gitianuser,
77 # and configure LXC IP addresses
78 echo 'export USE_LXC=1' >> /home/gitianuser/.profile
79 echo 'export GITIAN_HOST_IP=10.0.2.2' >> /home/gitianuser/.profile
80 echo 'export LXC_GUEST_IP=10.0.2.5' >> /home/gitianuser/.profile
81 reboot
82 ```
83
84 This setup is required to enable networking in the container.
85
86 Docker
87 ------
88
89 Prepare for building with docker:
90
91 ```bash
92 sudo bash -c 'apt-get update && apt-get upgrade -y && apt-get install git curl docker.io'
93 ```
94
95 Consider adding `gitianuser` to the `docker` group after reading about [the security implications](https://docs.docker.com/v17.09/engine/installation/linux/linux-postinstall/):
96
97 ```bash
98 sudo groupadd docker
99 sudo usermod -aG docker gitianuser
100 ```
101
102 Optionally add yourself to the docker group. Note that this will give docker root access to your system.
103
104 ```bash
105 sudo usermod -aG docker $USER
106 ```
107
108 Manual Building
109 -------------------
110
111 =======
112 The script automatically installs some packages with apt. If you are not running it on a debian-like system, pass `--no-apt` along with the other
113 arguments to it. It calls all available .yml descriptors, which in turn pass the build configurations for different platforms to gitian.
114 The instructions below use the automated script [gitian-build.py](gitian-build.py) which is tested to work on Ubuntu.
115
116 It calls all available .yml descriptors, which in turn pass the build configurations for different platforms to gitian.
117 Help for the build steps taken can be accessed with `./gitian-build.py --help`.
118
119 Initial Gitian Setup
120 --------------------
121
122 The `gitian-build.py` script will checkout different release tags, so it's best to copy it to the top level directory:
123
124 ```bash
125 cp monero/contrib/gitian/gitian-build.py .
126 ```
127
128 ### Setup the required environment
129
130 Common setup part:
131
132 ```bash
133 su - gitianuser
134
135 GH_USER=YOUR_GITHUB_USER_NAME
136 VERSION=v0.18.5.0
137 ```
138
139 Where `GH_USER` is your GitHub user name and `VERSION` is the version tag you want to build.
140 The `gitian-build.py`'s `--setup` switch will also refresh the environment of any stale files and submodules.
141
142 Setup for LXC:
143
144 ```bash
145 ./gitian-build.py --setup $GH_USER $VERSION
146 ```
147
148 Setup for docker:
149
150 ```bash
151 ./gitian-build.py --setup --docker $GH_USER $VERSION
152 ```
153
154 While gitian and this build script does provide a way for you to sign the build directly, it is recommended to sign in a separate step. This script is only there for convenience. Separate steps for building can still be taken.
155 In order to sign gitian builds on your host machine, which has your PGP key,
156 fork the [gitian.sigs repository](https://github.com/monero-project/gitian.sigs) and clone it on your host machine,
157 or pass the signed assert file back to your build machine.
158
159 ```bash
160 git clone https://github.com/monero-project/gitian.sigs/
161 pushd gitian.sigs
162 git remote add $GH_USER https://github.com/$GH_USER/gitian.sigs
163 popd
164 ```
165
166 Build the binaries
167 ------------------
168
169 To build the most recent tag (pass in `--docker` if using docker):
170
171 ```bash
172 ./gitian-build.py --detach-sign --no-commit --build $GH_USER $VERSION
173 ```
174
175 To speed up the build, use `-j 5 --memory 10000` as the first arguments, where `5` is the number of CPU's you allocated to the VM plus one, and 10000 is a little bit less than then the MB's of RAM you allocated. If there is memory corruption on your machine, try to tweak these values. A good rule of thumb is, that Monero currently needs about 2 GB of RAM per core.
176
177 A full example for `docker` would look like the following:
178
179 ```bash
180 ./gitian-build.py -j 5 --memory 10000 --docker --detach-sign --no-commit --build $GH_USER $VERSION
181 ```
182
183 If all went well, this produces a number of (uncommitted) `.assert` files in the gitian.sigs directory.
184
185 Checking your work
186 ------------------
187
188 Take a look in the assert files and note the SHA256 checksums listed there.
189
190 You should verify that the checksum that is listed matches each of the binaries you actually built.
191 This may be done on Linux using the `sha256sum` command or on MacOS using `shasum --algorithm 256` for example.
192 An example script to verify the checksums would be:
193
194 ```bash
195 pushd out/${VERSION}
196
197 for ASSERT in ../../sigs/${VERSION}-*/*/*.assert; do
198 if ! sha256sum --ignore-missing -c "${ASSERT}" ; then
199 echo "FAILED for ${ASSERT} ! Please inspect manually."
200 fi
201 done
202
203 popd
204 ```
205
206 Don't ignore the incorrect formatting of the found assert files. These files you'll have to compare manually (currently OSX and FreeBSD).
207
208
209 You can also look in the [gitian.sigs](https://github.com/monero-project/gitian.sigs/) repo and / or [getmonero.org release checksums](https://web.getmonero.org/downloads/hashes.txt) to see if others got the same checksum for the same version tag. If there is ever a mismatch -- **STOP! Something is wrong**. Contact others on IRC / github to figure out what is going on.
210
211
212 Signing assert files
213 --------------------
214
215 If you chose to do detached signing using `--detach-sign` above (recommended), you need to copy these uncommitted changes to your host machine, then sign them using your gpg key like so:
216
217 ```bash
218 for ASSERT in sigs/${VERSION}-*/*/*.assert; do gpg --detach-sign ${ASSERT}; done
219 ```
220
221 This will create a `.sig` file for each `.assert` file above (2 files for each platform).
222
223
224 Submitting your signed assert files
225 -----------------------------------
226
227 Make a pull request (both the `.assert` and `.assert.sig` files) to the
228 [monero-project/gitian.sigs](https://github.com/monero-project/gitian.sigs/) repository:
229
230 ```bash
231 cd gitian.sigs
232 git checkout -b $VERSION
233 # add your assert and sig files...
234 git commit -S -a -m "Add $GH_USER $VERSION"
235 git push --set-upstream $GH_USER $VERSION
236 ```
237
238 **Note:** Please ensure your gpg public key is available to check signatures by adding it to the [gitian.sigs/gitian-pubkeys/](https://github.com/monero-project/gitian.sigs/tree/master/gitian-pubkeys) directory in a pull request.
239
240
241 More Build Options
242 ------------------
243
244 You can choose your own remote and commit hash by running for example:
245 ```bash
246 ./gitian-build.py --detach-sign --no-commit --url https://github.com/moneromooo-monero/bitmonero -b moneromooo 1f5680c8db8f4cc7acc04a04c724b832003440fd
247 ```
248
249 Note that you won't be able to build commits authored before the gitian scripts
250 were added. Gitian clones the source files from the given url, be sure to push
251 to the remote you provide before building.
252 To get all build options run:
253 ```bash
254 ./gitian-build.py --help
255 ```
256
257 Doing Successive Builds
258 -----------------------
259
260 If you need to do multiple iterations (while developing/testing) you can use the
261 `--rebuild` option instead of `--build` on subsequent iterations. This skips the
262 initial check for the freshness of the depends tools. In particular, doing this
263 check all the time prevents rebuilding when you have no network access.
264
265
266 Local-Only Builds
267 -----------------
268
269 If you need to run builds while disconnected from the internet, make sure you have
270 local up-to-date repos in advance. Then specify your local repo using the `--url`
271 option when building. This will avoid attempts to git pull across a network.
272