Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): increase supply chain image boot responsiveness #780 #1152

Merged
merged 7 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ As blockchain technology proliferates, blockchain integration will become an inc

### Supply Chain Example

1. Run the following command to pull up the container that will run the example application and the test ledgers as well:
1. Ensure a working installation of [Docker](https://docs.docker.com/desktop/) is present on your machine.
2. Run the following command to pull up the container that will run the example application and the test ledgers as well:
```sh
docker run \
--rm \
Expand All @@ -30,11 +31,11 @@ As blockchain technology proliferates, blockchain integration will become an inc
-p 4000:4000 \
-p 4100:4100 \
-p 4200:4200 \
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-01--fix-1063-v2
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-20--fix-720
```
2. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3100`
3. Visit http://localhost:3100 in a web browser with Javascript enabled
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.
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3100`
4. Visit http://localhost:3100 in a web browser with Javascript enabled
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.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ export class SupplyChainAppDummyInfrastructure {
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });

this.besu = new BesuTestLedger();
this.quorum = new QuorumTestLedger();
this.besu = new BesuTestLedger({
logLevel: level,
});
this.quorum = new QuorumTestLedger({
logLevel: level,
emitContainerLogs: true,
});
this.fabric = new FabricTestLedgerV1({
publishAllPorts: true,
imageName: "ghcr.io/hyperledger/cactus-fabric-all-in-one",
imageVersion: "2021-03-02-ssh-hotfix",
logLevel: level,
emitContainerLogs: true,
});

if (this.options.keychain) {
Expand Down
2 changes: 1 addition & 1 deletion examples/supply-chain-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-p 4000:4000 \
-p 4100:4100 \
-p 4200:4200 \
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-01--fix-1063-v2
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-07-20--fix-720
```
2. Observe the example application pulling up in the logs
1. the test ledger containers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
LogLevelDesc,
Logger,
LoggerProvider,
Bools,
} from "@hyperledger/cactus-common";
import { ITestLedger } from "../i-test-ledger";
import { Streams } from "../common/streams";
Expand All @@ -22,6 +23,7 @@ export interface IBesuTestLedgerConstructorOptions {
rpcApiWsPort?: number;
envVars?: string[];
logLevel?: LogLevelDesc;
emitContainerLogs?: boolean;
}

export const BESU_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({
Expand Down Expand Up @@ -52,6 +54,7 @@ export class BesuTestLedger implements ITestLedger {
public readonly rpcApiHttpPort: number;
public readonly rpcApiWsPort: number;
public readonly envVars: string[];
public readonly emitContainerLogs: boolean;

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

this.emitContainerLogs = Bools.isBooleanStrict(options.emitContainerLogs)
? (options.emitContainerLogs as boolean)
: true;

this.validateConstructorOptions();
const label = "besu-test-ledger";
const level = options.logLevel || "INFO";
Expand Down Expand Up @@ -255,6 +262,16 @@ export class BesuTestLedger implements ITestLedger {
this.log.debug(`Started container OK. Waiting for healthcheck...`);
this.container = container;
this.containerId = container.id;

if (this.emitContainerLogs) {
const logOptions = { follow: true, stderr: true, stdout: true };
const logStream = await container.logs(logOptions);
logStream.on("data", (data: Buffer) => {
const fnTag = `[${this.getContainerImageName()}]`;
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
});
}

try {
await this.waitForHealthCheck();
this.log.debug(`Healthcheck passing OK.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import Joi from "joi";
import tar from "tar-stream";
import Web3 from "web3";
import { Account } from "web3-core";
import {
Bools,
Logger,
LoggerProvider,
LogLevelDesc,
} from "@hyperledger/cactus-common";
import { ITestLedger } from "../i-test-ledger";
import { Streams } from "../common/streams";
import { IKeyPair } from "../i-key-pair";
Expand All @@ -15,6 +21,8 @@ export interface IQuorumTestLedgerConstructorOptions {
containerImageVersion?: string;
containerImageName?: string;
rpcApiHttpPort?: number;
logLevel?: LogLevelDesc;
emitContainerLogs?: boolean;
}

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

private readonly log: Logger;
private container: Container | undefined;
private containerId: string | undefined;

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

this.emitContainerLogs = Bools.isBooleanStrict(options.emitContainerLogs)
? (options.emitContainerLogs as boolean)
: true;

this.validateConstructorOptions();

const label = "quorum-test-ledger";
const level = options.logLevel || "INFO";
this.log = LoggerProvider.getOrCreate({ level, label });
}

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

this.log.debug(`Starting Quorum Test Ledger: ${containerNameAndTag}`);
if (this.container) {
await this.container.stop();
await this.container.remove();
}
const docker = new Docker();

if (!omitPull) {
this.log.debug(`Pulling image: ${containerNameAndTag}`);
await this.pullContainerImage(containerNameAndTag);
}

Expand Down Expand Up @@ -217,8 +237,21 @@ export class QuorumTestLedger implements ITestLedger {
eventEmitter.once("start", async (container: Container) => {
this.container = container;
this.containerId = container.id;

this.log.debug("Quorum Test Ledger container started booting OK.");

if (this.emitContainerLogs) {
const logOptions = { follow: true, stderr: true, stdout: true };
const logStream = await container.logs(logOptions);
logStream.on("data", (data: Buffer) => {
const fnTag = `[${this.getContainerImageName()}]`;
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
});
}

try {
await this.waitForHealthCheck();
this.log.debug("Quorum Test Ledger container passed healthcheck OK");
resolve(container);
} catch (ex) {
reject(ex);
Expand Down