-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(satp-hermes): gateway runner and docker for SATP
Signed-off-by: Bruno Mateus <brumat315@gmail.com>
- Loading branch information
1 parent
a7fa53e
commit 9bd1f19
Showing
14 changed files
with
983 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
FROM ubuntu:22.04 | ||
|
||
USER root | ||
RUN groupadd -r docker | ||
RUN usermod -aG docker root | ||
|
||
RUN apt-get update | ||
RUN apt-get -y install --no-install-recommends supervisor | ||
RUN apt-get -y install --no-install-recommends openssl | ||
RUN apt-get -y install --no-install-recommends jq | ||
RUN apt-get -y install --no-install-recommends curl | ||
RUN apt-get -y install --no-install-recommends file | ||
RUN apt-get -y install --no-install-recommends ca-certificates | ||
RUN apt-get -y install --no-install-recommends tzdata | ||
RUN apt-get -y install --no-install-recommends git | ||
RUN apt-get -y install --no-install-recommends apt-utils | ||
RUN apt-get -y install --no-install-recommends net-tools | ||
RUN apt-get -y install --no-install-recommends default-jdk | ||
|
||
RUN mkdir -p /var/log/supervisor | ||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf | ||
|
||
ARG APP=/usr/src/app/cactus/ | ||
COPY . ${APP} | ||
|
||
RUN mkdir -p ${APP} | ||
RUN mkdir -p "${APP}/log/" | ||
RUN mkdir -p /app/keys | ||
|
||
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 18.18.2 && \ | ||
npm install -g yarn ts-node | ||
|
||
SHELL ["/bin/bash", "--login", "-c"] | ||
|
||
COPY ./supervisord.conf /etc/supervisord.conf | ||
COPY ./run-satp-gateway.sh / | ||
COPY ./tsconfig.json /usr/src/tsconfig.json | ||
COPY ./tsconfig.json /tsconfig.json | ||
|
||
RUN chmod +x /run-satp-gateway.sh | ||
|
||
EXPOSE 3010 3011 4010 | ||
|
||
EXPOSE 9001 | ||
|
||
ENV SATP_PRIVATE_KEY="default_private_key" | ||
ENV SATP_PUBLIC_KEY="default_public_key" | ||
|
||
ENV SATP_LOG_LEVEL=INFO | ||
ENV SATP_NODE_ENV=development | ||
ENV SATP_ENABLE_OPEN_API=true | ||
|
||
ENV SATP_GATEWAY_VERSION_CORE=v02 | ||
ENV SATP_GATEWAY_VERSION_ARCHITECTURE=v02 | ||
ENV SATP_GATEWAY_VERSION_CRASH=v02 | ||
ENV SATP_GATEWAY_SERVER_PORT=3010 | ||
ENV SATP_GATEWAY_CLIENT_PORT=3011 | ||
ENV SATP_GATEWAY_GRPC_PORT=4010 | ||
ENV SATP_VALIDATION_OPTIONS={"skipMissingProperties":true} | ||
ENV SATP_PRIVACY_POLICIES=[{"policy":"singleTransaction","policyHash":"hash123"}] | ||
ENV SATP_MERGE_POLICIES=[{"policy":"NONE","policyHash":"hash456"}] | ||
|
||
ENTRYPOINT ["/usr/bin/supervisord"] | ||
CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
version: '3.8' | ||
|
||
services: | ||
### To build new image version: | ||
### uncomment and run in the terminal "docker compose build" | ||
# satp-hermes-gateway-base: | ||
# image: ghcr.io/brunoffmateus/cactus-plugin-satp-hermes-gateway:new-version | ||
# build: | ||
# context: ./ | ||
# dockerfile: Dockerfile.gateway | ||
|
||
satp-hermes-gateway1: | ||
image: ghcr.io/brunoffmateus/cactus-plugin-satp-hermes-gateway:2024-09-02-3117 | ||
ports: | ||
- 13010:3010/tcp # SERVER_PORT | ||
- 13011:3011/tcp # CLIENT_PORT | ||
environment: | ||
- SATP_GATEWAY_ID=gateway1 | ||
- SATP_GATEWAY_NAME=ExampleGateway1 | ||
- SATP_SUPPORTED_DLTS=FabricSATPGateway,BesuSATPGateway | ||
- SATP_GATEWAY_ADDRESS=http://localhost | ||
- SATP_PROOF_ID=mockProofID1 | ||
- SATP_COUNTER_PARTY_GATEWAYS=[{"id":"gateway2","version":"v02,v02,v02","supportedDLTs":"FabricSATPGateway,BesuSATPGateway"}] | ||
volumes: | ||
- gateway1_keys:/app/keys | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 4G | ||
cpus: '0.9' | ||
|
||
# satp-hermes-gateway2: | ||
# image: ghcr.io/brunoffmateus/cactus-plugin-satp-hermes-gateway:2024-09-02-3117 | ||
# ports: | ||
# - 23020:3010/tcp # SERVER_PORT | ||
# - 23021:3011/tcp # CLIENT_PORT | ||
# environment: | ||
# - SATP_GATEWAY_ID=gateway2 | ||
# - SATP_GATEWAY_NAME=ExampleGateway2 | ||
# - SATP_SUPPORTED_DLTS=FabricSATPGateway,BesuSATPGateway | ||
# - SATP_GATEWAY_ADDRESS=http://localhost | ||
# - SATP_PROOF_ID=mockProofID2 | ||
# - SATP_COUNTER_PARTY_GATEWAYS=[{"id":"gateway1","version":"v02,v02,v02","supportedDLTs":"FabricSATPGateway,BesuSATPGateway"}] | ||
# volumes: | ||
# - gateway2_keys:/app/keys | ||
# deploy: | ||
# resources: | ||
# limits: | ||
# memory: 2G | ||
# cpus: '0.5' | ||
|
||
volumes: | ||
gateway1_keys: | ||
# gateway2_keys: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.PHONY: setup-env run-gateway clean | ||
|
||
setup-env: | ||
@echo "Setting up environment for SATP-Hermes..." | ||
|
||
# Check if Node.js is installed, if not, install it | ||
@if ! command -v node >/dev/null 2>&1; then \ | ||
echo "Installing Node.js 18.18.2..."; \ | ||
sudo curl -fsSL https://nodejs.org/dist/v18.18.2/node-v18.18.2-linux-x64.tar.xz | sudo tar -xJ -C /usr/local --strip-components=1; \ | ||
fi | ||
|
||
@if ! command -v yarn >/dev/null 2>&1; then \ | ||
echo "Installing Yarn..."; \ | ||
sudo npm install -g yarn; \ | ||
fi | ||
|
||
# Install dependencies and compile the plugin | ||
yarn install | ||
yarn tsc | ||
|
||
@echo "Initializing databases..." | ||
yarn db:init | ||
|
||
@echo "Environment setup complete." | ||
|
||
run-gateway: | ||
# @echo "Building SATP Gateway Docker image..." | ||
# docker compose build | ||
|
||
@echo "Running SATP Gateway Docker containers..." | ||
docker compose up | ||
|
||
# @echo "Pushing SATP Gateway Docker image..." | ||
# docker push ${DOCKER_IMAGE} | ||
|
||
clean: | ||
@echo "Cleaning up SATP-Hermes environment..." | ||
|
||
@echo "Rolling back database migrations..." | ||
yarn db:rollback | ||
|
||
@echo "Removing SQLite database files..." | ||
find src/knex -name "*.sqlite3" -type f -delete | ||
|
||
@echo "Stopping and removing Docker containers..." | ||
docker compose down | ||
|
||
@echo "Cleanup complete." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
generate_keys() { | ||
# Check if we need to generate new keys | ||
if [ "$SATP_PRIVATE_KEY" = "default_private_key" ] || [ "$SATP_PUBLIC_KEY" = "default_public_key" ]; then | ||
echo "Generating new key pair..." | ||
# Using OpenSSL to generate a 256-bit private key and derive public key | ||
PRIVATE_KEY=$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//') | ||
PUBLIC_KEY=$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//') | ||
|
||
export SATP_PRIVATE_KEY=$PRIVATE_KEY | ||
export SATP_PUBLIC_KEY=$PUBLIC_KEY | ||
else | ||
echo "Using existing key pair from environment variables" | ||
fi | ||
|
||
echo "SATP_PRIVATE_KEY: $SATP_PRIVATE_KEY" | ||
echo "SATP_PUBLIC_KEY: $SATP_PUBLIC_KEY" | ||
} | ||
|
||
run_gateway() { | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
nvm use 18.18.2 | ||
|
||
echo "Starting SATP Hermes Gateway CLI..." | ||
node --max-old-space-size=2048 -r ts-node/register /usr/src/app/cactus/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway-cli.ts | ||
echo "SATP Hermes Gateway CLI execution completed." | ||
} | ||
|
||
main() { | ||
generate_keys | ||
run_gateway | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.