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

fix(satp-hermes): update docker image for the new logging implementation to database and postgres test case #3729

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 0 additions & 15 deletions packages/cactus-plugin-satp-hermes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,3 @@ services:
- 3010:3010/tcp # SERVER_PORT
- 3011:3011/tcp # CLIENT_PORT
- 4010:4010/tcp # API_PORT
db:
image: postgres:13
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_HOST: ${DB_HOST}
PGPORT: ${DB_PORT}
ports:
- "${DB_PORT}:5432"
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata:
17 changes: 13 additions & 4 deletions packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"build:bundle": "ncc build ./dist/lib/main/typescript/plugin-satp-hermes-gateway-cli.js --minify --out=./dist/bundle/ncc/ --external=fabric-common",
"build": "run-s codegen tsc",
"build-proto": "buf build --path src/main/proto --verbose",
"build:dev:backend:postbuild": "mkdir -p ./dist/lib/knex && cp -r ./src/knex/* ./dist/lib/knex",
"build:dev:backend:postbuild": "",
"bundle-openapi-json": "swagger-cli bundle ./src/main/yml/bol/openapi-blo.yml -o ./src/main/json/openapi-blo-bundled.json -r -t json",
"bundle-openapi-yaml": "swagger-cli bundle ./src/main/yml/bol/openapi-blo.yml -o ./src/main/yml/bol/openapi-blo-bundled.yml -r -t yaml",
"codegen": "run-p 'codegen:*'",
Expand Down Expand Up @@ -95,7 +95,13 @@
"db:migrate": "knex migrate:latest --knexfile src/knex/knexfile.js",
"db:migrate:production": "knex migrate:latest --env production --knexfile src/knex/knexfile.ts",
"db:seed": "knex seed:run --knexfile src/knex/knexfile.ts",
"db:cleanup": "find src/knex/ -name '.dev.local-*.sqlite3' -delete"
"db:cleanup": "find src/knex/ -name '.dev.local-*.sqlite3' -delete",
"docker:build:stable": "docker build --file ./satp-hermes-gateway.Dockerfile ./ --tag hyperledger/cacti-satp-hermes-gateway:$(node -e \"console.log(require('./package.json').version)\")",
"docker:build:dev": "docker build --file ./satp-hermes-gateway.Dockerfile ./ --tag hyperledger/cacti-satp-hermes-gateway:$(git rev-parse --short HEAD)-$(date +\"%Y-%m-%d\")",
"docker:build:latest": "docker build --file ./satp-hermes-gateway.Dockerfile ./ --tag hyperledger/cacti-satp-hermes-gateway:latest",
"docker:run:stable": "docker run -it hyperledger/cacti-satp-hermes-gateway:$(node -e \"console.log(require('./package.json').version)\")",
"docker:run:dev": "docker run -it hyperledger/cacti-satp-hermes-gateway:$(git rev-parse --short HEAD)-$(date +\"%Y-%m-%d\")",
"docker:compose": "docker compose --project-directory ./ -f ./docker-compose.yml up --build"
},
"jest": {
"moduleNameMapper": {
Expand Down Expand Up @@ -131,6 +137,7 @@
"class-validator": "0.14.1",
"cors": "2.8.5",
"crypto-js": "4.2.0",
"dockerode": "3.3.0",
"dotenv": "16.4.5",
"ethereum-abi-types-generator": "1.3.4",
"ethers": "6.13.1",
Expand All @@ -143,6 +150,7 @@
"knex": "2.4.0",
"kubo-rpc-client": "3.0.1",
"node-schedule": "2.1.1",
"node-ssh": "^13.2.0",
"npm-run-all": "4.1.5",
"openzeppelin-solidity": "3.4.2",
"pg": "8.13.1",
Expand All @@ -161,11 +169,12 @@
"@bufbuild/buf": "^1.47.2",
"@bufbuild/protoc-gen-es": "2.2.2",
"@grpc/proto-loader": "0.7.13",
"@hyperledger/cactus-api-client": "2.0.0",
"@hyperledger/cactus-test-geth-ledger": "2.0.0-rc.7",
"@hyperledger/cactus-api-client": "2.1.0",
"@hyperledger/cactus-test-geth-ledger": "2.1.0",
"@quobix/vacuum": "0.9.16",
"@types/body-parser": "1.19.4",
"@types/crypto-js": "4.0.1",
"@types/dockerode": "3.2.7",
"@types/express": "5.0.0",
"@types/fs-extra": "11.0.4",
"@types/google-protobuf": "3.15.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ RUN apt-get remove -y --allow-remove-essential perl perl-base && apt-get autorem

ARG APP_DIR=/opt/cacti/satp-hermes
WORKDIR ${APP_DIR}
RUN mkdir -p /opt/cacti/satp-hermes/log/
RUN mkdir -p ${APP_DIR}/log/

COPY ./dist/bundle/ncc/ ${APP_DIR}
COPY ./satp-hermes-gateway.Dockerfile.healthcheck.mjs ${APP_DIR}
COPY ./gateway-config.json /gateway-config.json
COPY ./src/knex/ ${APP_DIR}/src/knex/

COPY ./dist/lib/main/typescript/knex/migrations/*.js ${APP_DIR}/migrations/
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ./supervisord.conf /etc/supervisord.conf

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Knex } from "knex";

export function validateKnexRepositoryConfig(opts: {
readonly configValue: unknown;
}): Knex.Config | undefined {
if (!opts || !opts.configValue) {
return undefined;
}

if (opts.configValue === null) {
return undefined;
}

if (typeof opts.configValue !== "object") {
throw new Error(
`Configuration must be an object: ${JSON.stringify(opts.configValue)}`,
);
}

const config = opts.configValue as Knex.Config;

// Validate 'client' property
if (!config.client || typeof config.client !== "string") {
throw new Error(
`Invalid or missing 'client' property: ${JSON.stringify(config)}`,
);
}

// Validate 'connection' property
if (!config.connection) {
throw new Error(`Missing 'connection' property: ${JSON.stringify(config)}`);
}

if (typeof config.connection === "string") {
// If connection is a string, ensure it's not empty
if (config.connection.trim() === "") {
throw new Error(
`Connection string cannot be empty: ${JSON.stringify(config)}`,
);
}
} else if (typeof config.connection === "object") {
// Validate connection object based on client type
const connection = config.connection as any;

switch (config.client) {
case "sqlite3":
if (!connection.filename || typeof connection.filename !== "string") {
throw new Error(
`Invalid or missing 'connection.filename' for sqlite3: ${JSON.stringify(config)}`,
);
}
break;
case "mysql":
case "mysql2":
case "pg":
case "oracledb":
case "mssql":
if (!connection.host || typeof connection.host !== "string") {
throw new Error(
`Invalid or missing 'connection.host': ${JSON.stringify(config)}`,
);
}
if (!connection.user || typeof connection.user !== "string") {
throw new Error(
`Invalid or missing 'connection.user': ${JSON.stringify(config)}`,
);
}
if (!connection.password || typeof connection.password !== "string") {
throw new Error(
`Invalid 'connection.password': ${JSON.stringify(config)}`,
);
}
if (!connection.database || typeof connection.database !== "string") {
throw new Error(
`Invalid or missing 'connection.database': ${JSON.stringify(config)}`,
);
}
break;
default:
throw new Error(`Unsupported client type: ${config.client}`);
}
} else {
// Connection is neither a string nor an object
throw new Error(`Invalid 'connection' property: ${JSON.stringify(config)}`);
}

// Validate 'migrations' property if present
if (config.migrations !== undefined) {
if (typeof config.migrations !== "object" || config.migrations === null) {
throw new Error(
`Invalid 'migrations' property: ${JSON.stringify(config)}`,
);
} else {
if (
config.migrations.directory !== undefined &&
typeof config.migrations.directory !== "string"
) {
throw new Error(
`Invalid 'migrations.directory' property: ${JSON.stringify(config)}`,
);
}
if (
config.migrations.tableName !== undefined &&
typeof config.migrations.tableName !== "string"
) {
throw new Error(
`Invalid 'migrations.tableName' property: ${JSON.stringify(config)}`,
);
}
}
}

// Validate 'useNullAsDefault' property if present
if (
config.useNullAsDefault !== undefined &&
typeof config.useNullAsDefault !== "boolean"
) {
throw new Error(
`Invalid 'useNullAsDefault' property; it must be a boolean: ${JSON.stringify(config)}`,
);
}

// Additional validation can be added here as needed

return config;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function validateSatpEnableCrashRecovery(opts: {
readonly configValue: unknown;
}): boolean {
if (!opts || opts.configValue === undefined) {
return false;
}

if (typeof opts.configValue !== "boolean") {
throw new TypeError(
`Invalid config.enableCrashRecovery: ${opts.configValue}. Expected a boolean`,
);
}
return opts.configValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class Stage0ClientService extends SATPService {
session.verify(fnTag, SessionType.CLIENT);
const sessionData = session.getClientSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -266,7 +265,6 @@ export class Stage0ClientService extends SATPService {
session.verify(fnTag, SessionType.CLIENT);

const sessionData = session.getClientSessionData();
this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -378,7 +376,6 @@ export class Stage0ClientService extends SATPService {
session.verify(fnTag, SessionType.CLIENT);

const sessionData = session.getClientSessionData();
this.Log.info(`init-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token-client",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class Stage1ClientService extends SATPService {

const sessionData = session.getClientSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -262,7 +261,6 @@ export class Stage1ClientService extends SATPService {

const sessionData = session.getClientSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ export class Stage0ServerService extends SATPService {
}
const sessionData = session.getServerSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -429,7 +428,6 @@ export class Stage0ServerService extends SATPService {

const sessionData = session.getServerSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -514,7 +512,6 @@ export class Stage0ServerService extends SATPService {
}

const sessionData = session.getServerSessionData();
this.Log.info(`init-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token-server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class Stage1ServerService extends SATPService {

const sessionData = session.getServerSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -259,7 +258,6 @@ export class Stage1ServerService extends SATPService {
session.verify(fnTag, SessionType.SERVER);

const sessionData = session.getServerSessionData();
this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class Stage2ServerService extends SATPService {
session.verify(fnTag, SessionType.SERVER);

const sessionData = session.getServerSessionData();
this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand All @@ -75,7 +74,6 @@ export class Stage2ServerService extends SATPService {
sequenceNumber: Number(sessionData.lastSequenceNumber),
});
try {
this.Log.info(`exec-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class Stage3ServerService extends SATPService {
session.verify(fnTag, SessionType.SERVER);

const sessionData = session.getServerSessionData();
this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -228,7 +227,6 @@ export class Stage3ServerService extends SATPService {

const sessionData = session.getServerSessionData();

this.Log.info(`init-${messageType}`);
await this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: messageType,
Expand Down Expand Up @@ -745,7 +743,6 @@ export class Stage3ServerService extends SATPService {

session.verify(fnTag, SessionType.SERVER);
const sessionData = session.getServerSessionData();
this.Log.info(`init-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "assign-asset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface SATPGatewayConfig {
bridgesConfig?: NetworkConfig[];
knexLocalConfig?: Knex.Config;
knexRemoteConfig?: Knex.Config;
enableCrashManager?: boolean;
enableCrashRecovery?: boolean;
}

// export interface SATPBridgeConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ export const knexLocalInstance: { [key: string]: Knex.Config } = {
migrations: {
directory: path.resolve(__dirname, "migrations"),
},
seeds: {
directory: path.resolve(__dirname, "seeds"),
},
useNullAsDefault: true,
},
production: {
client: "pg",
connection: {
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function up(knex: Knex): Knex.SchemaBuilder {
table.string("key").notNullable().primary();
table.string("operation").notNullable();
table.string("timestamp").notNullable();
table.string("data").notNullable();
table.text("data").notNullable();
table.bigInteger("sequenceNumber").notNullable();
});
}
Expand Down
Loading
Loading