Skip to content

Commit a577e93

Browse files
authored
Feat: add post-start hook executed after up/start (#616)
1 parent 138a0e3 commit a577e93

25 files changed

+216
-273
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,28 @@ Other available parameters for entries in the `chaincodes` array are:
589589
590590
### hooks
591591
592-
Hooks in Fablo are Bash commands to be executed after a specific event.
593-
Currently, Fablo supports only one kind of hook: `postGenerate`.
594-
It will be executed each time after the network config is generated -- after the `./fablo generate` command (executed separately or automatically by `./fablo up`).
592+
Hooks in Fablo are Bash commands to be executed after specific events.
593+
Supported hooks:
595594
596-
The following hook example will change `MaxMessageCount` to 1 in the generated Hyperledger Fabric config:
595+
- `postGenerate` — executed after the network config is generated (after `./fablo generate`, executed separately or automatically by `./fablo up`).
596+
- `postStart` — executed after the network is started (after `./fablo up` or `./fablo start`).
597+
598+
Example `postGenerate` hook that changes `MaxMessageCount` to 1 in generated Hyperledger Fabric config:
597599
598600
```json
599601
"hooks": {
600602
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' \"./fablo-target/fabric-config/configtx.yaml\""
601603
}
602604
```
603605
606+
Example `postStart` hook that waits for peers to be ready or performs any additional bootstrap actions:
607+
608+
```json
609+
"hooks": {
610+
"postStart": "echo 'Network started' && ./fablo-target/fabric-docker.sh channel list org1 peer0"
611+
}
612+
```
613+
604614
Generated hooks are saved in `fablo-target/hooks`.
605615
606616

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-network/docker/test-02-v2-raft-2orgs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ networkUp() {
2424
expectCommand "cat \"$TEST_TMP/fablo-target/fabric-config/configtx.yaml\"" "MaxMessageCount: 1$"
2525

2626
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" up)
27+
28+
# verify if post start hook was called
29+
expectCommand "cat \"$TEST_TMP/fablo-target/container-list.txt\"" "peer0.org1.example.com"
30+
echo "✅ All expected containers found in the log"
2731
}
2832

2933
dumpLogs() {

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
{
@@ -5893,6 +5897,7 @@ exports[`extend config samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml 1`]
58935897
},
58945898
"hooks": {
58955899
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
5900+
"postStart": "docker ps --format 'table {{.Names}} {{.Status}} {{.Ports}}' > ./fablo-target/container-list.txt 2>&1 && echo 'Container list saved into fablo-target directory'",
58965901
},
58975902
"orderedHeadsDistinct": [
58985903
{
@@ -8489,6 +8494,7 @@ exports[`extend config samples/fablo-config-hlf2-3orgs-1chaincode-raft-explorer.
84898494
},
84908495
"hooks": {
84918496
"postGenerate": "",
8497+
"postStart": "",
84928498
},
84938499
"orderedHeadsDistinct": [
84948500
{
@@ -10335,6 +10341,7 @@ exports[`extend config samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json
1033510341
},
1033610342
"hooks": {
1033710343
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
10344+
"postStart": "",
1033810345
},
1033910346
"orderedHeadsDistinct": [
1034010347
{
@@ -11224,6 +11231,7 @@ exports[`extend config samples/fablo-config-hlf3-1orgs-1chaincode.json 1`] = `
1122411231
},
1122511232
"hooks": {
1122611233
"postGenerate": "",
11234+
"postStart": "",
1122711235
},
1122811236
"orderedHeadsDistinct": [
1122911237
{
@@ -12184,6 +12192,7 @@ exports[`extend config samples/fablo-config-hlf3-bft-1orgs-1chaincode.json 1`] =
1218412192
},
1218512193
"hooks": {
1218612194
"postGenerate": "",
12195+
"postStart": "",
1218712196
},
1218812197
"orderedHeadsDistinct": [
1218912198
{
@@ -13621,6 +13630,7 @@ exports[`extend config samples/invalid-fablo-config.json 1`] = `
1362113630
},
1362213631
"hooks": {
1362313632
"postGenerate": "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-config/configtx.yaml"",
13633+
"postStart": "",
1362413634
},
1362513635
"orderedHeadsDistinct": [
1362613636
{
@@ -14325,6 +14335,7 @@ exports[`extend config samples/java-dev-mode-sample.json 1`] = `
1432514335
},
1432614336
"hooks": {
1432714337
"postGenerate": "",
14338+
"postStart": "",
1432814339
},
1432914340
"orderedHeadsDistinct": [
1433014341
{

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
@@ -547,6 +547,14 @@ echo "Executing post-generate hook"
547547
"
548548
`;
549549
550+
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`] = `
551+
"#!/usr/bin/env bash
552+
553+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
554+
echo "Executing post-start hook"
555+
"
556+
`;
557+
550558
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`] = `
551559
"graph TD
552560
@@ -583,6 +591,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode-k8s.json should create proper
583591
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/fabric-k8s/scripts/chaincode-functions.sh",
584592
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/fabric-k8s/scripts/util.sh",
585593
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/hooks/post-generate.sh",
594+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/hooks/post-start.sh",
586595
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-k8s.json.tmpdir/fablo-target/network-topology.mmd",
587596
]
588597
`;

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
@@ -3528,6 +3528,14 @@ echo "Executing post-generate hook"
35283528
"
35293529
`;
35303530
3531+
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`] = `
3532+
"#!/usr/bin/env bash
3533+
3534+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3535+
echo "Executing post-start hook"
3536+
"
3537+
`;
3538+
35313539
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`] = `
35323540
"graph TD
35333541
@@ -3578,6 +3586,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json should cre
35783586
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
35793587
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
35803588
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/hooks/post-generate.sh",
3589+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/hooks/post-start.sh",
35813590
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json.tmpdir/fablo-target/network-topology.mmd",
35823591
]
35833592
`;

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
@@ -3589,6 +3589,14 @@ echo "Executing post-generate hook"
35893589
"
35903590
`;
35913591
3592+
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`] = `
3593+
"#!/usr/bin/env bash
3594+
3595+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3596+
echo "Executing post-start hook"
3597+
"
3598+
`;
3599+
35923600
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`] = `
35933601
"graph TD
35943602
@@ -3641,6 +3649,7 @@ exports[`samples/fablo-config-hlf2-1org-1chaincode.json should create proper fil
36413649
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
36423650
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
36433651
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/hooks/post-generate.sh",
3652+
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/hooks/post-start.sh",
36443653
"e2e/__tmp__/samples/fablo-config-hlf2-1org-1chaincode.json.tmpdir/fablo-target/network-topology.mmd",
36453654
]
36463655
`;

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
@@ -3774,6 +3774,14 @@ perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-
37743774
"
37753775
`;
37763776
3777+
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`] = `
3778+
"#!/usr/bin/env bash
3779+
3780+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
3781+
echo "Executing post-start hook"
3782+
"
3783+
`;
3784+
37773785
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`] = `
37783786
"graph TD
37793787
@@ -3831,6 +3839,7 @@ exports[`samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json should create
38313839
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
38323840
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
38333841
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/hooks/post-generate.sh",
3842+
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/hooks/post-start.sh",
38343843
"e2e/__tmp__/samples/fablo-config-hlf3-1org-2chaincode-raft-ccaas.json.tmpdir/fablo-target/network-topology.mmd",
38353844
]
38363845
`;

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
@@ -4546,6 +4546,14 @@ echo "Executing post-generate hook"
45464546
"
45474547
`;
45484548
4549+
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`] = `
4550+
"#!/usr/bin/env bash
4551+
4552+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
4553+
echo "Executing post-start hook"
4554+
"
4555+
`;
4556+
45494557
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`] = `
45504558
"graph TD
45514559
@@ -4612,6 +4620,7 @@ exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml should cr
46124620
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
46134621
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
46144622
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/hooks/post-generate.sh",
4623+
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/hooks/post-start.sh",
46154624
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-private-data.yaml.tmpdir/fablo-target/network-topology.mmd",
46164625
]
46174626
`;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ chaincodes:
8282
hooks:
8383
# changes MaxMessageCount to 1
8484
postGenerate: "perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' \\"./fablo-target/fabric-config/configtx.yaml\\""
85+
postStart: "docker ps --format 'table {{.Names}}\\t{{.Status}}\\t{{.Ports}}' > ./fablo-target/container-list.txt 2>&1 && echo 'Container list saved into fablo-target directory'"
8586
"
8687
`;
8788

@@ -6509,6 +6510,16 @@ perl -i -pe 's/MaxMessageCount: 10/MaxMessageCount: 1/g' "./fablo-target/fabric-
65096510
"
65106511
`;
65116512
6513+
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`] = `
6514+
"#!/usr/bin/env bash
6515+
6516+
# The code from this file is called after Fablo starts the Hyperledger Fabric network (after 'up' or 'start')
6517+
echo "Executing post-start hook"
6518+
6519+
docker ps --format 'table {{.Names}} {{.Status}} {{.Ports}}' >./fablo-target/container-list.txt 2>&1 && echo 'Container list saved into fablo-target directory'
6520+
"
6521+
`;
6522+
65126523
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`] = `
65136524
"graph TD
65146525
@@ -6610,6 +6621,7 @@ exports[`samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml should create pro
66106621
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/fabric-docker/scripts/cli/channel_fns.sh",
66116622
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/fabric-docker/snapshot-scripts.sh",
66126623
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/hooks/post-generate.sh",
6624+
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/hooks/post-start.sh",
66136625
"e2e/__tmp__/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml.tmpdir/fablo-target/network-topology.mmd",
66146626
]
66156627
`;

0 commit comments

Comments
 (0)