Skip to content

Commit

Permalink
test(test-tooling): migrate AIO image to Fabric v2.5.6, add constants
Browse files Browse the repository at this point in the history
1. The Fabric v2 image has been migrated to the current LTS release
which has increased stability and of course adheres to general best
practices more thoroughly since now we are in sync with the Fabric
maintainers in terms of LTS.
2. The newer versions of the fabric-samples test-net containers have
some of the configuration files under different paths and this had to be
reverse engineered by manually inspecting the containers at runtime and
searching for the same files in different directories. To make this
easier in the future for people who are using the AIO image, we've added
a collection of constants to the test-tooling package that stores the
paths hardcoded that are exported via verbose variable names that pin these
to the specific Fabric version they are related to so that in the future
if these paths change again, we can accommodate the change in a way that
is not too confusing by exporting more variables with slightly different
names and values.
3. The image built from the updated `Dockerfile_v2` is accessible on GHCR
as: `ghcr.io/hyperledger/cactus-fabric2-all-in-one:2024-03-03--issue-2945-fabric-v2-5-6`
which has the v2.5.6 versioned container images pre-cached (embedded) so that
network transfer does not need to occur and rate limiting doesn't produce
CI flakes (DockerHub has rate limits for image downloading that we regularly
hit when we don't embed the Fabric container images this way...).
4. Why can't we just pull the values for these constants directly from the
container at runtime?
4.1. The list of constants and their names/values change based on the
Fabric version that's being used by the AIO image.
4.2. The only ones that could be pulled are the ones that belong to the
first organization because this is the one that the CLI container uses.
4.3. Configuration files that store the constants' values for the second
organization are also located in different directories depending on the
Fabric version being used.
4.4. The fabric-samples repo have been known to make breaking changes
to older releases which would then make it even harder to debug if we
had logic for identifying the constants that suddenly broke (this specific
incident has happened in the past unfortunately)
4.5. In short, there is definitely a case for applying the DRY principle
here, but in this particular case it appears to be not worth it due to
the increased complexity that the convoluted additional logic would bring.

Related but does not fix https://github.com/hyperledger/cacti/issues/1899

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Mar 7, 2024
1 parent 7fd9d7b commit f59f369
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
export interface IFabricOrgEnvInfo extends NodeJS.ProcessEnv {
[key: string]: string | undefined;
readonly CORE_PEER_TLS_ENABLED: string;
readonly CORE_PEER_LOCALMSPID: string;
readonly CORE_PEER_TLS_CERT_FILE: string;
readonly CORE_PEER_TLS_KEY_FILE: string;
readonly CORE_PEER_ADDRESS: string;
readonly CORE_PEER_MSPCONFIGPATH: string;
readonly CORE_PEER_TLS_ROOTCERT_FILE: string;
readonly ORDERER_TLS_ROOTCERT_FILE: string;
}

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_1 = "true";
export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_1 =
"Org1MSP";
export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_1 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_1 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_1 =
"peer0.org1.example.com:7051";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_1 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_1 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt";

export const FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_1 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem";

/**
* Contains the file paths and other configuration parameters (such as flags,
* hostnames etc.) that are a match for what you need to execute peer commands
* from within the "cli" container of the fabric samples test network.
*
* The aforementioned test network ships with 2 organizations by default, this
* is the configuration to make the peer binary talk to the **first** organization.
*
* Important note: The paths are only accurate within the mentioned `cli` container
* as defined in the compose .yaml files describing the test network. Therefore,
* if you have shelled into the Cacti All-in-One Fabric container, these are not
* useful there, instead you need to shell into the nested `cli` container by
* executing something like `docker exec -it cli bash` which will then get you
* to the environment where these paths are representative and useful.
*
* @see https://github.com/hyperledger/fabric-samples
*/
export const FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1: IFabricOrgEnvInfo = {
CORE_PEER_TLS_ENABLED:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_1,
CORE_PEER_LOCALMSPID:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_1,
CORE_PEER_TLS_CERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_1,
CORE_PEER_TLS_KEY_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_1,
CORE_PEER_ADDRESS: FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_1,
CORE_PEER_MSPCONFIGPATH:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_1,
CORE_PEER_TLS_ROOTCERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_1,
ORDERER_TLS_ROOTCERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_1,
};

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_2 = "true";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_2 =
"Org2MSP";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_2 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_2 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_2 =
"peer0.org2.example.com:9051";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_2 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp";

export const FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_2 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt";

export const FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_2 =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem";

/**
* Contains the file paths and other configuration parameters (such as flags,
* hostnames etc.) that are a match for what you need to execute peer commands
* from within the "cli" container of the fabric samples test network.
*
* The aforementioned test network ships with 2 organizations by default, this
* is the configuration to make the peer binary talk to the **second** organization.
*
* Important note: The paths are only accurate within the mentioned `cli` container
* as defined in the compose .yaml files describing the test network. Therefore,
* if you have shelled into the Cacti All-in-One Fabric container, these are not
* useful there, instead you need to shell into the nested `cli` container by
* executing something like `docker exec -it cli bash` which will then get you
* to the environment where these paths are representative and useful.
*
* @see https://github.com/hyperledger/fabric-samples
*/
export const FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2: IFabricOrgEnvInfo = {
CORE_PEER_TLS_ENABLED:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_2,
CORE_PEER_LOCALMSPID:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_2,
CORE_PEER_TLS_CERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_2,
CORE_PEER_TLS_KEY_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_2,
CORE_PEER_ADDRESS: FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_2,
CORE_PEER_MSPCONFIGPATH:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_2,
CORE_PEER_TLS_ROOTCERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_2,
ORDERER_TLS_ROOTCERT_FILE:
FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_2,
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export const DEFAULT_FABRIC_2_AIO_IMAGE_NAME =
export const DEFAULT_FABRIC_2_AIO_IMAGE_VERSION = "2023-08-17-issue2057-pr2135";
export const DEFAULT_FABRIC_2_AIO_FABRIC_VERSION = "2.4.4";

export const FABRIC_25_LTS_AIO_IMAGE_VERSION =
"2024-03-03--issue-2945-fabric-v2-5-6";
export const FABRIC_25_LTS_AIO_FABRIC_VERSION = "2.5.6";

/*
* Provides default options for Fabric container
*/
Expand Down
24 changes: 24 additions & 0 deletions packages/cactus-test-tooling/src/main/typescript/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export {
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FABRIC_25_LTS_AIO_FABRIC_VERSION,
FABRIC_25_LTS_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
IFabricTestLedgerV1ConstructorOptions,
FABRIC_TEST_LEDGER_DEFAULT_OPTIONS,
Expand Down Expand Up @@ -193,3 +195,25 @@ export { envNodeToDocker } from "./common/env-node-to-docker";
export { envMapToDocker } from "./common/env-map-to-docker";
export { envNodeToMap } from "./common/env-node-to-map";
export * as SocketIOTestSetupHelpers from "./socketio-test-setup-helpers/socketio-test-setup-helpers";

export {
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_ADDRESS_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_LOCALMSPID_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_MSPCONFIGPATH_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_CERT_FILE_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ENABLED_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_KEY_FILE_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__CORE_PEER_TLS_ROOTCERT_FILE_ORG_2,
FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES__ORDERER_TLS_ROOTCERT_FILE_ORG_2,
IFabricOrgEnvInfo,
} from "./fabric/fabric-samples-env-constants";
12 changes: 10 additions & 2 deletions tools/docker/fabric-all-in-one/Dockerfile_v2.x
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM docker:24.0.5-dind

ARG FABRIC_VERSION=2.4.4
ARG FABRIC_NODEENV_VERSION=2.4.2
ARG FABRIC_VERSION=2.5.6
ARG FABRIC_NODEENV_VERSION=2.5.4
ARG CA_VERSION=1.5.3
ARG COUCH_VERSION_FABRIC=0.4
ARG COUCH_VERSION=3.2.2
Expand Down Expand Up @@ -172,9 +172,16 @@ RUN /bootstrap.sh ${FABRIC_VERSION} ${CA_VERSION} -d
# But we need at least NodeJS 16 and npm v7 for the dependency installation to work.
RUN sed -i "s/fabric-nodeenv:\$(TWO_DIGIT_VERSION)/fabric-nodeenv:${FABRIC_NODEENV_VERSION}/g" /fabric-samples/test-network/compose/docker/peercfg/core.yaml
RUN yq '.chaincode.logging.level = "debug"' \
--inplace /fabric-samples/test-network/compose/docker/peercfg/core.yaml
# Set the log level of the peers and other containers to DEBUG instead of the default INFO
RUN sed -i "s/FABRIC_LOGGING_SPEC=INFO/FABRIC_LOGGING_SPEC=DEBUG/g" /fabric-samples/test-network/compose/docker/docker-compose-test-net.yaml
# For now this cannot be used because it mangles the outupt of the "peer lifecycle chaincode queryinstalled" commands.
# We need to refactor those commands in the deployment endpoints so that they are immune to this logging setting.
# RUN sed -i "s/FABRIC_LOGGING_SPEC=INFO/FABRIC_LOGGING_SPEC=DEBUG/g" /fabric-samples/test-network/compose/compose-test-net.yaml
# Update the docker-compose file of the fabric-samples repo so that the
# core.yaml configuration file of the peer containers can be customized.
# We need the above because we need to override the NodeJS version the peers are
Expand All @@ -191,6 +198,7 @@ RUN yq '.services."peer0.org2.example.com".volumes += "../..:/opt/gopath/src/git
RUN yq '.services."peer0.org2.example.com".volumes += "../../config/core.yaml:/etc/hyperledger/fabric/core.yaml"' \
--inplace /fabric-samples/test-network/compose/docker/docker-compose-test-net.yaml
# Install supervisord because we need to run the docker daemon and also the fabric network
# meaning that we have multiple processes to run.
RUN apk add --no-cache supervisor
Expand Down

1 comment on commit f59f369

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 0.05.

Benchmark suite Current: f59f369 Previous: 7fd9d7b Ratio
cmd-api-server_HTTP_GET_getOpenApiSpecV1 623 ops/sec (±1.67%) 613 ops/sec (±1.68%) 0.98
cmd-api-server_gRPC_GetOpenApiSpecV1 397 ops/sec (±1.55%) 377 ops/sec (±1.47%) 0.95

This comment was automatically generated by workflow using github-action-benchmark.

CC: @petermetz

Please sign in to comment.