Skip to content

Commit d5a059a

Browse files
committed
docs(examples): increase supply chain image boot responsiveness hyperledger-cacti#780
Added logging to all 3 of the test ledger classes that are being used which are taking up most of the boot time. Now users can see the setup process as it chugs along step by step and in general be much more confident while waiting that things are indeed happening instead of the container just being in a zombie state. Also added an additional point in the README.md file claryfying that one needs to have a working installation of docker on their machine. Decided to not go into any more detail than that because the (linked) docker for desktop documentation is the best/most robust resrouces available there is and it would be hard to compete with it if we were to produce our own installation instructions. Fixes hyperledger-cacti#780 Signed-off-by: Peter Somogyvari <[email protected]>
1 parent ff6e85c commit d5a059a

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ As blockchain technology proliferates, blockchain integration will become an inc
1919

2020
### Supply Chain Example
2121

22-
1. Run the following command to pull up the container that will run the example application and the test ledgers as well:
22+
1. Ensure a working installation of [Docker](https://docs.docker.com/desktop/) is present on your machine.
23+
2. Run the following command to pull up the container that will run the example application and the test ledgers as well:
2324
```sh
2425
docker run \
2526
--rm \
@@ -30,11 +31,11 @@ As blockchain technology proliferates, blockchain integration will become an inc
3031
-p 4000:4000 \
3132
-p 4100:4100 \
3233
-p 4200:4200 \
33-
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-01--fix-1063-v2
34+
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-20--fix-720
3435
```
35-
2. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3100`
36-
3. Visit http://localhost:3100 in a web browser with Javascript enabled
37-
4. Use the graphical user interface to create data on both ledgers and observe that a consistent view of the data from different ledgers is provided.
36+
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3100`
37+
4. Visit http://localhost:3100 in a web browser with Javascript enabled
38+
5. Use the graphical user interface to create data on both ledgers and observe that a consistent view of the data from different ledgers is provided.
3839

3940
Once the last command has finished executing, open link printed on the console with a web browser of your choice
4041

examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,19 @@ export class SupplyChainAppDummyInfrastructure {
103103
const label = this.className;
104104
this.log = LoggerProvider.getOrCreate({ level, label });
105105

106-
this.besu = new BesuTestLedger();
107-
this.quorum = new QuorumTestLedger();
106+
this.besu = new BesuTestLedger({
107+
logLevel: level,
108+
});
109+
this.quorum = new QuorumTestLedger({
110+
logLevel: level,
111+
emitContainerLogs: true,
112+
});
108113
this.fabric = new FabricTestLedgerV1({
109114
publishAllPorts: true,
110115
imageName: "ghcr.io/hyperledger/cactus-fabric-all-in-one",
111116
imageVersion: "2021-03-02-ssh-hotfix",
112117
logLevel: level,
118+
emitContainerLogs: true,
113119
});
114120

115121
if (this.options.keychain) {

examples/supply-chain-app/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
-p 4000:4000 \
1515
-p 4100:4100 \
1616
-p 4200:4200 \
17-
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-01--fix-1063-v2
17+
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-20--fix-720
1818
```
1919
2. Observe the example application pulling up in the logs
2020
1. the test ledger containers,

packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
LogLevelDesc,
1010
Logger,
1111
LoggerProvider,
12+
Bools,
1213
} from "@hyperledger/cactus-common";
1314
import { ITestLedger } from "../i-test-ledger";
1415
import { Streams } from "../common/streams";
@@ -22,6 +23,7 @@ export interface IBesuTestLedgerConstructorOptions {
2223
rpcApiWsPort?: number;
2324
envVars?: string[];
2425
logLevel?: LogLevelDesc;
26+
emitContainerLogs?: boolean;
2527
}
2628

2729
export const BESU_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({
@@ -52,6 +54,7 @@ export class BesuTestLedger implements ITestLedger {
5254
public readonly rpcApiHttpPort: number;
5355
public readonly rpcApiWsPort: number;
5456
public readonly envVars: string[];
57+
public readonly emitContainerLogs: boolean;
5558

5659
private readonly log: Logger;
5760
private container: Container | undefined;
@@ -73,6 +76,10 @@ export class BesuTestLedger implements ITestLedger {
7376
options.rpcApiWsPort || BESU_TEST_LEDGER_DEFAULT_OPTIONS.rpcApiWsPort;
7477
this.envVars = options.envVars || BESU_TEST_LEDGER_DEFAULT_OPTIONS.envVars;
7578

79+
this.emitContainerLogs = Bools.isBooleanStrict(options.emitContainerLogs)
80+
? (options.emitContainerLogs as boolean)
81+
: true;
82+
7683
this.validateConstructorOptions();
7784
const label = "besu-test-ledger";
7885
const level = options.logLevel || "INFO";
@@ -255,6 +262,16 @@ export class BesuTestLedger implements ITestLedger {
255262
this.log.debug(`Started container OK. Waiting for healthcheck...`);
256263
this.container = container;
257264
this.containerId = container.id;
265+
266+
if (this.emitContainerLogs) {
267+
const logOptions = { follow: true, stderr: true, stdout: true };
268+
const logStream = await container.logs(logOptions);
269+
logStream.on("data", (data: Buffer) => {
270+
const fnTag = `[${this.getContainerImageName()}]`;
271+
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
272+
});
273+
}
274+
258275
try {
259276
await this.waitForHealthCheck();
260277
this.log.debug(`Healthcheck passing OK.`);

packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import Joi from "joi";
66
import tar from "tar-stream";
77
import Web3 from "web3";
88
import { Account } from "web3-core";
9+
import {
10+
Bools,
11+
Logger,
12+
LoggerProvider,
13+
LogLevelDesc,
14+
} from "@hyperledger/cactus-common";
915
import { ITestLedger } from "../i-test-ledger";
1016
import { Streams } from "../common/streams";
1117
import { IKeyPair } from "../i-key-pair";
@@ -15,6 +21,8 @@ export interface IQuorumTestLedgerConstructorOptions {
1521
containerImageVersion?: string;
1622
containerImageName?: string;
1723
rpcApiHttpPort?: number;
24+
logLevel?: LogLevelDesc;
25+
emitContainerLogs?: boolean;
1826
}
1927

2028
export const QUORUM_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({
@@ -40,7 +48,9 @@ export class QuorumTestLedger implements ITestLedger {
4048
public readonly containerImageVersion: string;
4149
public readonly containerImageName: string;
4250
public readonly rpcApiHttpPort: number;
51+
public readonly emitContainerLogs: boolean;
4352

53+
private readonly log: Logger;
4454
private container: Container | undefined;
4555
private containerId: string | undefined;
4656

@@ -60,7 +70,15 @@ export class QuorumTestLedger implements ITestLedger {
6070
options.rpcApiHttpPort ||
6171
QUORUM_TEST_LEDGER_DEFAULT_OPTIONS.rpcApiHttpPort;
6272

73+
this.emitContainerLogs = Bools.isBooleanStrict(options.emitContainerLogs)
74+
? (options.emitContainerLogs as boolean)
75+
: true;
76+
6377
this.validateConstructorOptions();
78+
79+
const label = "quorum-test-ledger";
80+
const level = options.logLevel || "INFO";
81+
this.log = LoggerProvider.getOrCreate({ level, label });
6482
}
6583

6684
public getContainer(): Container {
@@ -174,13 +192,15 @@ export class QuorumTestLedger implements ITestLedger {
174192
public async start(omitPull = false): Promise<Container> {
175193
const containerNameAndTag = this.getContainerImageName();
176194

195+
this.log.debug(`Starting Quorum Test Ledger: ${containerNameAndTag}`);
177196
if (this.container) {
178197
await this.container.stop();
179198
await this.container.remove();
180199
}
181200
const docker = new Docker();
182201

183202
if (!omitPull) {
203+
this.log.debug(`Pulling image: ${containerNameAndTag}`);
184204
await this.pullContainerImage(containerNameAndTag);
185205
}
186206

@@ -217,8 +237,21 @@ export class QuorumTestLedger implements ITestLedger {
217237
eventEmitter.once("start", async (container: Container) => {
218238
this.container = container;
219239
this.containerId = container.id;
240+
241+
this.log.debug("Quorum Test Ledger container started booting OK.");
242+
243+
if (this.emitContainerLogs) {
244+
const logOptions = { follow: true, stderr: true, stdout: true };
245+
const logStream = await container.logs(logOptions);
246+
logStream.on("data", (data: Buffer) => {
247+
const fnTag = `[${this.getContainerImageName()}]`;
248+
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
249+
});
250+
}
251+
220252
try {
221253
await this.waitForHealthCheck();
254+
this.log.debug("Quorum Test Ledger container passed healthcheck OK");
222255
resolve(container);
223256
} catch (ex) {
224257
reject(ex);

0 commit comments

Comments
 (0)