Fixes #13620
- Rename Mac OSX to MacOS, rename option from ‘x’ to ’m’
- Fix a bug from https://github.com/bitcoin/bitcoin/blob/b641f60425674d737d77abd8c49929d953ea4154/contrib/gitian-build.sh#L338-L342
Fixes #13620
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
As gitian-build.sh
is mostly calling other executables, I think bash/sh
is still the most sensible/readable/least-dependencies choice. According to #13620 there are edge cases to fix, sure, but I’m not convinced that there’s a need for a python rewrite.
Static analysis tools run against shell scripts in the check pipeline can eliminate/mitigate edge cases. I’d recommend: https://github.com/koalaman/shellcheck
As gitian-build.sh is mostly calling other executables, I think bash/sh is still the most sensible/readable/least-dependencies choice.
The point is that most of the developers in this project have a much easier time reviewing and maintaining python code. Shell script has turned out to be a continuous struggle against shell differences, bad performance, bugs and other edge cases due to obscure quoting practices, and so on.
You might disagree personally–obviously everything is possible with shell script as well, but porting this to python is more of a social consensus. (as for dependencies, I don’t think that is a big thing here, Python 3 is already required to build the project and this requires no external modules)
125+ parser.add_argument('-m', '--memory', dest='memory', default=2000, help='Memory to allocate in MiB. Default %(default)s')
126+ parser.add_argument('-k', '--kvm', action='store_true', dest='kvm', help='Use KVM instead of LXC')
127+ parser.add_argument('-S', '--setup', action='store_true', dest='setup', help='Set up the Gitian building environment. Uses LXC. If you want to use KVM, use the --kvm option. Only works on Debian-based systems (Ubuntu, Debian)')
128+ parser.add_argument('-d', '--detach-sign', action='store_true', dest='detach_sign', help='Create the assert file for detached signing. Will not commit anything.')
129+ parser.add_argument('-n', '--no-commit', action='store_false', dest='commit_files', help='Do not commit anything to git')
130+ parser.add_argument('signer', help='GPG signer to sign each build assert file')
type
argument with a custom callable (saves a few lines)
161+ if args.version == '':
162+ print(script_name+': Missing version.')
163+ print('Try '+script_name+' --help for more information')
164+ exit(1)
165+
166+ # Add leading 'v' for tags
vmaster
because I didn’t have the --commit
option.
168+ print(args.commit)
169+
170+ if args.setup:
171+ setup()
172+
173+ os.chdir('bitcoin')
173+ os.chdir('bitcoin')
174+ subprocess.check_call(['git', 'fetch'])
175+ subprocess.check_call(['git', 'checkout', args.commit])
176+ os.chdir(workdir)
177+
178+ if args.build:
Using a67812d if I pass --setup
and already have one of the required repos cloned I see:
0Processing triggers for ureadahead (0.100.0-20) ...
1Processing triggers for ufw (0.35-5) ...
2fatal: destination path 'gitian.sigs' already exists and is not an empty directory.
3Traceback (most recent call last):
4 File "./gitian-build.py", line 188, in <module>
5 main()
6 File "./gitian-build.py", line 171, in main
7 setup()
8 File "./gitian-build.py", line 16, in setup
9 subprocess.check_call(['git', 'clone', 'https://github.com/bitcoin-core/gitian.sigs.git'])
10 File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
11 raise CalledProcessError(retcode, cmd)
12subprocess.CalledProcessError: Command '['git', 'clone', 'https://github.com/bitcoin-core/gitian.sigs.git']' returned non-zero exit status 128.
13ubuntu@ubuntu:~$ ls
Removed the repos and re-ran with --setup
:
0| E |
1+----[SHA256]-----+
2sudo: debootstrap: command not found
3Traceback (most recent call last):
4 File "./gitian-build.py", line 188, in <module>
5 main()
6 File "./gitian-build.py", line 171, in main
7 setup()
8 File "./gitian-build.py", line 23, in setup
9 subprocess.check_call(make_image_prog)
10 File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
11 raise CalledProcessError(retcode, cmd)
12subprocess.CalledProcessError: Command '['bin/make-base-vm', '--suite', 'trusty', '--arch', 'amd64', '--lxc']' returned non-zero exit status 1.
--setup --kvm
0invoke-rc.d: policy-rc.d denied execution of restart.
1
2Configuration file '/etc/sudoers'
3 ==> Modified (by you or by a script) since installation.
4 ==> Package distributor has shipped an updated version.
5 What would you like to do about it ? Your options are:
6 Y or I : install the package maintainer's version
7 N or O : keep your currently-installed version
8 D : show the differences between the versions
9 Z : start a shell to examine the situation
10 The default action is to keep your current version.
11*** sudoers (Y/I/N/O/D/Z) [default=N] ? dpkg: error processing package sudo (--configure):
12 EOF on stdin at conffile prompt
13invoke-rc.d: policy-rc.d denied execution of restart.
14Errors were encountered while processing:
15 sudo
16E: Sub-process /usr/bin/dpkg returned an error code (1)
17
18Traceback (most recent call last):
19 File "./gitian-build.py", line 188, in <module>
20 main()
21 File "./gitian-build.py", line 171, in main
22 setup()
23 File "./gitian-build.py", line 23, in setup
24 subprocess.check_call(make_image_prog)
25 File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
26 raise CalledProcessError(retcode, cmd)
27subprocess.CalledProcessError: Command '['bin/make-base-vm', '--suite', 'trusty', '--arch', 'amd64']' returned non-zero exit status 1.
This is great, especially not having to worry about the exact sequence of arguments (the bash script had some quirks).
I’m trying to sign master
on a Bionic VM (haven’t tried a Debian 9 host).
0# git clone bitcoin, gitian.sigs, etc
1cp bitcoin/contrib/gitian-build.py .
2# add MacOS stuff
3python3 gitian-build.py --setup sjors -c master
4python3 gitian-build.py --detach-sign --no-commit -b sjors -c master
This throws an error for me, see #13623. The original bash script also throws that error, so probably not related. Just means I can’t test the rest of the process on this VM.
When running --setup --docker
it throws an error:
0ERRO[0000] failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: permission denied
docker ps
also throws a permission error; sudo docker ps
works. sudo usermod -aG docker $USER
solves the problem. It creates an image base-bionic-amd64
.
Trying to build with Docker complains:
0Compiling master Linux
1--- Building for bionic amd64 ---
2Stopping target if it is up
3Making a new image copy
4Error: No such container: gitian-target
The bash script throws the same complaint, so that’s not related.
When running gitian-build.py without arguments, it should probably just return --help
(or otherwise point out that this exists).
Is there a corresponding PR to update the instructions? (mostly just renaming .sh
to .py
)
Can you add make
to the dependencies installed during --setup
?
For another PR: having a config flag to get a Trusty base image can be useful when building backports.
Compiling master Linux — Building for bionic amd64 — Stopping target if it is up Making a new image copy Error: No such container: gitian-target
I believe the docker problem is already exist on gitian-build.sh because I saw the same error trying to use gitian-build.sh to create docker image.
Can you add make to the dependencies installed during –setup?
Why?
Correct, it happens both with bash and python.
Without “make” setup throws an error on a fresh Bionic machine (unless you install all dependencies recommended in the docs, which is overkill).