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

build: harden build by pre-fetching dependencies #1633

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ self: super: rec {
ms-buildenv = super.callPackage ./pkgs/ms-buildenv { };
nvme-cli = super.callPackage ./pkgs/nvme-cli { };
nvmet-cli = super.callPackage ./pkgs/nvmet-cli { };
units = (super.callPackage ./pkgs/io-engine/units.nix { });
units = (super.callPackage ./pkgs/io-engine/units.nix { inherit tag sourcer; });
}
3 changes: 3 additions & 0 deletions nix/pkgs/io-engine/cargo-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ let
};
in
{
cargoDeps = rustPlatform.importCargoLock {
lockFile = ../../../Cargo.lock;
};
release = rustPlatform.buildRustPackage (buildProps // {
cargoBuildFlags = "--bin io-engine --bin io-engine-client --bin casperf";
buildType = "release";
Expand Down
27 changes: 5 additions & 22 deletions nix/pkgs/io-engine/units.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
{ stdenv
, clang
, dockerTools
, e2fsprogs
, lib
, libaio
, libspdk
, libspdk-dev
, udev
, liburing
, makeRustPlatform
, numactl
, openssl
, pkg-config
, protobuf
, sources
, xfsprogs
, utillinux
, llvmPackages
, targetPackages
, buildPackages
, targetPlatform
, pkgs
, git
, tag
, sourcer
}:
let
versionDrv = import ../../lib/version.nix { inherit lib stdenv git tag sourcer; };
versions = {
"version" = version;
"version" = "${versionDrv}";
"long" = builtins.readFile "${versionDrv.long}";
"tag_or_long" = builtins.readFile "${versionDrv.tag_or_long}";
};
project-builder = { cargoBuildFlags }: pkgs.callPackage ./cargo-package.nix { inherit versions cargoBuildFlags; };
project-builder = { cargoBuildFlags ? [ ] }: pkgs.callPackage ./cargo-package.nix { inherit versions cargoBuildFlags; };
components = { build }: {
io-engine = (project-builder { cargoBuildFlags = [ "--bin io-engine" ]; }).${build};
io-engine-cli = (project-builder { cargoBuildFlags = [ "--bin io-engine-cli" ]; }).${build};
Expand All @@ -39,6 +21,7 @@ let
};
in
{
cargoDeps = (project-builder { }).cargoDeps;
release = components { build = "release"; };
debug = components { build = "debug"; };
}
42 changes: 40 additions & 2 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,39 @@ nix_experimental() {
echo -n " "
fi
}
pre_fetch_cargo_deps() {
local nixAttrPath=$1
local project=$2
local maxAttempt=$3

local outLink="--no-out-link"
local cargoVendorMsg=""
if [ -n "$CARGO_VENDOR_DIR" ]; then
if [ "$(realpath -s "$CARGO_VENDOR_DIR")" = "$(realpath -s "$SCRIPTDIR/..")" ]; then
cargoVendorDir="$CARGO_VENDOR_DIR/$GIT_BRANCH"
else
cargoVendorDir="$CARGO_VENDOR_DIR/$project/$GIT_BRANCH"
fi

outLink="--out-link "$cargoVendorDir""
cargoVendorMsg="into $(realpath -s "$cargoVendorDir") "
fi

for (( attempt=1; attempt<=maxAttempt; attempt++ )); do
if $NIX_BUILD $outLink -A "$nixAttrPath"; then
echo "Cargo vendored dependencies pre-fetched "$cargoVendorMsg"after $attempt attempt(s)"
return 0
fi
sleep 1
done
if [ "$attempt" = "1" ]; then
echo "Cargo vendor pre-fetch is disabled"
return 0
fi

echo "Failed to pre-fetch the cargo vendored dependencies in $maxAttempt attempts"
exit 1
}

help() {
cat <<EOF
Expand Down Expand Up @@ -59,8 +92,8 @@ RM="rm"
SCRIPTDIR=$(dirname "$0")
TAG=`get_tag`
HASH=`get_hash`
BRANCH=`git rev-parse --abbrev-ref HEAD`
BRANCH=${BRANCH////-}
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
BRANCH=${GIT_BRANCH////-}
IMAGES=
UPLOAD=
SKIP_PUBLISH=
Expand All @@ -69,6 +102,8 @@ REGISTRY=
ALIAS=
DEBUG=
OVERRIDE_COMMIT_HASH=
CARGO_VENDOR_DIR=${CARGO_VENDOR_DIR:-}
CARGO_VENDOR_ATTEMPTS=${CARGO_VENDOR_ATTEMPTS:-25}

# Check if all needed tools are installed
curl --version >/dev/null
Expand Down Expand Up @@ -140,6 +175,9 @@ done

cd $SCRIPTDIR/..

# pre-fetch build dependencies with a number of attempts to harden against flaky networks
pre_fetch_cargo_deps units.cargoDeps "mayastor-io-engine" "$CARGO_VENDOR_ATTEMPTS"

if [ -z "$IMAGES" ]; then
if [ -z "$DEBUG" ]; then
IMAGES="mayastor-io-engine mayastor-fio-spdk mayastor-casperf"
Expand Down
Loading