Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap GnuPG #24003

Merged
merged 10 commits into from Nov 3, 2021
Merged

Conversation

alalazo
Copy link
Member

@alalazo alalazo commented May 28, 2021

depends on #22720
depends on #23889

Modifications:

  • Bootstrap GnuPG from binaries if not found in the PATH
  • If can't use binaries, bootstrap GnuPG from sources

@alalazo alalazo added the bootstrap Anything that has to do with Spack building its own dependencies. label May 28, 2021
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 5de002b to cc52c74 Compare June 1, 2021 18:39
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from cc52c74 to 4ece090 Compare August 6, 2021 12:10
@alalazo alalazo marked this pull request as ready for review August 6, 2021 13:57
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 14d38f2 to 45a8843 Compare August 18, 2021 20:41
@alalazo alalazo added this to In progress in Spack 0.17.0 Release via automation Aug 19, 2021
Comment on lines 52 to 54
monkeypatch.setattr(
spack.bootstrap, 'ensure_gpg_in_path_or_raise', lambda: None
)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to check this by "untrusting" all the bootstrapping methods? That way we're actually checking the proper behavior if gpg isn't available, rather than testing what happens if bootstrapping fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

See 019ca56

Comment on lines +657 to +781
def ensure_gpg_in_path_or_raise():
"""Ensure gpg or gpg2 are in the PATH or raise."""
ensure_executables_in_path_or_raise(
executables=['gpg2', 'gpg'], abstract_spec=gnupg_root_spec(),
)
Copy link
Member

Choose a reason for hiding this comment

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

We should think about whether this is sustainable to have a method here for each calling site, or whether these methods should be pushed into the callers.

Copy link
Member Author

@alalazo alalazo Aug 20, 2021

Choose a reason for hiding this comment

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

My take on it is the following:

  1. The wrapper function may be pushed on the caller (it's indeed just a convenience to fix parameters in one place)
  2. I think gnupg_root_spec and similar should stay here so that we can collect in the spack.bootstrap module all the specs we may need on bootstrapping

Copy link
Member

Choose a reason for hiding this comment

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

gnupg_root_spec and clingo_root_spec are identical methods, besides the spec string. I think we should have a method get_bootstrap_spec that takes an abstract spec or abstract spec string as an argument. Then the calling site can keep the information that belongs to it ("I need gpg@1.1:" or whatever it is) and call into bootstrap only to turn that abstract information into a bootstrappable spec.

Copy link
Member Author

Choose a reason for hiding this comment

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

See d2a41f7 I factored together adding a compiler and a target, but I still think it's good to keep in bootstrap.py the wrapping functions, like:

def clingo_root_spec():
    """Return the root spec used to bootstrap clingo"""
    return _root_spec('clingo-bootstrap@spack+python')

The rationale is that the root spec for e.g. clingo should stay consistent across Spack if /when needed in multiple places in the code. So having a function here that returns it seems good to keep the information in a single place.

lib/spack/spack/bootstrap.py Outdated Show resolved Hide resolved
@@ -325,6 +447,44 @@ def ensure_module_importable_or_raise(module, abstract_spec=None):
raise ImportError(msg)


def ensure_executables_in_path_or_raise(executables, abstract_spec):
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a default argument as it is for modules?

Copy link
Member Author

Choose a reason for hiding this comment

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

The API is slightly different, since executables accepts a list. As it stands I don't think it needs a default value, but maybe we can revisit this post v0.17.0? If after the release we'll add more dependencies to the bootstrap procedure we may have more data to make the API more consistent.

lib/spack/spack/bootstrap.py Outdated Show resolved Hide resolved
Comment on lines 102 to 188
def _executables_in_path(executables):
"""Return True if at least one of the executables is in PATH,
False otherwise.
"""
msg = "[BOOTSTRAP EXECUTABLES {0}] Look if the executables are in the path"
executables_str = ', '.join(executables)
tty.debug(msg.format(executables_str))
found = spack.util.executable.which_string(*executables)
if found:
msg = "[BOOTSTRAP EXECUTABLES {0}] {1} executable found in PATH"
tty.debug(msg.format(executables_str, found))
return True
return False
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this method just be replaced with bool(spack.util.executable.which_string(*executables)? I think we're getting a little overly verbose, even for debug mode with some of this.

Copy link
Member Author

Choose a reason for hiding this comment

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

See dee4605

Comment on lines 137 to 216
current_path = os.environ['PATH']

os.environ['PATH'] = ':'.join([bin_dir, current_path])
if _executables_in_path(executables):
return True
os.environ['PATH'] = current_path
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
current_path = os.environ['PATH']
os.environ['PATH'] = ':'.join([bin_dir, current_path])
if _executables_in_path(executables):
return True
os.environ['PATH'] = current_path
if spack.util.executable.which_string(*executables, path=bin_dir):
spack.util.environment.path_put_first('PATH', [bin_dir])
return True

Copy link
Member Author

Choose a reason for hiding this comment

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

See dee4605

lib/spack/spack/bootstrap.py Outdated Show resolved Hide resolved
with spack.config.override(self.mirror_scope):
# This index is currently needed to get the compiler used to build some
# specs that wwe know by dag hash.
spack.binary_distribution.binary_index.regenerate_spec_cache()
Copy link
Member

Choose a reason for hiding this comment

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

We probably need something more robust for this -- do we need to regenerate the spec cache when we're done and switching back to the normal mirro configurations?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need to regenerate it, but might be wrong. In any case this method didn't change in this PR. It's what we currently use to bootstrap clingo. Can we postpone making it more robust to a later PR, if there are no major concerns about that?

lib/spack/spack/bootstrap.py Outdated Show resolved Hide resolved
Spack 0.17.0 Release automation moved this from In progress to Review in progress Aug 20, 2021
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch 2 times, most recently from 344a800 to 2780c74 Compare September 16, 2021 14:59
@spackbot-app spackbot-app bot added the modules label Sep 16, 2021
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 2780c74 to 244a307 Compare September 16, 2021 15:03
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 244a307 to 9f202b1 Compare October 26, 2021 15:05
@alalazo
Copy link
Member Author

alalazo commented Oct 26, 2021

@becker33 Can you review again? I think most points have been addressed (and hopefully the PR will pass unit tests, which are currently still pending).

@tgamblin
Copy link
Member

@alalazo coverage is still pretty low -- is that avoidable?

@alalazo
Copy link
Member Author

alalazo commented Oct 28, 2021

coverage is still pretty low -- is that avoidable?

Adding unit tests for this was difficult, so I resorted to e2e tests which are not run with coverage. The one added in this PR is:

ubuntu-gnupg-binaries:
runs-on: ubuntu-latest
container: "ubuntu:latest"
steps:
- name: Install dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
apt-get update -y && apt-get upgrade -y
apt-get install -y \
bzip2 curl file g++ gcc patchelf gfortran git gzip \
make patch unzip xz-utils python3 python3-dev tree
- uses: actions/checkout@v2
- name: Setup repo and non-root user
run: |
git --version
git fetch --unshallow
. .github/workflows/setup_git.sh
useradd -m spack-test
chown -R spack-test .
- name: Bootstrap GnuPG
shell: runuser -u spack-test -- bash {0}
run: |
source share/spack/setup-env.sh
spack bootstrap untrust spack-install
spack -d gpg list
tree ~/.spack/bootstrap/store/

I didn't add a macOS tests for binaries since gpg is installed in the base macOS image, but I can try to remove that and see if I can push a working e2e test. Also, I didn't add an e2e test to check building from sources since it takes a while to do so - but let me know if you want to add that.

@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 019ca56 to 64fcba2 Compare October 28, 2021 08:08
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from e7c0921 to 9274573 Compare October 28, 2021 08:53
@alalazo alalazo force-pushed the features/add_gnupg_to_bootstrap branch from 73db1b4 to 20279d7 Compare October 28, 2021 09:46
@alalazo
Copy link
Member Author

alalazo commented Oct 28, 2021

@tgamblin Added more e2e tests see 9274573 and 20279d7

@alalazo alalazo requested a review from becker33 October 28, 2021 11:55
@becker33 becker33 merged commit 78c08fc into spack:develop Nov 3, 2021
Spack 0.17.0 Release automation moved this from Review in progress to Done Nov 3, 2021
@alalazo alalazo deleted the features/add_gnupg_to_bootstrap branch November 3, 2021 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary-packages bootstrap Anything that has to do with Spack building its own dependencies. commands defaults documentation modules sbang tests General test capability(ies) utilities workflow
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants