Skip to content

Commit fdbd122

Browse files
committed
feat(hooks): add post-start hook executed after up/start
Signed-off-by: OsamaRab3 <osrab3@gmail.com>
1 parent 40d612c commit fdbd122

23 files changed

+211
-274
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,29 @@ The `privateData` parameter is optional. You don't need to define the private da
551551
552552
### hooks
553553
554-
Hooks in Fablo are Bash commands to be executed after a specific event.
555-
Right now Fablo supports only one kind of hook: `postGenerate`.
556-
It will be executed each time after the network config is generated -- after `./fablo generate` command (executed separately or automatically by `./fablo up`).
554+
Hooks in Fablo are Bash commands to be executed after specific events.
555+
Supported hooks:
557556
558-
The following hook example will change `MaxMessageCount` to 1 in generated Hyperledger Fabric config:
557+
- `postGenerate` — executed after the network config is generated (after `./fablo generate`, executed separately or automatically by `./fablo up`).
558+
- `postStart` — executed after the network is started (after `./fablo up` or `./fablo start`).
559+
560+
Example `postGenerate` hook that changes `MaxMessageCount` to 1 in generated Hyperledger Fabric config:
559561
560562
```json
561563
"hooks": {
562564
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' \"./fablo-target/fabric-config/configtx.yaml\""
563565
}
564566
```
565567
566-
Genrated Hooks are saved in `fablo-target/hooks`.
568+
Example `postStart` hook that waits for peers to be ready or performs any additional bootstrap actions:
569+
570+
```json
571+
"hooks": {
572+
"postStart": "echo 'Network started' && ./fablo-target/fabric-docker.sh channel list org1 peer0"
573+
}
574+
```
575+
576+
Generated hooks are saved in `fablo-target/hooks`.
567577
568578
569579
### Sample YAML config file

docs/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,12 @@
553553
"title": "Post generate hook",
554554
"description": "Operation to run run after a network config is generated",
555555
"type": "string"
556+
},
557+
"postStart": {
558+
"$id": "#/properties/hooks/postStart",
559+
"title": "Post start hook",
560+
"description": "Operation to run after the network is started (after 'up' or 'start')",
561+
"type": "string"
556562
}
557563
}
558564
}

e2e/__snapshots__/extendConfig.test.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ exports[`extend config samples/fablo-config-hlf2-1org-1chaincode.json 1`] = `
610610
},
611611
"hooks": {
612612
"postGenerate": "",
613+
"postStart": "",
613614
},
614615
"orderedHeadsDistinct": [
615616
{
@@ -1438,6 +1439,7 @@ exports[`extend config samples/fablo-config-hlf2-1org-1chaincode-k8s.json 1`] =
14381439
},
14391440
"hooks": {
14401441
"postGenerate": "",
1442+
"postStart": "",
14411443
},
14421444
"orderedHeadsDistinct": [
14431445
{
@@ -2242,6 +2244,7 @@ exports[`extend config samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.j
22422244
},
22432245
"hooks": {
22442246
"postGenerate": "",
2247+
"postStart": "",
22452248
},
22462249
"orderedHeadsDistinct": [
22472250
{
@@ -3611,6 +3614,7 @@ exports[`extend config samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.
36113614
},
36123615
"hooks": {
36133616
"postGenerate": "",
3617+
"postStart": "",
36143618
},
36153619
"orderedHeadsDistinct": [
36163620
{
@@ -5879,6 +5883,7 @@ exports[`extend config samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml 1`]
58795883
},
58805884
"hooks": {
58815885
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
5886+
"postStart": "",
58825887
},
58835888
"orderedHeadsDistinct": [
58845889
{
@@ -8476,6 +8481,7 @@ exports[`extend config samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.
84768481
},
84778482
"hooks": {
84788483
"postGenerate": "",
8484+
"postStart": "",
84798485
},
84808486
"orderedHeadsDistinct": [
84818487
{
@@ -10318,6 +10324,7 @@ exports[`extend config samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json
1031810324
},
1031910325
"hooks": {
1032010326
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
10327+
"postStart": "",
1032110328
},
1032210329
"orderedHeadsDistinct": [
1032310330
{
@@ -11207,6 +11214,7 @@ exports[`extend config samples/fablo-config-hlf3-1orgs-1chaincode.json 1`] = `
1120711214
},
1120811215
"hooks": {
1120911216
"postGenerate": "",
11217+
"postStart": "",
1121011218
},
1121111219
"orderedHeadsDistinct": [
1121211220
{
@@ -12167,6 +12175,7 @@ exports[`extend config samples/fablo-config-hlf3-bft-1orgs-1chaincode.json 1`] =
1216712175
},
1216812176
"hooks": {
1216912177
"postGenerate": "",
12178+
"postStart": "",
1217012179
},
1217112180
"orderedHeadsDistinct": [
1217212181
{
@@ -13600,6 +13609,7 @@ exports[`extend config samples/invalid-fablo-config.json 1`] = `
1360013609
},
1360113610
"hooks": {
1360213611
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
13612+
"postStart": "",
1360313613
},
1360413614
"orderedHeadsDistinct": [
1360513615
{
@@ -14304,6 +14314,7 @@ exports[`extend config samples/java-dev-mode-sample.json 1`] = `
1430414314
},
1430514315
"hooks": {
1430614316
"postGenerate": "",
14317+
"postStart": "",
1430714318
},
1430814319
"orderedHeadsDistinct": [
1430914320
{

e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-k8s.json.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ echo "Executing post-generate hook"
487487
"
488488
`;
489489
490+
exports[`samples/fablo-config-hlf2-1org-1chaincode-k8s.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-1org-1chaincode-k8s.json 1`] = `
491+
"#!/usr/bin/env bash
492+
493+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
494+
echo "Executing post-start hook"
495+
"
496+
`;
497+
490498
exports[`samples/fablo-config-hlf2-1org-1chaincode-k8s.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-1org-1chaincode-k8s.json 1`] = `
491499
"graph TD
492500
@@ -522,6 +530,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode-k8s.json should create proper
522530
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/fabric-k8s/scripts/chaincode-functions.sh",
523531
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/fabric-k8s/scripts/util.sh",
524532
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/hooks/post-generate.sh",
533+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/hooks/post-start.sh",
525534
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/network-topology.mmd",
526535
]
527536
`;

e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,14 @@ echo "Executing post-generate hook"
34413441
"
34423442
`;
34433443
3444+
exports[`samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json 1`] = `
3445+
"#!/usr/bin/env bash
3446+
3447+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3448+
echo "Executing post-start hook"
3449+
"
3450+
`;
3451+
34443452
exports[`samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json 1`] = `
34453453
"graph TD
34463454
@@ -3490,6 +3498,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json should cre
34903498
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
34913499
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
34923500
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/hooks/post-generate.sh",
3501+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/hooks/post-start.sh",
34933502
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/network-topology.mmd",
34943503
]
34953504
`;

e2e/__snapshots__/fablo-config-hlf2-1org-1chaincode.json.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,6 +3511,14 @@ echo "Executing post-generate hook"
35113511
"
35123512
`;
35133513
3514+
exports[`samples/fablo-config-hlf2-1org-1chaincode.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-1org-1chaincode.json 1`] = `
3515+
"#!/usr/bin/env bash
3516+
3517+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3518+
echo "Executing post-start hook"
3519+
"
3520+
`;
3521+
35143522
exports[`samples/fablo-config-hlf2-1org-1chaincode.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-1org-1chaincode.json 1`] = `
35153523
"graph TD
35163524
@@ -3562,6 +3570,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode.json should create proper fil
35623570
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
35633571
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
35643572
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/hooks/post-generate.sh",
3573+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/hooks/post-start.sh",
35653574
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/network-topology.mmd",
35663575
]
35673576
`;

e2e/__snapshots__/fablo-config-hlf2-1org-2chaincode-raft-ccaas.json.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,6 +3656,14 @@ perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-
36563656
"
36573657
`;
36583658
3659+
exports[`samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json should create proper e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json 1`] = `
3660+
"#!/usr/bin/env bash
3661+
3662+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3663+
echo "Executing post-start hook"
3664+
"
3665+
`;
3666+
36593667
exports[`samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json should create proper e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json 1`] = `
36603668
"graph TD
36613669
@@ -3712,6 +3720,7 @@ exports[`samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json should create
37123720
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
37133721
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
37143722
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/hooks/post-generate.sh",
3723+
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/hooks/post-start.sh",
37153724
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/network-topology.mmd",
37163725
]
37173726
`;

e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,6 +4465,14 @@ echo "Executing post-generate hook"
44654465
"
44664466
`;
44674467
4468+
exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml should create proper e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml 1`] = `
4469+
"#!/usr/bin/env bash
4470+
4471+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
4472+
echo "Executing post-start hook"
4473+
"
4474+
`;
4475+
44684476
exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml should create proper e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml 1`] = `
44694477
"graph TD
44704478
@@ -4530,6 +4538,7 @@ exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml should cr
45304538
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
45314539
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
45324540
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/hooks/post-generate.sh",
4541+
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/hooks/post-start.sh",
45334542
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/network-topology.mmd",
45344543
]
45354544
`;

e2e/__snapshots__/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,6 +6367,14 @@ perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-
63676367
"
63686368
`;
63696369
6370+
exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml should create proper e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml 1`] = `
6371+
"#!/usr/bin/env bash
6372+
6373+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
6374+
echo "Executing post-start hook"
6375+
"
6376+
`;
6377+
63706378
exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml should create proper e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml 1`] = `
63716379
"graph TD
63726380
@@ -6467,6 +6475,7 @@ exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml should create pro
64676475
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
64686476
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
64696477
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/hooks/post-generate.sh",
6478+
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/hooks/post-start.sh",
64706479
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/network-topology.mmd",
64716480
]
64726481
`;

e2e/__snapshots__/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6939,6 +6939,14 @@ echo "Executing post-generate hook"
69396939
"
69406940
`;
69416941
6942+
exports[`samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/hooks/post-start.sh from samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json 1`] = `
6943+
"#!/usr/bin/env bash
6944+
6945+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
6946+
echo "Executing post-start hook"
6947+
"
6948+
`;
6949+
69426950
exports[`samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json should create proper e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/network-topology.mmd from samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json 1`] = `
69436951
"graph TD
69446952
@@ -7031,6 +7039,7 @@ exports[`samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json should cr
70317039
"e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
70327040
"e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
70337041
"e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/hooks/post-generate.sh",
7042+
"e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/hooks/post-start.sh",
70347043
"e2e/__tmp__/samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.json.tmpdir/fablo-target/network-topology.mmd",
70357044
]
70367045
`;

0 commit comments

Comments
 (0)