Skip to content

Commit

Permalink
Merge #3707
Browse files Browse the repository at this point in the history
3707: Workbench:  make geneses effectively cacheable in CI, by pinning the producing workbench r=deepfire a=deepfire

This makes workbench-produced geneses effectively cacheable in CI, by pinning the producing workbench as a new flake input.

Co-authored-by: Kosyrev Serge <serge.kosyrev@iohk.io>
  • Loading branch information
iohk-bors[bot] and deepfire authored Mar 16, 2022
2 parents 6ad9048 + dfdfa8a commit d7ebae3
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 143 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ test-ghcid-nix: ## Run ghcid on test suites with Nix
bench-chainsync: PROFILE=chainsync-${ERA}
bench-chainsync: cluster-shell-dev ## Enter Nix shell and start the chainsync benchmark

cluster-profiles: ## List available workbench profiles (for PROFILE=)
@./nix/workbench/wb profile list

## TODO: migrate to `nix develop`
cluster-shell: ## Enter Nix shell and start the workbench cluster
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} --arg 'autoStartCluster' true
Expand All @@ -68,6 +65,11 @@ smoke-analysis:
nix build -f 'default.nix' 'workbench-smoke-analysis' --out-link result-smoke-analysis --cores 0 --show-trace
ci-analysis:
nix build -f 'default.nix' 'workbench-ci-analysis' --out-link result-ci-analysis --cores 0 --show-trace
list-profiles: ## List workbench profiles
nix build .#workbench.profile-names-json --json | jq '.[0].outputs.out' -r | xargs jq .
ps: list-profiles
bump-cardano-node-workbench: ## Update the cardano-node-workbench flake input
nix flake lock --update-input cardano-node-workbench

shell: ## Enter Nix shell, CI mode (workbench run from Nix store)
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} ${ARGS}
Expand Down
18 changes: 18 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 25 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
url = "github:input-output-hk/cardano-node/1.33.0";
flake = false;
};

## This pin is to prevent workbench-produced geneses being regenerated each time the node is bumped.
cardano-node-workbench = {
url = "github:input-output-hk/cardano-node/ae35d4c7ae6482397c8444566f25ef0fabb03b18";
flake = false;
};
};

outputs = { self, nixpkgs, hostNixpkgs, utils, haskellNix, iohkNix, membench, plutus-example, ... }@input:
outputs = { self, nixpkgs, hostNixpkgs, utils, haskellNix, iohkNix, membench, plutus-example, cardano-node-workbench, ... }@input:
let
inherit (nixpkgs) lib;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault
Expand Down Expand Up @@ -111,6 +117,8 @@
inherit (project.pkgs) system;
gitrev = plutus-example.rev;
}).haskellPackages.plutus-example.components.exes) plutus-example;
pinned-workbench =
(import cardano-node-workbench {}).workbench.x86_64-linux;
hsPkgsWithPassthru = lib.mapAttrsRecursiveCond (v: !(lib.isDerivation v))
(path: value:
if (lib.isAttrs value) then
Expand All @@ -127,6 +135,7 @@
in
{
inherit projectPackages profiledProject assertedProject eventloggedProject;
inherit pinned-workbench;
projectExes = flatten (haskellLib.collectComponents' "exes" projectPackages) // (with hsPkgsWithPassthru; {
inherit (ouroboros-consensus-byron.components.exes) db-converter;
inherit (ouroboros-consensus-cardano.components.exes) db-analyser;
Expand Down Expand Up @@ -160,7 +169,7 @@
eventlogged = eventloggedProject;
};

inherit (mkPackages project) projectPackages projectExes profiledProject assertedProject eventloggedProject;
inherit (mkPackages project) projectPackages projectExes profiledProject assertedProject eventloggedProject pinned-workbench;

shell = import ./shell.nix { inherit pkgs customConfig; };
devShells = {
Expand Down Expand Up @@ -207,7 +216,7 @@
benchmarks = collectComponents' "benchmarks" projectPackages;
});

workbench = pkgs.clusterNix.workbench;
inherit (pkgs) workbench supervisord-workbench-for-profile;

packages = exes
# Linux only packages:
Expand All @@ -216,9 +225,17 @@
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
membenches = membench.outputs.packages.x86_64-linux.batch-report;
snapshot = membench.outputs.packages.x86_64-linux.snapshot;
workbench-smoke-test = pkgs.clusterNix.profile-run-supervisord { profileName = "smoke-alzo";trace = true; };
workbench-smoke-test =
(pkgs.supervisord-workbench-for-profile
{ workbench = pinned-workbench;
profileName = "smoke-alzo"; }
).profile-run { trace = true; };
workbench-ci-test =
(pkgs.supervisord-workbench-for-profile
{ workbench = pinned-workbench;
profileName = "k6-600slots-1000kU-1000kD-64kbs-10tps-fixed-loaded-alzo"; }
).profile-run {};
workbench-smoke-analysis = workbench-smoke-test.analysis;
workbench-ci-test = pkgs.clusterNix.profile-run-supervisord { profileName = "ci-light-alzo"; };
workbench-ci-analysis = workbench-ci-test.analysis;
}
# Add checks to be able to build them individually
Expand All @@ -242,6 +259,9 @@
# This is used by `nix develop .` to open a devShell
inherit devShell devShells;

# The parametrisable workbench.
inherit workbench;

systemHydraJobs = optionalAttrs (system == "x86_64-linux")
{
linux = {
Expand Down
23 changes: 11 additions & 12 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final: prev: with final; {
scripts = lib.recursiveUpdate (import ./scripts.nix { inherit pkgs; })
(import ./scripts-submit-api.nix { inherit pkgs; });

clusterTests = import ./supervisord-cluster/tests { inherit pkgs; };
clusterTests = import ./workbench/tests { inherit pkgs; };

plutus-scripts = callPackage ./plutus-scripts.nix { plutus-builder = plutus-example; };

Expand Down Expand Up @@ -76,22 +76,21 @@ final: prev: with final; {
script = "submit-api";
};

# This provides a supervisord-backed instance of a the workbench development environment
# A generic, parameteric version of the workbench development environment.
workbench = pkgs.callPackage ./workbench {};

# An instance of the workbench, specialised to the supervisord backend and a profile,
# that can be used with nix-shell or lorri.
# See https://input-output-hk.github.io/haskell.nix/user-guide/development/
workbench-supervisord =
{ useCabalRun, profileName ? customConfig.localCluster.profileName }:
pkgs.callPackages ./supervisord-cluster
supervisord-workbench-for-profile =
{ useCabalRun ? false
, profileName ? customConfig.localCluster.profileName
, workbench ? pkgs.workbench }:
pkgs.callPackage ./workbench/supervisor.nix
{
inherit profileName useCabalRun;
workbench = pkgs.callPackage ./workbench { inherit useCabalRun; };
inherit profileName useCabalRun workbench;
};

clusterCabal = pkgs.workbench-supervisord {
useCabalRun = true;
};
clusterNix = pkgs.workbench-supervisord { useCabalRun = false; };

# Disable failing python uvloop tests
python38 = prev.python38.override {
packageOverrides = pythonFinal: pythonPrev: {
Expand Down
102 changes: 25 additions & 77 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
{ lib
, stdenv
, pkgs
, git
, graphviz
, jq
, moreutils
, makeWrapper
, runCommand
, customConfig
{ pkgs
, lib, jq, runCommand
, cardanoNodePackages

, useCabalRun
}:

with lib; with customConfig.localCluster;
with lib;

let
nixWbMode =
if useCabalRun
then "cabal-exes+nix-wb"
else "nix-exes+nix-wb";

workbench' = tools:
stdenv.mkDerivation {
pkgs.stdenv.mkDerivation {
pname = "workbench";

version = "0.1";

src = ./.;

buildInputs = [ jq makeWrapper ];
buildInputs = with pkgs; [ jq makeWrapper ];

buildPhase = ''
patchShebangs .
'';

postFixup = ''
wrapProgram "$out/bin/wb" --argv0 wb --add-flags "--set-mode ${nixWbMode}" \
--prefix PATH ":" ${pkgs.lib.makeBinPath tools}
wrapProgram "$out/bin/wb" --argv0 wb --prefix PATH ":" ${makeBinPath tools}
'';

installPhase = ''
Expand All @@ -48,7 +32,7 @@ let
dontStrip = true;
};

workbench = with cardanoNodePackages; workbench'
workbench = with cardanoNodePackages; with pkgs; workbench'
[ git graphviz
jq
moreutils
Expand All @@ -67,7 +51,7 @@ let
runWorkbenchJqOnly =
name: command:
runCommand name {} ''
${workbench' [jq moreutils]}/bin/wb ${command} > $out
${workbench' (with pkgs; [jq moreutils])}/bin/wb ${command} > $out
'';

runJq =
Expand All @@ -77,58 +61,22 @@ let
${jq}/bin/jq '${query}' "''${args[@]}" > $out
'';

exeCabalOp = op: exe:
toString [ "cabal" "-v0" op "--" "exe:${exe}"];

checkoutWbMode =
if useCabalRun
then "cabal-exes+checkout-wb"
else "nix-exes+checkout-wb";

shellHook = ''
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun}'
export WORKBENCH_BACKEND=supervisor
${optionalString
workbenchDevMode
''
export WORKBENCH_CARDANO_NODE_REPO_ROOT=$(git rev-parse --show-toplevel)
export WORKBENCH_EXTRA_FLAGS=
function wb() {
$WORKBENCH_CARDANO_NODE_REPO_ROOT/nix/workbench/wb --set-mode ${checkoutWbMode} $WORKBENCH_EXTRA_FLAGS "$@"
}
export -f wb
''}
${optionalString
useCabalRun
''
. nix/workbench/lib.sh
. nix/workbench/lib-cabal.sh
''}
export CARDANO_NODE_SOCKET_PATH=run/current/node-0/node.socket
'';
profile-names-json =
runWorkbenchJqOnly "profile-names.json" "profiles list";

generateProfiles =
{ pkgs
profile-names =
__fromJSON (__readFile profile-names-json);

generateProfiles =
## The backend is an attrset of AWS/supervisord-specific methods and parameters.
, backend
{ backend

## Environment arguments:
## - either affect semantics on all backends equally,
## - or have no semantic effect
, envArgs
}:
rec {
profile-names-json =
runWorkbenchJqOnly "profile-names.json" "profiles list";

profile-names =
__fromJSON (__readFile profile-names-json);

mkProfile =
profileName:
pkgs.callPackage ./profiles
Expand All @@ -140,9 +88,6 @@ let
};

profiles = genAttrs profile-names mkProfile;

profilesJSON =
runWorkbenchJqOnly "all-profiles.json" "profiles generate-all";
};

## materialise-profile :: ProfileNix -> BackendProfile -> Profile
Expand All @@ -153,10 +98,10 @@ let
profile-topology-genesis = import ./genesis.nix { inherit pkgs; };

with-profile =
{ pkgs, backend, envArgs, profileName }:
{ backend, envArgs, profileName }:
let
ps = generateProfiles
{ inherit pkgs backend envArgs; };
{ inherit backend envArgs; };

profileNix = ps.profiles."${profileName}"
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.profiles)}");
Expand All @@ -167,9 +112,9 @@ let
backend.materialise-profile { inherit profileNix; };
};

topology = profile-topology { inherit profileNix profile workbench; };
topology = profile-topology { inherit profileNix profile; };

genesis = profile-topology-genesis { inherit profileNix profile topology workbench; };
genesis = profile-topology-genesis { inherit profileNix profile topology; };
in {
inherit
profileNix profile
Expand All @@ -178,10 +123,13 @@ let
};

run-analysis = import ./analyse.nix;
in

{
inherit workbench runWorkbench runJq with-profile run-analysis;
in {
inherit runJq;

inherit workbench' workbench runWorkbench runWorkbenchJqOnly;

inherit profile-names profile-names-json with-profile;

inherit generateProfiles shellHook;
inherit run-analysis;
}
12 changes: 10 additions & 2 deletions nix/workbench/genesis.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{ pkgs }:

{ profileNix, profile, topology, workbench }:
{ profileNix, profile, topology }:
pkgs.runCommand "workbench-profile-genesis-cache-${profileNix.name}"
{ requiredSystemFeatures = [ "benchmark" ];
nativeBuildInputs = with pkgs.haskellPackages; with pkgs;
[ bash cardano-cli coreutils gnused jq moreutils workbench ];
[ bash cardano-cli coreutils gnused jq moreutils workbench.workbench ];
}
''
mkdir $out
cache_key_input=$(wb genesis profile-cache-key-input ${profileNix.JSON})
cache_key=$(wb genesis profile-cache-key ${profileNix.JSON})
keepalive() {
while test ! -e $out/profile; do echo 'keepalive for Hydra'; sleep 60s; done
echo 'keepalive done'
}
keepalive &
args=(
genesis actually-genesis
${profileNix.JSON}
Expand All @@ -22,5 +28,7 @@ pkgs.runCommand "workbench-profile-genesis-cache-${profileNix.name}"
)
time wb ''${args[@]}
touch done
ln -s ${profile} $out/profile
''
Loading

0 comments on commit d7ebae3

Please sign in to comment.