Skip to content

Commit

Permalink
ci(tools/docker): stop compiling Iroha as part of the all-in-one imag…
Browse files Browse the repository at this point in the history
…e build

1. Upgraded the Iroha AIO image to use v1.4.0-patch-3
2. The new Iroha version now supports configuraton via ENV variables
3. Because of 2) we don't need to apply config file changes in the
entrypoint script of the container anymore, yay.
4. The new image uses the iroha release image as the base and  it
does NOT recompile the entire project which makes the build
orders of magnitude faster, wasting much less CI time/resources.
5. Exposed the healthcheck port for through the IrohaTestLedger class
so the other improvement we'll be able to do after this is to phase out
the hacky python script that does the healthcheck at the moment if
the new built-in healthcheck endpoint does actually work fine.
6. Migrated all the test cases to the new image version.

Fixes hyperledger#2524

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz authored and sandeepnRES committed Dec 21, 2023
1 parent 6741b0b commit 0662cf1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
// Constants
//////////////////////////////////

import { IROHA_TEST_LEDGER_DEFAULT_OPTIONS } from "@hyperledger/cactus-test-tooling";

// Ledger settings
const ledgerImageName = "ghcr.io/hyperledger/cactus-iroha-all-in-one";
const ledgerImageVersion = "2021-08-16--1183";
const ledgerImageVersion = IROHA_TEST_LEDGER_DEFAULT_OPTIONS.imageVersion;
const postgresImageName = "postgres";
const postgresImageVersion = "9.5-alpine";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import cryptoHelper from "iroha-helpers/lib/cryptoHelper";
import { Constants } from "@hyperledger/cactus-core-api";

const testCase = "runs tx on an Iroha v1.2.0 ledger";
const testCase = "runs tx on an Iroha v1.4.0-patch-3 ledger";
const logLevel: LogLevelDesc = "INFO";

test.onFailure(async () => {
Expand Down Expand Up @@ -87,7 +87,7 @@ test(testCase, async (t: Test) => {
test.onFinish(async () => {
await iroha.stop();
});
await iroha.start();
await iroha.start(false);
const irohaPort = await iroha.getRpcToriiPort();
const rpcToriiPortHost = await iroha.getRpcToriiPortHost();
const rpcApiWsHost = await iroha.getRpcApiWsHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,45 @@ export interface IIrohaTestLedgerOptions {
readonly logLevel?: LogLevelDesc;
readonly emitContainerLogs?: boolean;
readonly rpcApiWsPort?: number;
readonly healthcheckPort?: number;
}

/*
* Provides default options for Iroha container
*/
export const IROHA_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({
imageVersion: "2021-08-16--1183",
imageVersion: "2023-07-17-issue-2524",
imageName: "ghcr.io/hyperledger/cactus-iroha-all-in-one",
adminPriv: " ",
adminPub: " ",
nodePriv: " ",
nodePub: " ",
tlsCert: " ",
tlsKey: " ",
healthcheckPort: 50508,
rpcToriiPort: 50051,
toriiTlsPort: 55552,
envVars: [
"IROHA_MST_EXPIRATION_TIME=1440",
"IROHA_MST_ENABLE=false",
"IROHA_HEALTHCHECK_PORT=50508",
"IROHA_PROPOSAL_CREATION_TIMEOUT=3000",
"IROHA_VOTE_DELAY=5000",
"IROHA_PROPOSAL_DELAY=5000",
"IROHA_MAX_PROPOSAL_SIZE=10",
"IROHA_DATABASE_TYPE=postgres",
"IROHA_INTER_PEER_TLS_KEY_PAIR_PATH=/opt/iroha_data/node0",
"IROHA_TORII_TLS_PARAMS_PORT=55552",
"IROHA_INTERNAL_PORT=10001",
"IROHA_BLOCK_STORE_PATH=/tmp/block_store/",
"IROHA_TORII_PORT=50051",
"IROHA_LOG_LEVEL=info",
"IROHA_POSTGRES_USER=postgres",
"IROHA_POSTGRES_PASSWORD=my-secret-password",
"IROHA_DATABASE_USER=postgres",
"IROHA_DATABASE_PASSWORD=my-secret-password",
"IROHA_DATABASE_WORKING DATABASE=iroha_default",
"IROHA_DATABASE_MAINTENANCE DATABASE=postgres",
"KEY=node0",
],
rpcApiWsPort: 50052,
Expand All @@ -67,6 +87,9 @@ export const IROHA_TEST_LEDGER_OPTIONS_JOI_SCHEMA: Joi.Schema = Joi.object().key
nodePub: Joi.string().min(1).max(64).required(),
tlsCert: Joi.string().min(1).required(),
tlsKey: Joi.string().min(1).required(),
healthcheckPort: Joi.number()
.port()
.default(IROHA_TEST_LEDGER_DEFAULT_OPTIONS.healthcheckPort),
toriiTlsPort: Joi.number().port().required(),
postgresPort: Joi.number().port().required(),
postgresHost: Joi.string().hostname().required(),
Expand All @@ -92,6 +115,7 @@ export class IrohaTestLedger implements ITestLedger {
public readonly rpcApiWsPort: number;
public readonly tlsCert?: string;
public readonly tlsKey?: string;
public readonly healthcheckPort?: number;
public readonly toriiTlsPort?: number;

private readonly log: Logger;
Expand Down Expand Up @@ -131,6 +155,12 @@ export class IrohaTestLedger implements ITestLedger {
options.toriiTlsPort || IROHA_TEST_LEDGER_DEFAULT_OPTIONS.toriiTlsPort;
this.rpcApiWsPort =
options.rpcApiWsPort || IROHA_TEST_LEDGER_DEFAULT_OPTIONS.rpcApiWsPort;
this.healthcheckPort =
options.healthcheckPort ||
IROHA_TEST_LEDGER_DEFAULT_OPTIONS.healthcheckPort;

this.envVars.push(`IROHA_DATABASE_HOST=${this.postgresHost}`);
this.envVars.push(`IROHA_DATABASE_PORT=${this.postgresPort}`);

this.envVars.push(`IROHA_POSTGRES_HOST=${this.postgresHost}`);
this.envVars.push(`IROHA_POSTGRES_PORT=${this.postgresPort}`);
Expand Down Expand Up @@ -295,6 +325,7 @@ export class IrohaTestLedger implements ITestLedger {
[`${this.rpcToriiPort}/tcp`]: {}, // Iroha RPC - Torii
[`${this.toriiTlsPort}/tcp`]: {}, // Iroha TLS RPC
[`${this.rpcApiWsPort}/tcp`]: {}, // Iroha RPC WS
[`${this.healthcheckPort}/tcp`]: {}, // Iroha Healthcheck Service
},
Env: this.envVars,
Healthcheck: {
Expand Down
38 changes: 11 additions & 27 deletions tools/docker/iroha-all-in-one/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
FROM ubuntu:20.04 as builder
ARG DEBIAN_FRONTEND=noninteractive
FROM hyperledger/iroha:1.4.0-patch-3

RUN set -e && apt-get update && apt-get install -y --no-install-recommends \
file build-essential ninja-build ca-certificates tar curl unzip cmake pkg-config zip software-properties-common

RUN add-apt-repository ppa:git-core/ppa
RUN apt-get update
RUN apt-get install -y --no-install-recommends git

RUN git clone https://github.com/hyperledger/iroha.git -b 1.4.0
RUN iroha/vcpkg/build_iroha_deps.sh
RUN /vcpkg-build/vcpkg integrate install
WORKDIR /iroha/build/

RUN cmake -DCMAKE_TOOLCHAIN_FILE=/vcpkg-build/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TYPE=Release -DPACKAGE_DEB=ON -G "Ninja" ..
RUN cmake --build . --target package -- -j$(nproc)

FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN set -e && apt-get update && \
apt-get install -y moreutils jq python3 python3-pip && \
apt-get install -y moreutils jq wget python3 python3-pip && \
pip install iroha && \
apt-get purge -y `apt-get -s purge python3-pip | grep '^ ' | tr -d '*'` && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/*
# irohad is the core of Iroha ledger
COPY --from=builder /iroha/build/bin/irohad /usr/bin/irohad
# copying iroha-cli optional; only copied for debugging purpose
COPY --from=builder /iroha/build/bin/iroha-cli /usr/bin/iroha-cli
# files below are necessary
COPY --from=builder /iroha/example/ /opt/iroha_data/
COPY --from=builder /iroha/docker/release/wait-for-it.sh /

COPY genesis.block /opt/iroha_data/genesis.block
COPY entrypoint.sh healthcheck.py /
RUN chmod +x /entrypoint.sh /wait-for-it.sh
RUN chmod +x /entrypoint.sh

WORKDIR /opt/iroha_data

RUN wget https://github.com/hyperledger/iroha/v1.4.0-patch-3/example/admin%40test.pub --output-document=admin@test.pub
RUN wget https://github.com/hyperledger/iroha/v1.4.0-patch-3/example/admin%40test.priv --output-document=admin@test.priv
RUN wget https://github.com/hyperledger/iroha/v1.4.0-patch-3/example/node0.pub
RUN wget https://github.com/hyperledger/iroha/v1.4.0-patch-3/example/node0.priv

ENTRYPOINT ["/entrypoint.sh"]

CMD ["irohad"]
9 changes: 1 addition & 8 deletions tools/docker/iroha-all-in-one/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env bash
set -e

# sync the local config file with the environment variables for pg opts
export pg_opt_value="host=${IROHA_POSTGRES_HOST} port=${IROHA_POSTGRES_PORT} user=${IROHA_POSTGRES_USER} password=${IROHA_POSTGRES_PASSWORD}"

if [ ! $ADMIN_PRIV = *" "* ] && [ -n "$ADMIN_PRIV" ]; then
sed -i "1s/.*/$ADMIN_PRIV/" admin@test.priv
fi
Expand All @@ -26,10 +23,6 @@ if [ ! $NODE_PUB = *" "* ] && [ -n "$NODE_PUB" ]; then
genesis.block|sponge genesis.block
fi

jq --arg pg_opt "${pg_opt_value}" \
'.pg_opt = $pg_opt' \
config.docker|sponge config.docker

# if first arg looks like a flag, assume we want to run irohad server
if [ "${1:0:1}" = '-' ]; then
set -- irohad "$@"
Expand All @@ -46,7 +39,7 @@ if [ "$1" = 'irohad' ]; then
echo "WARNING: IROHA_POSTGRES_HOST is not defined.
Do not wait for Postgres to become ready. Iroha may fail to start up"
fi
exec "$@" --genesis_block genesis.block --config config.docker --keypair_name $KEY
exec "$@" --genesis_block genesis.block --keypair_name $KEY --verbosity=${IROHA_LOG_LEVEL}
fi

exec "$@"

0 comments on commit 0662cf1

Please sign in to comment.