Skip to content

Conversation

@ken2812221
Copy link
Contributor

@ken2812221 ken2812221 commented Jul 10, 2018

Fixes #13620

  • Rename Mac OSX to MacOS, rename option from 'x' to 'm'
  • Fix a bug from
    # Signed Windows
    echo ""
    echo "Verifying v${VERSION} Signed Windows"
    echo ""
    ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml

@laanwj
Copy link
Member

laanwj commented Jul 10, 2018

Thanks // Concept ACK, code looks good to me at first glance but ofcourse needs manual testing (as it's not tested by the test framework).

@maflcko
Copy link
Member

maflcko commented Jul 10, 2018

Could remove the bash script in the same commit?

@ken2812221 ken2812221 changed the title [WIP] Migrate gitian-build.sh to python Migrate gitian-build.sh to python Jul 10, 2018
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 10, 2018

Note to reviewers: This pull request conflicts with the following ones:

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.

@jtimon
Copy link
Contributor

jtimon commented Jul 10, 2018

Concept ACK

@dongcarl
Copy link
Contributor

dongcarl commented Jul 10, 2018

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

@laanwj laanwj mentioned this pull request Jul 11, 2018
@laanwj
Copy link
Member

laanwj commented Jul 11, 2018

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)

@maflcko
Copy link
Member

maflcko commented Jul 11, 2018

Also, the resulting python script is a lot shorter. Means less code weight to maintain in the future :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add the parameter nargs=1 to make signer and version mandatory and skip lines 155-162. It will produce a list of one item. See https://docs.python.org/3/library/argparse.html#nargs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary since signer and version are positional arguments so if they aren't provided then an error will always be thrown. The checks later are still necessary since you can still pass in the empty string as an argument regardless of nargs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I missed the point of the checks. Still if we want to guard against empty string we can use the type argument with a custom callable (saves a few lines)

@ken2812221
Copy link
Contributor Author

Update: exit 1 if signer or version is empty.

Copy link
Contributor

@jb55 jb55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only tested some of the basic ergonomics since I don't have the gitian builder set up on my machine yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this option necessary? if there's a v you could just include it in the argument. I found this confusing when I ran the command, it was trying to checkout vmaster because I didn't have the --commit option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version without 'v' prefix is still used in gsign.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assumes you would be running the command from outside the bitcoin directory. is this correct? I found I had to cd .. and then run ./bitcoin/contrib/gitian-builder.py to make the command work?

Copy link
Contributor Author

@ken2812221 ken2812221 Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the instruction from https://github.com/bitcoin-core/docs/blob/master/gitian-building.md , you should copy the script to the same level as bitcoin folder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could default to build? or at least throw an error when all three are not selected?

@fanquake
Copy link
Member

fanquake commented Jul 13, 2018

Using a67812d if I pass --setup and already have one of the required repos cloned I see:

Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for ufw (0.35-5) ...
fatal: destination path 'gitian.sigs' already exists and is not an empty directory.
Traceback (most recent call last):
  File "./gitian-build.py", line 188, in <module>
    main()
  File "./gitian-build.py", line 171, in main
    setup()
  File "./gitian-build.py", line 16, in setup
    subprocess.check_call(['git', 'clone', 'https://github.com/bitcoin-core/gitian.sigs.git'])
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'clone', 'https://github.com/bitcoin-core/gitian.sigs.git']' returned non-zero exit status 128.
ubuntu@ubuntu:~$ ls

Removed the repos and re-ran with --setup:

|               E |
+----[SHA256]-----+
sudo: debootstrap: command not found
Traceback (most recent call last):
  File "./gitian-build.py", line 188, in <module>
    main()
  File "./gitian-build.py", line 171, in main
    setup()
  File "./gitian-build.py", line 23, in setup
    subprocess.check_call(make_image_prog)
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['bin/make-base-vm', '--suite', 'trusty', '--arch', 'amd64', '--lxc']' returned non-zero exit status 1.

--setup --kvm

invoke-rc.d: policy-rc.d denied execution of restart.

Configuration file '/etc/sudoers'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** sudoers (Y/I/N/O/D/Z) [default=N] ? dpkg: error processing package sudo (--configure):
 EOF on stdin at conffile prompt
invoke-rc.d: policy-rc.d denied execution of restart.
Errors were encountered while processing:
 sudo
E: Sub-process /usr/bin/dpkg returned an error code (1)

Traceback (most recent call last):
  File "./gitian-build.py", line 188, in <module>
    main()
  File "./gitian-build.py", line 171, in main
    setup()
  File "./gitian-build.py", line 23, in setup
    subprocess.check_call(make_image_prog)
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['bin/make-base-vm', '--suite', 'trusty', '--arch', 'amd64']' returned non-zero exit status 1.

@ken2812221
Copy link
Contributor Author

I don't know how to deal with KVM errors since I haven't used KVM ever, I just follow the same command with the original script. Can anyone give a hint?

@fanquake
Copy link
Member

@ken2812221 Now that #13368 has been merged, can you update the new Python script to add Docker support. I will retest the changes here shortly.

@DrahtBot
Copy link
Contributor

Needs rebase

@Sjors
Copy link
Member

Sjors commented Jul 17, 2018

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).

# git clone bitcoin, gitian.sigs, etc
cp bitcoin/contrib/gitian-build.py .
# add MacOS stuff 
python3 gitian-build.py --setup sjors -c master
python3 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:

ERRO[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:

Compiling master Linux
--- Building for bionic amd64 ---
Stopping target if it is up
Making a new image copy
Error: 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.

@ken2812221
Copy link
Contributor Author

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?

@Sjors
Copy link
Member

Sjors commented Jul 17, 2018

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).

@maflcko
Copy link
Member

maflcko commented Jul 17, 2018

utACK 78f06e4

@maflcko maflcko merged commit 78f06e4 into bitcoin:master Jul 17, 2018
maflcko pushed a commit that referenced this pull request Jul 17, 2018
78f06e4 Migrate gitian-build.sh to python (Chun Kuan Lee)

Pull request description:

  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

Tree-SHA512: ff943055d5feca345bd17b64311374db3937d14d2f21493116fd7ab7b4cb7042480abd6a3d1d7640073b00bc0badb300e8dd32618bf73ba182df417c0633397a
@ken2812221 ken2812221 deleted the python-gitian-build branch July 17, 2018 18:04
@Sjors
Copy link
Member

Sjors commented Jul 17, 2018

On Debian 9, when trying to --setup with --docker, I'm getting Package 'docker.io' has no installation candidate.

So I installed Docker manually, but get the same error. Disabling programs += ['docker.io'] does the trick.

hebasto added a commit to hebasto/bitcoin that referenced this pull request Aug 19, 2018
UdjinM6 pushed a commit to dashpay/dash that referenced this pull request Oct 21, 2018
* backport python version of gitian-build from bitcoin

rename gitian-build script

fix release notes typo

0.12.3-backports

* change gitian host IP address

* docker/etc fixes

* use docker as default virtualization tech

* add checksum to depends download stage

* add SDK download

checksum added

* remove SDK check

* fix verification
maflcko pushed a commit that referenced this pull request May 20, 2019
…rections

0f22a0c Fix gitian-build.py --verify option (Hennadii Stepanov)
4c56a79 Set/unset USE_LXC, USE_VBOX, USE_DOCKER explicitly (Hennadii Stepanov)
cbbd988 Fix Docker related issues for gitian-build.py (Hennadii Stepanov)

Pull request description:

  1. The Docker does not depend on `apt-cacher-ng` package. Ref: #14002.

  2. Do not try to install the Docker if `docker.service` is detected on the system (e.g., the Docker was installed manually). Fix #13623 (comment) by **Sjors**.

  3. Prevent the setting of more than one environment variable for the `gitian-builder` (an alternative to #13999). E.g., USE_LXC being set shadows USE_DOCKER; for details see [`gitian-builder/libexec/make-clean-vm`](https://github.com/devrandom/gitian-builder/blob/93a62c7d7d018c66c02a19bac3d751144043cfec/libexec/make-clean-vm#L7):
  ```sh
  VMSW=KVM
  if [ -n "$USE_LXC" ]; then
      VMSW=LXC
  elif [ -n "$USE_VBOX" ]; then
      VMSW=VBOX
  elif [ -n "$USE_DOCKER" ]; then
      VMSW=DOCKER
  fi
  ```
  4. The [`gitian-builder/bin/gverify`](https://github.com/devrandom/gitian-builder/blob/master/bin/gverify) script returns the exit code 1 if a signature verification ends with 'BAD SIGNATURE' or 'MISMATCH' by design. This PR allows to see the verification results for all signatures without a premature fail of the `gitian-build.py` script. Ref: #14014.

ACKs for commit 0f22a0:

Tree-SHA512: 55f8a5cffa20d0c745f51a687f3199cea015fa616e56a0aee4c25b5ca0985036c61e8cf1922515338d8c6a85f873674ebe7a9a56a5069d65a187e383150f1a83
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 20, 2019
…and corrections

0f22a0c Fix gitian-build.py --verify option (Hennadii Stepanov)
4c56a79 Set/unset USE_LXC, USE_VBOX, USE_DOCKER explicitly (Hennadii Stepanov)
cbbd988 Fix Docker related issues for gitian-build.py (Hennadii Stepanov)

Pull request description:

  1. The Docker does not depend on `apt-cacher-ng` package. Ref: bitcoin#14002.

  2. Do not try to install the Docker if `docker.service` is detected on the system (e.g., the Docker was installed manually). Fix bitcoin#13623 (comment) by **Sjors**.

  3. Prevent the setting of more than one environment variable for the `gitian-builder` (an alternative to bitcoin#13999). E.g., USE_LXC being set shadows USE_DOCKER; for details see [`gitian-builder/libexec/make-clean-vm`](https://github.com/devrandom/gitian-builder/blob/93a62c7d7d018c66c02a19bac3d751144043cfec/libexec/make-clean-vm#L7):
  ```sh
  VMSW=KVM
  if [ -n "$USE_LXC" ]; then
      VMSW=LXC
  elif [ -n "$USE_VBOX" ]; then
      VMSW=VBOX
  elif [ -n "$USE_DOCKER" ]; then
      VMSW=DOCKER
  fi
  ```
  4. The [`gitian-builder/bin/gverify`](https://github.com/devrandom/gitian-builder/blob/master/bin/gverify) script returns the exit code 1 if a signature verification ends with 'BAD SIGNATURE' or 'MISMATCH' by design. This PR allows to see the verification results for all signatures without a premature fail of the `gitian-build.py` script. Ref: bitcoin#14014.

ACKs for commit 0f22a0:

Tree-SHA512: 55f8a5cffa20d0c745f51a687f3199cea015fa616e56a0aee4c25b5ca0985036c61e8cf1922515338d8c6a85f873674ebe7a9a56a5069d65a187e383150f1a83
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request May 21, 2019
* backport python version of gitian-build from bitcoin

rename gitian-build script

fix release notes typo

0.12.3-backports

* change gitian host IP address

* docker/etc fixes

* use docker as default virtualization tech

* add checksum to depends download stage

* add SDK download

checksum added

* remove SDK check

* fix verification
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request May 4, 2021
…hpay#2319)

* backport python version of gitian-build from bitcoin

rename gitian-build script

fix release notes typo

0.12.3-backports

* change gitian host IP address

* docker/etc fixes

* use docker as default virtualization tech

* add checksum to depends download stage

* add SDK download

checksum added

* remove SDK check

* fix verification
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request May 4, 2021
Backport bitcoin bitcoin#13623 Migrate gitian-build.sh to python (dashpay#2319)
* backport python version of gitian-build from bitcoin
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Sep 2, 2021
…and corrections

0f22a0c Fix gitian-build.py --verify option (Hennadii Stepanov)
4c56a79 Set/unset USE_LXC, USE_VBOX, USE_DOCKER explicitly (Hennadii Stepanov)
cbbd988 Fix Docker related issues for gitian-build.py (Hennadii Stepanov)

Pull request description:

  1. The Docker does not depend on `apt-cacher-ng` package. Ref: bitcoin#14002.

  2. Do not try to install the Docker if `docker.service` is detected on the system (e.g., the Docker was installed manually). Fix bitcoin#13623 (comment) by **Sjors**.

  3. Prevent the setting of more than one environment variable for the `gitian-builder` (an alternative to bitcoin#13999). E.g., USE_LXC being set shadows USE_DOCKER; for details see [`gitian-builder/libexec/make-clean-vm`](https://github.com/devrandom/gitian-builder/blob/93a62c7d7d018c66c02a19bac3d751144043cfec/libexec/make-clean-vm#L7):
  ```sh
  VMSW=KVM
  if [ -n "$USE_LXC" ]; then
      VMSW=LXC
  elif [ -n "$USE_VBOX" ]; then
      VMSW=VBOX
  elif [ -n "$USE_DOCKER" ]; then
      VMSW=DOCKER
  fi
  ```
  4. The [`gitian-builder/bin/gverify`](https://github.com/devrandom/gitian-builder/blob/master/bin/gverify) script returns the exit code 1 if a signature verification ends with 'BAD SIGNATURE' or 'MISMATCH' by design. This PR allows to see the verification results for all signatures without a premature fail of the `gitian-build.py` script. Ref: bitcoin#14014.

ACKs for commit 0f22a0:

Tree-SHA512: 55f8a5cffa20d0c745f51a687f3199cea015fa616e56a0aee4c25b5ca0985036c61e8cf1922515338d8c6a85f873674ebe7a9a56a5069d65a187e383150f1a83
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite gitian-build.sh in Python