Skip to content

Commit

Permalink
docs(examples): fix supply chain app container image hyperledger-cact…
Browse files Browse the repository at this point in the history
…i#1312

Also published as a container image on ghcr.io as:
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-09-08--docs-1312

Fixes hyperledger-cacti#1312

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Sep 14, 2021
1 parent 1f6ea5f commit 86c0e81
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 118 deletions.
22 changes: 22 additions & 0 deletions .vscode/template.launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
"console": "integratedTerminal",
"sourceMaps": true,
"cwd": "${workspaceRoot}"
},
{
"name": "Example: Supply Chain App",
"type": "node",
"request": "launch",
"protocol": "inspector",
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.json"
},
"args": [
"../cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app-cli.ts",
"dotenv_config_path=process.env"
],
"runtimeArgs": [
"-r",
"ts-node/register",
"-r",
"dotenv/config"
],
"console": "integratedTerminal",
"sourceMaps": true,
"cwd": "${workspaceFolder}/examples/supply-chain-app/"
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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-20--fix-720
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-09-08--docs-1312
```
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class SupplyChainAppDummyInfrastructure {

this.besu = new BesuTestLedger({
logLevel: level,
emitContainerLogs: true,
});
this.quorum = new QuorumTestLedger({
logLevel: level,
Expand Down Expand Up @@ -150,11 +151,9 @@ export class SupplyChainAppDummyInfrastructure {
public async start(): Promise<void> {
try {
this.log.info(`Starting dummy infrastructure...`);
await Promise.all([
this.besu.start(),
this.quorum.start(),
this.fabric.start(),
]);
await this.fabric.start();
await this.besu.start();
await this.quorum.start();
this.log.info(`Started dummy infrastructure OK`);
} catch (ex) {
this.log.error(`Starting of dummy infrastructure crashed: `, ex);
Expand All @@ -172,11 +171,11 @@ export class SupplyChainAppDummyInfrastructure {

await this.keychain.set(
BookshelfRepositoryJSON.contractName,
BookshelfRepositoryJSON.contractName,
JSON.stringify(BookshelfRepositoryJSON),
);
await this.keychain.set(
BambooHarvestRepositoryJSON.contractName,
BambooHarvestRepositoryJSON.contractName,
JSON.stringify(BambooHarvestRepositoryJSON),
);
{
this._quorumAccount = await this.quorum.createEthTestAccount(2000000);
Expand Down
68 changes: 9 additions & 59 deletions examples/supply-chain-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
FROM node:16.3.0-buster-slim as builder

RUN apt-get update
RUN apt-get -y upgrade

# Generic dependencies that are usually needed by other software
RUN apt-get install -y build-essential libssl-dev libffi-dev python3-dev

# Need git because some of our npm depedencies might be coming
# straight from github instead of being an npm package on npmjs.com.
RUN apt-get install -y git

# Need OpenJDK for the OpenAPI generator tool
ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /opt
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& curl \
-L \
-o openjdk.tar.gz \
https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz \
&& mkdir jdk \
&& tar zxf openjdk.tar.gz -C jdk --strip-components=1 \
&& rm -rf openjdk.tar.gz \
&& ln -sf /opt/jdk/bin/* /usr/local/bin/ \
&& java --version \
&& javac --version \
&& jlink --version

# Some install scripts of the npm package fabric-network need python/pip
RUN apt-get install -y python3-pip

WORKDIR /
RUN mkdir /app/
WORKDIR /app/
COPY ./ ./
RUN npm ci
RUN ./node_modules/.bin/lerna clean --yes
RUN ./node_modules/.bin/lerna bootstrap
RUN npm rebuild
RUN npm run build:dev:backend
RUN npm run webpack:dev:web
RUN npm run build:dev:frontend -- --scope='@hyperledger/cactus-example-supply-chain-frontend'

RUN rm -rf ./packages/cactus-test-plugin*
RUN rm -rf ./packages/cactus-test-cmd*
RUN rm -rf ./packages/cactus-test-api*
RUN rm -rf ./node_modules/

FROM cruizba/ubuntu-dind:19.03.11 as runner

USER root
Expand All @@ -76,22 +24,23 @@ RUN useradd -m ${APP_USER}
RUN usermod -a -G ${APP_USER} ${APP_USER}
RUN mkdir -p ${APP}

COPY --chown=$APP_USER:$APP_USER --from=builder /app/ ${APP}

RUN mkdir -p "${APP}/log/"
RUN chown -R $APP_USER:$APP_USER "${APP}/log/"
RUN chown -R $APP_USER:$APP_USER "${APP}/"

# TODO: Can we hack it together so that the whole thing works rootless?
USER ${APP_USER}
WORKDIR ${APP}

SHELL ["/bin/bash", "--login", "-i", "-c"]

# Installing Node Version Manager (nvm)
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
RUN source ~/.bashrc && nvm install 16.3.0
RUN source ~/.bashrc && \
nvm install 16.8.0 && \
npm install -g yarn && \
yarn add @hyperledger/cactus-example-supply-chain-backend@0.9.1-docs-1312.bcfd3c31.6+bcfd3c31 --ignore-engines --production

SHELL ["/bin/bash", "--login", "-c"]

WORKDIR ${APP}

COPY --chown=${APP_USER}:${APP_USER} ./examples/supply-chain-app/healthcheck.sh /

Expand All @@ -100,7 +49,7 @@ ENV AUTHORIZATION_PROTOCOL=NONE
ENV CACTUS_NODE_ID=-
ENV CONSORTIUM_ID=-
ENV KEY_PAIR_PEM=-
ENV COCKPIT_WWW_ROOT=examples/cactus-example-supply-chain-frontend/www/
ENV COCKPIT_WWW_ROOT=/usr/src/app/node_modules/@hyperledger/cactus-example-supply-chain-frontend/www/
ENV COCKPIT_TLS_ENABLED=false
ENV COCKPIT_CORS_DOMAIN_CSV=\*
ENV COCKPIT_MTLS_ENABLED=false
Expand All @@ -117,6 +66,7 @@ ENV API_TLS_CLIENT_CA_PEM=-
ENV API_TLS_KEY_PEM=-
ENV API_HOST=0.0.0.0
ENV API_PORT=4000
ENV GRPC_TLS_ENABLED=false
ENV LOG_LEVEL=TRACE

COPY examples/supply-chain-app/supervisord.conf /etc/supervisord.conf
Expand Down
30 changes: 23 additions & 7 deletions 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-20--fix-720
ghcr.io/hyperledger/cactus-example-supply-chain-app:2021-09-08--docs-1312
```
2. Observe the example application pulling up in the logs
1. the test ledger containers,
Expand All @@ -38,11 +38,27 @@ DOCKER_BUILDKIT=1 docker build -f ./examples/supply-chain-app/Dockerfile . -t sc
docker run --rm -it --privileged -p 3000:3000 -p 3100:3100 -p 3200:3200 -p 4000:4000 -p 4100:4100 -p 4200:4200 scaeb
```

## Configuring and running the example as a process
## Running the Example Application Locally

1. If the `cactus-example-supply-chain-frontend` is in another directory from the default or need expose the API in another port, check the `process.env`
2. Execute the following command:
> Make sure you have all the dependencies set up as explained in `BUILD.md`

```
npm run start
```
On the terminal, issue the following commands:

1. `npm run install-yarn`
2. `yarn configure`
3. `yarn start:example-supply-chain`

## Debugging the Example Application Locally

On the terminal, issue the following commands (steps 1 to 6) and then perform the rest of the steps manually.

1. `npm run install-yarn`
2. `yarn configure`
3. `yarn build:dev`
4. `cd ./examples/supply-chain-app/`
5. `yarn --no-lockfile`
6. `cd ../../`
7. Locate the `.vscode/template.launch.json` file
8. Within that file locate the entry named `"Example: Supply Chain App"`
9. Copy the VSCode debug definition object from 2) to your `.vscode/launch.json` file
10. At this point the VSCode `Run and Debug` panel on the left should have an option also titled `"Example: Supply Chain App"` which
2 changes: 1 addition & 1 deletion examples/supply-chain-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.2.0",
"description": "An example project demonstrating how Cactus can be used for cross-chain dapp development.",
"scripts": {
"start": "node -r dotenv/config ./node_modules/.bin/cactus-example-supply-chain-backend dotenv_config_path=process.env",
"start": "node -r dotenv/config node_modules/@hyperledger/cactus-example-supply-chain-backend/dist/lib/main/typescript/supply-chain-app-cli.js dotenv_config_path=process.env",
"start-direct": "node ./node_modules/@hyperledger/cactus-example-supply-chain-backend/dist/lib/main/typescript/supply-chain-app-cli.js"
},
"private": true,
Expand Down
4 changes: 3 additions & 1 deletion examples/supply-chain-app/process.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ API_TLS_CLIENT_CA_PEM=-
API_TLS_KEY_PEM=-
API_HOST=0.0.0.0
API_PORT=4000
LOG_LEVEL=DEBUG
GRPC_TLS_ENABLED=false
LOG_LEVEL=TRACE
AUTHORIZATION_PROTOCOL=NONE
AUTHORIZATION_CONFIG_JSON="{}"
4 changes: 3 additions & 1 deletion examples/supply-chain-app/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ loglevel = info
command=/usr/local/bin/dockerd
autostart=true
autorestart=true
startretries=20
stderr_logfile=/usr/src/app/log/dockerd.err.log
stdout_logfile=/usr/src/app/log/dockerd.out.log

[program:supply-chain-app]
command=/home/appuser/.nvm/versions/node/v16.3.0/bin/node /usr/src/app/examples/cactus-example-supply-chain-backend/dist/lib/main/typescript/supply-chain-app-cli.js
command=/home/appuser/.nvm/versions/node/v16.8.0/bin/node /usr/src/app/node_modules/@hyperledger/cactus-example-supply-chain-backend/dist/lib/main/typescript/supply-chain-app-cli.js
autostart=true
autorestart=unexpected
startretries=20
exitcodes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"custom-checks": "TS_NODE_PROJECT=./tools/tsconfig.json node --trace-deprecation --experimental-modules --abort-on-uncaught-exception --loader ts-node/esm --experimental-specifier-resolution=node ./tools/custom-checks/run-custom-checks.ts",
"generate-api-server-config": "node ./tools/generate-api-server-config.js",
"start:api-server": "node ./packages/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js --config-file=.config.json",
"start:example-supply-chain": "cd ./examples/supply-chain-app/ && npm i --no-package-lock && npm run start",
"start:example-supply-chain": "yarn build:dev && cd ./examples/supply-chain-app/ && yarn --no-lockfile && yarn start",
"start:example-carbon-accounting": "CONFIG_FILE=examples/cactus-example-carbon-accounting-backend/example-config.json node examples/cactus-example-carbon-accounting-backend/dist/lib/main/typescript/carbon-accounting-app-cli.js",
"purge-build-cache": "del-cli .build-cache/*",
"clean": "npm run purge-build-cache && del-cli \"./{packages,examples,extensions}/cactus-*/{dist,.nyc_output,src/main/proto/generated/*,src/main/typescript/generated/proto/protoc-gen-ts/*,src/main/typescript/generated/openapi/typescript-axios/*}\"",
Expand Down
1 change: 1 addition & 0 deletions packages/cactus-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"express-jwt": "6.0.0",
"express-openapi-validator": "4.12.12",
"fs-extra": "10.0.0",
"google-protobuf": "3.18.0-rc.2",
"jose": "1.28.1",
"lmify": "0.3.0",
"node-forge": "0.10.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/cactus-test-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"is-port-reachable": "3.0.0",
"joi": "17.4.2",
"keycloak-admin": "1.14.21",
"lodash": "4.17.21",
"node-ssh": "12.0.0",
"p-retry": "4.6.1",
"run-time-error": "1.4.0",
Expand All @@ -88,6 +89,7 @@
"@types/dockerode": "3.2.7",
"@types/esm": "3.2.0",
"@types/fs-extra": "9.0.12",
"@types/lodash": "4.14.172",
"@types/node-ssh": "7.0.1",
"@types/ssh2": "0.5.47",
"@types/ssh2-streams": "0.1.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class BesuMpTestLedger {
return container;
}
if (!omitPull) {
await Containers.pullImage(this.imageFqn);
await Containers.pullImage(this.imageFqn, {}, this.options.logLevel);
}

const dockerEnvVars: string[] = new Array(...this.envVars).map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,17 @@ export class BesuTestLedger implements ITestLedger {
});
}

public async waitForHealthCheck(timeoutMs = 180000): Promise<void> {
public async waitForHealthCheck(timeoutMs = 360000): Promise<void> {
const fnTag = "BesuTestLedger#waitForHealthCheck()";
// const httpUrl = await this.getRpcApiHttpHost();
const startedAt = Date.now();
let isHealthy = false;
do {
if (Date.now() >= startedAt + timeoutMs) {
throw new Error(`${fnTag} timed out (${timeoutMs}ms)`);
}
const containerInfo = await this.getContainerInfo();
this.log.debug(`ContainerInfo.Status=%o`, containerInfo.Status);
this.log.debug(`ContainerInfo.State=%o`, containerInfo.State);
isHealthy = containerInfo.Status.endsWith("(healthy)");
const { Status, State } = await this.getContainerInfo();
this.log.debug(`ContainerInfo.Status=%o, State=O%`, Status, State);
isHealthy = Status.endsWith("(healthy)");
if (!isHealthy) {
await new Promise((resolve2) => setTimeout(resolve2, 1000));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class CactusKeychainVaultServer {
}
const docker = new Docker();

await Containers.pullImage(this.imageFqn);
await Containers.pullImage(this.imageFqn, {}, this.options.logLevel);

return new Promise<Container>((resolve, reject) => {
const eventEmitter: EventEmitter = docker.run(
Expand Down
Loading

0 comments on commit 86c0e81

Please sign in to comment.