Skip to content

Commit

Permalink
Workbench: Add app subcommand to create the docker-compose.yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Jun 24, 2022
1 parent 1f07fb1 commit 4fb1c04
Show file tree
Hide file tree
Showing 6 changed files with 71 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
}
2 changes: 1 addition & 1 deletion nix/workbench/default.nix
Expand Up @@ -140,7 +140,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,4 +48,8 @@ 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
''
2 changes: 2 additions & 0 deletions nix/workbench/shell.nix
@@ -1,4 +1,5 @@
{ lib
, profile
, profileName
, workbenchDevMode ? false
, useCabalRun ? false
Expand All @@ -10,6 +11,7 @@ let
shellHook = ''
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun} profileName=${profileName}'
export WORKBENCH_BACKEND=supervisor
export WORKBENCH_SHELL_PROFILE_DIR=${profile}
export WORKBENCH_SHELL_PROFILE=${profileName}
${lib.optionalString
Expand Down
6 changes: 6 additions & 0 deletions nix/workbench/wb
Expand Up @@ -19,6 +19,7 @@ global_mode='unknown'
. "$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 @@ -39,6 +40,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 @@ -231,6 +234,9 @@ main() {
mode ) echo -n $global_mode;;
path ) echo $global_basedir;;

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

## Bail for help:
* ) usage_main "$op"; exit 1;; esac
}
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Expand Up @@ -103,7 +103,7 @@ let

shellHook = ''
${with customConfig.localCluster;
(import ./nix/workbench/shell.nix { inherit lib workbenchDevMode profileName useCabalRun profiled; }).shellHook}
(import ./nix/workbench/shell.nix { inherit lib workbenchDevMode profileName useCabalRun profiled; inherit (cluster) profile;}).shellHook}
function workbench_atexit() {
if wb backend is-running
Expand Down

0 comments on commit 4fb1c04

Please sign in to comment.