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 15, 2022
2 parents a3fc02b + 7b479d4 commit 38760d4
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 111 deletions.
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/efbe7d5717dbf0a7b1207fecdf44b6bb05412f66";
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 = "ci-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
92 changes: 20 additions & 72 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,45 +61,9 @@ 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
'';

generateProfiles =
{ pkgs

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

## Environment arguments:
## - either affect semantics on all backends equally,
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 with-profile;

inherit generateProfiles shellHook;
inherit run-analysis;
}
4 changes: 2 additions & 2 deletions nix/workbench/genesis.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ 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
Expand Down
2 changes: 1 addition & 1 deletion nix/workbench/profiles/defaults.jq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Testable with:
##
## jq -n 'include "defaults" { search: "nix/supervisord-cluster/profiles" }; era_defaults("alonzo")'
## jq -n 'include "defaults" { search: "nix/workbench/profiles" }; era_defaults("alonzo")'
##
def era_defaults($era):
{ common:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nix/workbench/profiles/topology.jq
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##
## Testable with:
##
## jq -n 'include "composition" { search: "nix/supervisord-cluster/profiles" }; topology_composition({ coreNodes: { bft1: { pools: 0 } } })'
## jq -n 'include "composition" { search: "nix/workbench/profiles" }; topology_composition({ coreNodes: { bft1: { pools: 0 } } })'
##
def topology_composition($topo):
$topo
Expand Down
4 changes: 2 additions & 2 deletions nix/workbench/profiles/variants.jq
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def genesis_profile_variants:
}
, generator: { tps: 10 }
}
, { name: "ci-light"
, { name: "ci"
, scenario: "fixed-loaded"
, genesis: { utxo: 1000000, delegators: 100000 }
, genesis: { utxo: 2000000, delegators: 1000000 }
, node:
{ shutdown_on_slot_synced: 600
}
Expand Down
Loading

0 comments on commit 38760d4

Please sign in to comment.