Skip to content

Commit

Permalink
WIP OCI for profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Aug 8, 2022
1 parent 1db89e7 commit 3cbe32e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
53 changes: 53 additions & 0 deletions nix/workbench/app.sh
@@ -0,0 +1,53 @@
usage_app() {
usage "app" "Multi-container application" <<EOF
compose Multi-container description file
EOF
}

app() {
local op=${1:-show}; test $# -gt 0 && shift

case "$op" in

# wb app compose $WORKBENCH_SHELL_PROFILE_DIR/{profile,node-specs}.json name tag
compose )
# jq 'keys|.[]' --raw-output $WORKBENCH_SHELL_PROFILE_DIR/node-specs.json
local usage="USAGE: wb app $op PROFILE-NAME/JSON NODE-SPECS/JSON IMAGE_NAME IMAGE_TAG"
local profile=${1:?$usage}
local nodespecs=${2:?$usage}
local imageName=${3:?$usage}
local imageTag=${4:?$usage}

# Hack
global_rundir_def=$PWD/run

yq --yaml-output "{
services:
(
.
| with_entries(
{
key: .key
, value: {
container_name: \"node-\(.value.i)\"
, pull_policy: \"never\"
, image: \"$imageName:$imageTag\"
, networks: [\"cardano-node-network\"]
, ports: [\"\(.value.port):\(.value.port)\"]
, volumes: [
\"DATA_DIR:/var/cardano-node/run\"
]
, environment: [
\"DATA_DIR=/var/cardano-node/run\"
]
}
}
)
)
, \"networks\": {\"cardano-node-network\": {}}
, \"volumes\": {\"DATA_DIR\": {\"external\": true} }
}" $nodespecs;;

* ) usage_app;; esac
}
5 changes: 3 additions & 2 deletions nix/workbench/default.nix
Expand Up @@ -2,6 +2,7 @@
, lib, jq, runCommand
, db-analyser
, cardanoNodePackages
, cardano-world
}:

with lib;
Expand Down Expand Up @@ -35,7 +36,7 @@ let

workbench = with cardanoNodePackages; with pkgs; workbench' (
[ git graphviz
jq
jq yq
moreutils
procps

Expand Down Expand Up @@ -96,7 +97,7 @@ let
};

## materialise-profile :: ProfileNix -> BackendProfile -> Profile
materialise-profile = import ./profile.nix { inherit pkgs lib; };
materialise-profile = import ./profile.nix { inherit pkgs lib cardano-world; };
## profile-topology :: ProfileNix -> Topology
profile-topology = import ./topology.nix { inherit pkgs; };
## profile-topology :: ProfileNix -> Topology -> Genesis
Expand Down
10 changes: 8 additions & 2 deletions nix/workbench/profile.nix
@@ -1,12 +1,12 @@
{ pkgs, lib }:
{ pkgs, lib, cardano-world }:
with lib;

{ profileNix
, backendProfile ## Backend-specific results for forwarding
, workbench
}:
pkgs.runCommand "workbench-profile-output-${profileNix.name}"
{ buildInputs = with pkgs; [ jq workbench ];
{ buildInputs = with pkgs; [ jq yq workbench ];
nodeServices =
__toJSON
(flip mapAttrs profileNix.node-services
Expand Down Expand Up @@ -35,6 +35,8 @@ pkgs.runCommand "workbench-profile-output-${profileNix.name}"
config = config.JSON;
start = startupScript;
};
cardanoNodeImageName = cardano-world.x86_64-linux.cardano.oci-images.cardano-node.imageName;
cardanoNodeImageTag = cardano-world.x86_64-linux.cardano.oci-images.cardano-node.imageTag;
passAsFile = [ "nodeServices" "generatorService" "tracerService" ];
}
''
Expand All @@ -46,6 +48,10 @@ pkgs.runCommand "workbench-profile-output-${profileNix.name}"
cp $tracerServicePath $out/tracer-service.json
wb profile node-specs $out/profile.json > $out/node-specs.json
echo $cardanoNodeImageName > $out/cardanoNodeImageName
echo $cardanoNodeImageTag > $out/cardanoNodeImageTag
wb app compose $out/profile.json $out/node-specs.json $cardanoNodeImageName $cardanoNodeImageTag > $out/docker-compose.yaml
''
// { inherit (profileNix) name;
inherit workbench;
Expand Down
2 changes: 2 additions & 0 deletions nix/workbench/shell.nix
Expand Up @@ -21,6 +21,7 @@ with lib;
let cluster = pkgs.supervisord-workbench-for-profile {
inherit profileName useCabalRun profiled;
};
inherit (cluster) profile;

shellHook = { workbenchDevMode, useCabalRun, profiled, profileName, withMainnet }: ''
while test $# -gt 0
Expand All @@ -29,6 +30,7 @@ let cluster = pkgs.supervisord-workbench-for-profile {
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun} profiled=${toString profiled} profileName=${profileName}'
export WB_BACKEND=supervisor
export WB_SHELL_PROFILE=${profileName}
export WB_SHELL_PROFILE_DIR=${profile}
${optionalString
workbenchDevMode
Expand Down
6 changes: 6 additions & 0 deletions nix/workbench/wb
Expand Up @@ -18,6 +18,7 @@ global_basedir=${global_basedir:-$(realpath "$(dirname "$0")")}
. "$global_basedir"/scenario.sh
. "$global_basedir"/analyse.sh
. "$global_basedir"/explain-mode.sh
. "$global_basedir"/app.sh

. "$global_basedir"/backend.sh
. "$global_basedir"/supervisor.sh
Expand All @@ -38,6 +39,8 @@ usage_main() {
topology (t) Topology generation
run (r) Managing cluster runs. Default op is 'list'
app Multi-container (services) application
Options:
--trace / --debug set -x
Expand Down Expand Up @@ -236,6 +239,9 @@ main() {
call ) "$@";;
path ) echo $global_basedir;;

## Docker's compose application (services) description.
app ) app "$@";;

## Bail for help:
* ) usage_main "$op"; exit 1;; esac
}
Expand Down

0 comments on commit 3cbe32e

Please sign in to comment.