Skip to content

Support hermetic builds - #26

Open
DazWorrall wants to merge 6 commits into
masterfrom
daz/hermetic-build-v2
Open

DazWorrall wants to merge 6 commits into
masterfrom
daz/hermetic-build-v2

Conversation

@DazWorrall

Copy link
Copy Markdown
Member

The current build scripts assume network access at build time, but that is not the case in all build environments, particularly nix, which has strict sandboxing.

However with the addition of a few knobs to the build scripts, Yugabyte can be built successfully in a hermetic environment. This PR adds those knobs, and the intention is for a no-op in any existing build environment.

Summary:
common-build-env.sh always clones yugabyte-bash-common from GitHub into
build/yugabyte-bash-common and checks out the commit from
build-support/yugabyte-bash-common-sha1.txt. Build systems that run without
network access (e.g. Nix, Bazel, distro package builders) cannot do that.

If YB_BASH_COMMON_DIR is set, use that directory as is instead. The caller
is responsible for it containing the commit from
yugabyte-bash-common-sha1.txt, e.g. by extracting the GitHub source archive
for that commit. The default behavior is unchanged.

Test Plan:
- ./yb_build.sh release (no change in behavior)
- YB_BASH_COMMON_DIR=<extracted archive of the pinned commit> ./yb_build.sh release
  in a source tree with no build/yugabyte-bash-common and no network access
Summary:
Building from an extracted source archive (no .git directory) fails in two
places:

- check_python_script_syntax uses `git ls-files` to find Python files. Fall
  back to `find` when the source root is not a Git checkout.
- build_postgres.py computes its "build stamp" from `git log` / `git diff`.
  Without Git there is no cheap way to tell whether PostgreSQL is up to date,
  so don't use a build stamp in that case: PostgreSQL is always (re)built and
  no stamp is written.

The Git SHA1 embedded in version metadata can already be provided with the
YB_VERSION_INFO_GIT_SHA1 environment variable.

Test Plan:
- ./yb_build.sh release in a Git checkout: build stamp logic unchanged.
- ./yb_build.sh release in an extracted source archive with
  YB_VERSION_INFO_GIT_SHA1 set.
Summary:
yb_build.sh unconditionally downloads the initial sys catalog snapshots into
/opt/yb-build/ysql-sys-catalog-snapshots. They are only used by tests, and
run-test.sh downloads them on its own, but the download (and creating
/opt/yb-build) makes builds without network access, or without write access
to /opt, fail.

Setting YB_DOWNLOAD_YSQL_SNAPSHOTS=0 now skips it, similar to
YB_DOWNLOAD_THIRDPARTY=0. The default behavior is unchanged.

Test Plan:
- YB_DOWNLOAD_YSQL_SNAPSHOTS=0 ./yb_build.sh release --no-tests
…lenv

Summary:
activate_virtualenv always creates (or reuses) a virtualenv in the build
directory and installs requirements_frozen.txt into it from PyPI, which is
not possible in build environments without network access. Such environments
typically provide the packages themselves (e.g. from Nix or distro packages).

With YB_USE_EXISTING_PYTHON_ENV=1, skip the virtualenv and use python3 from
PATH as is. VIRTUAL_ENV is set to that interpreter's prefix, as a few scripts
run $VIRTUAL_ENV/bin/python. The default behavior is unchanged.

Test Plan:
- YB_USE_EXISTING_PYTHON_ENV=1 ./yb_build.sh release with a Python 3.11 in
  PATH that has the build's requirements installed.
Summary:
build_postgres.py decides whether to pass --enable-nls by looking at the OS
version (via sys_detection, which reads /etc/os-release) and whether msgfmt
is available. Minimal build sandboxes and containers may not have
/etc/os-release, in which case sys_detection raises FileNotFoundError.

Check for msgfmt first, so that the OS version is only looked at when it
matters. The result of the condition is unchanged.

Test Plan:
- ./yb_build.sh release in an environment without /etc/os-release but with
  gettext installed.
Summary:
InitializeSystemInfo CHECK-fails when /sys/devices/system/cpu/present cannot
be read, crashing every YugabyteDB process at startup in environments that
do not mount /sys, such as some containers and build sandboxes. The build
itself runs freshly built binaries (e.g. for initdb), so this also breaks
builds in such sandboxes.

Return -1 from ReadMaxCPUIndex in that case. InitializeSystemInfo already
falls back to the number of CPUs when the max CPU index is unknown, as it
does on platforms other than Linux.

Test Plan:
- Run yb-master --version in a mount namespace without /sys.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant