From e8c64fc50ec98f883f9b7c774eedbf340816ffce Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Tue, 17 Dec 2024 11:49:48 +0200 Subject: [PATCH 1/8] Add dockerfile and compose Signed-off-by: georgi-l95 improve dockerfile Signed-off-by: georgi-l95 --- simulator/docker/Dockerfile | 39 +++++++++++++++++++++++++++++ simulator/docker/docker-compose.yml | 17 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 simulator/docker/Dockerfile create mode 100644 simulator/docker/docker-compose.yml diff --git a/simulator/docker/Dockerfile b/simulator/docker/Dockerfile new file mode 100644 index 000000000..d8d4b3f2b --- /dev/null +++ b/simulator/docker/Dockerfile @@ -0,0 +1,39 @@ +# Use Eclipse Temurin with Java 21 as the base image +FROM eclipse-temurin:21 + +# Create a non-root user and group +ARG UNAME=hedera +ARG UID=2000 +ARG GID=2000 +RUN groupadd -g $GID -o $UNAME +RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME + +# Set the working directory inside the container +WORKDIR /app + +# Copy the distribution and resources +COPY simulator-*.tar ./simulator.tar +COPY logging.properties . + +# Create resources directory and copy block data +RUN mkdir -p src/main/resources +COPY block-0.0.3.tar.gz src/main/resources/ + +# Extract the distribution and block data +RUN tar -xf simulator.tar && \ + rm simulator.tar && \ + cd src/main/resources && \ + tar -xzf block-0.0.3.tar.gz && \ + rm block-0.0.3.tar.gz && \ + cd /app && \ + chown -R $UNAME:$UNAME /app + +# Switch to non-root user +USER $UNAME + +# Run the simulator using the extracted directory name +RUN SIMULATOR_DIR=$(ls -d simulator-*/) && \ + echo "#!/bin/bash\n/app/${SIMULATOR_DIR}bin/simulator" > /app/start.sh && \ + chmod +x /app/start.sh + +ENTRYPOINT ["/app/start.sh"] \ No newline at end of file diff --git a/simulator/docker/docker-compose.yml b/simulator/docker/docker-compose.yml new file mode 100644 index 000000000..426921007 --- /dev/null +++ b/simulator/docker/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.8" + +services: + block-simulator: + container_name: block-simulator + build: + context: . + dockerfile: Dockerfile + image: hedera-block-simulator:latest + networks: + - block-node_default + environment: + - GRPC_SERVER_ADDRESS=block-node-server + +networks: + block-node_default: + external: true From 7c6805fcbe0977650fda24c63c348b8596c51b8c Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Tue, 17 Dec 2024 12:29:18 +0200 Subject: [PATCH 2/8] add docker prepare script Signed-off-by: georgi-l95 --- simulator/docker/prepare-docker.sh | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 simulator/docker/prepare-docker.sh diff --git a/simulator/docker/prepare-docker.sh b/simulator/docker/prepare-docker.sh new file mode 100755 index 000000000..b58948d9f --- /dev/null +++ b/simulator/docker/prepare-docker.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Exit on any error +set -e + +echo "๐Ÿš€ Preparing Docker build environment..." + +# Get the script's directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJECT_ROOT="$SCRIPT_DIR/../.." + +# Clean and build new distribution +echo "๐Ÿ“ฆ Building simulator distribution..." +cd "$PROJECT_ROOT" +./gradlew clean :simulator:assemble + +# Create docker directory if it doesn't exist +mkdir -p "$SCRIPT_DIR" + +# Copy simulator distribution +echo "๐Ÿ“‹ Copying simulator distribution..." +cp simulator/build/distributions/simulator-*.tar "$SCRIPT_DIR/" + +# Copy block data +echo "๐Ÿ“‹ Copying block data..." +cp simulator/src/main/resources/block-0.0.3.tar.gz "$SCRIPT_DIR/" + +# Copy logging properties +echo "๐Ÿ“‹ Copying logging properties..." +cp simulator/src/main/resources/logging.properties "$SCRIPT_DIR/logging.properties" + +echo "โœ… Docker build environment prepared successfully!" \ No newline at end of file From e9fe1e997ac52c507726693a3c1aea7ab9bcaa6d Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Tue, 17 Dec 2024 12:40:54 +0200 Subject: [PATCH 3/8] add gradle task Signed-off-by: georgi-l95 cleanup docker setup Signed-off-by: georgi-l95 rework documentation Signed-off-by: georgi-l95 spotless Signed-off-by: georgi-l95 fix conflicts Signed-off-by: georgi-l95 address feedback Signed-off-by: georgi-l95 revert documentation improvements Signed-off-by: georgi-l95 revert docs Signed-off-by: georgi-l95 --- server/docker/metrics/prometheus.yml | 4 ++-- server/docs/configuration.md | 2 +- simulator/build.gradle.kts | 20 ++++++++++++++++ simulator/docker/Dockerfile | 4 +--- simulator/docker/cleanup-docker.sh | 23 +++++++++++++++++++ simulator/docker/docker-compose.yml | 30 ++++++++++++++++++++++-- simulator/docker/prepare-docker.sh | 6 ++--- simulator/docs/configuration.md | 9 ++++++++ simulator/docs/quickstart.md | 34 ++++++---------------------- 9 files changed, 94 insertions(+), 38 deletions(-) create mode 100755 simulator/docker/cleanup-docker.sh diff --git a/server/docker/metrics/prometheus.yml b/server/docker/metrics/prometheus.yml index 1aeeea227..c53fb620a 100644 --- a/server/docker/metrics/prometheus.yml +++ b/server/docker/metrics/prometheus.yml @@ -8,7 +8,7 @@ scrape_configs: - job_name: 'simulator-publisher' static_configs: - - targets: ['host.docker.internal:9998'] + - targets: ['simulator-publisher:9998'] metrics_path: '/metrics' scheme: 'http' relabel_configs: @@ -18,7 +18,7 @@ scrape_configs: - job_name: 'simulator-consumer' static_configs: - - targets: ['host.docker.internal:9997'] + - targets: ['simulator-consumer:9997'] metrics_path: '/metrics' scheme: 'http' relabel_configs: diff --git a/server/docs/configuration.md b/server/docs/configuration.md index 69f880d59..c01d219ba 100644 --- a/server/docs/configuration.md +++ b/server/docs/configuration.md @@ -21,4 +21,4 @@ defaults and can be left unchanged. It is recommended to browse the properties b | MEDIATOR_RING_BUFFER_SIZE | Size of the ring buffer used by the mediator (must be a power of 2) | 67108864 | | NOTIFIER_RING_BUFFER_SIZE | Size of the ring buffer used by the notifier (must be a power of 2) | 2048 | | SERVER_PORT | The port the server will listen on | 8080 | -| SERVER_MAX_MESSAGE_SIZE_BYTES | The maximum size of a message frame in bytes | 1048576 | +| SERVER_MAX_MESSAGE_SIZE_BYTES | The maximum size of a message frame in bytes | 1048576 | \ No newline at end of file diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index 040b539b4..c61974ac4 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -93,3 +93,23 @@ tasks.register("untarTestBlockStream") { tasks.named("processResources") { dependsOn(tasks.named("untarTestBlockStream")) } tasks.named("sourcesJar") { dependsOn(tasks.named("untarTestBlockStream")) } + +// Task to prepare and run Docker container +tasks.register("startDockerContainer") { + description = "Prepare and run the simulator containers in publisher and consumer mode" + group = "docker" + + doLast { + exec { commandLine("./docker/prepare-docker.sh") } + + exec { + workingDir("docker") + commandLine("sh", "-c", "docker compose -p simulator up --build -d") + } + + exec { commandLine("./docker/cleanup-docker.sh") } + + println("โœ… Docker simulator is now running!") + println("๐Ÿงน Build artifacts have been cleaned up") + } +} diff --git a/simulator/docker/Dockerfile b/simulator/docker/Dockerfile index d8d4b3f2b..777b6d328 100644 --- a/simulator/docker/Dockerfile +++ b/simulator/docker/Dockerfile @@ -1,4 +1,3 @@ -# Use Eclipse Temurin with Java 21 as the base image FROM eclipse-temurin:21 # Create a non-root user and group @@ -8,7 +7,6 @@ ARG GID=2000 RUN groupadd -g $GID -o $UNAME RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME -# Set the working directory inside the container WORKDIR /app # Copy the distribution and resources @@ -36,4 +34,4 @@ RUN SIMULATOR_DIR=$(ls -d simulator-*/) && \ echo "#!/bin/bash\n/app/${SIMULATOR_DIR}bin/simulator" > /app/start.sh && \ chmod +x /app/start.sh -ENTRYPOINT ["/app/start.sh"] \ No newline at end of file +ENTRYPOINT ["/app/start.sh"] diff --git a/simulator/docker/cleanup-docker.sh b/simulator/docker/cleanup-docker.sh new file mode 100755 index 000000000..fa6abf90b --- /dev/null +++ b/simulator/docker/cleanup-docker.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Exit on any error +set -e + +echo "๐Ÿงน Cleaning up Docker build artifacts..." + +# Get the script's directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Remove simulator tar file +echo "๐Ÿ—‘๏ธ Removing simulator distribution tar..." +rm -f "$SCRIPT_DIR"/simulator-*.tar + +# Remove block data tar +echo "๐Ÿ—‘๏ธ Removing block data tar..." +rm -f "$SCRIPT_DIR"/block-0.0.3.tar.gz + +# Remove logging properties +echo "๐Ÿ—‘๏ธ Removing logging properties..." +rm -f "$SCRIPT_DIR"/logging.properties + +echo "โœจ Cleanup completed successfully!" diff --git a/simulator/docker/docker-compose.yml b/simulator/docker/docker-compose.yml index 426921007..c52d5d411 100644 --- a/simulator/docker/docker-compose.yml +++ b/simulator/docker/docker-compose.yml @@ -1,8 +1,8 @@ version: "3.8" services: - block-simulator: - container_name: block-simulator + simulator-publisher: + container_name: simulator-publisher build: context: . dockerfile: Dockerfile @@ -11,7 +11,33 @@ services: - block-node_default environment: - GRPC_SERVER_ADDRESS=block-node-server + - BLOCK_STREAM_SIMULATOR_MODE=PUBLISHER + - PROMETHEUS_ENDPOINT_ENABLED=true + - PROMETHEUS_ENDPOINT_PORT_NUMBER=9998 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9998/metrics"] + interval: 3s + timeout: 10s + retries: 5 + + simulator-consumer: + container_name: simulator-consumer + build: + context: . + dockerfile: Dockerfile + image: hedera-block-simulator:latest + networks: + - block-node_default + environment: + - GRPC_SERVER_ADDRESS=block-node-server + - BLOCK_STREAM_SIMULATOR_MODE=CONSUMER + - PROMETHEUS_ENDPOINT_ENABLED=true + - PROMETHEUS_ENDPOINT_PORT_NUMBER=9997 + depends_on: + simulator-publisher: + condition: service_healthy networks: block-node_default: + name: block-node_default external: true diff --git a/simulator/docker/prepare-docker.sh b/simulator/docker/prepare-docker.sh index b58948d9f..b41ccf8b4 100755 --- a/simulator/docker/prepare-docker.sh +++ b/simulator/docker/prepare-docker.sh @@ -9,10 +9,10 @@ echo "๐Ÿš€ Preparing Docker build environment..." SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_ROOT="$SCRIPT_DIR/../.." -# Clean and build new distribution +# Build new distribution echo "๐Ÿ“ฆ Building simulator distribution..." cd "$PROJECT_ROOT" -./gradlew clean :simulator:assemble +./gradlew :simulator:assemble # Create docker directory if it doesn't exist mkdir -p "$SCRIPT_DIR" @@ -29,4 +29,4 @@ cp simulator/src/main/resources/block-0.0.3.tar.gz "$SCRIPT_DIR/" echo "๐Ÿ“‹ Copying logging properties..." cp simulator/src/main/resources/logging.properties "$SCRIPT_DIR/logging.properties" -echo "โœ… Docker build environment prepared successfully!" \ No newline at end of file +echo "โœ… Docker build environment prepared successfully!" diff --git a/simulator/docs/configuration.md b/simulator/docs/configuration.md index 939ea5213..33f16ee05 100644 --- a/simulator/docs/configuration.md +++ b/simulator/docs/configuration.md @@ -38,3 +38,12 @@ Uses the prefix `grpc` so all properties should start with `grpc.` |:---|:---|---:| | `serverAddress` | The host of the Block-Node | `localhost` | | `port` | The port of the Block-Node | `8080` | + +## PrometheusConfig + +Uses the prefix `prometheus` so all properties should start with `prometheus.` + +| Key | Description | Default Value | +|:---|:---|--------------:| +| `endpointEnabled` | Whether Prometheus endpoint is enabled | `false` | +| `endpointPortNumber` | Port number for Prometheus endpoint | `9998` | \ No newline at end of file diff --git a/simulator/docs/quickstart.md b/simulator/docs/quickstart.md index b0202b012..df745addb 100644 --- a/simulator/docs/quickstart.md +++ b/simulator/docs/quickstart.md @@ -72,33 +72,13 @@ The simulator can run in two modes (Publisher and Consumer) and provides metrics ./gradlew startDockerContainer ``` -2. Configure and run the simulator in Publisher mode: - - - In `app.properties`, set: - ```properties - blockStream.simulatorMode=PUBLISHER - prometheus.endpointEnabled=true - prometheus.endpointPortNumber=9998 - ``` - - Start the simulator: - ```bash - ./gradlew :simulator:run - ``` - -3. Configure and run the simulator in Consumer mode: - - - In `app.properties`, update: - ```properties - blockStream.simulatorMode=CONSUMER - prometheus.endpointEnabled=true - prometheus.endpointPortNumber=9997 - ``` - - Start another instance of the simulator: - ```bash - ./gradlew :simulator:run - ``` - -4. Access the metrics: +2. Start the simulator containers (both Publisher and Consumer): + + ```bash + ./gradlew startSimulatorDockerContainers + ``` + +3. Access the metrics: - Open Grafana at http://localhost:3000 - Navigate to Dashboards - You'll find two dashboards: From c391d5723f9a137689af4af63f3fce7b1655dfc0 Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 19 Dec 2024 14:40:33 +0200 Subject: [PATCH 4/8] address comments Signed-off-by: georgi-l95 remove docker compose version Signed-off-by: georgi-l95 add update-env script Signed-off-by: georgi-l95 rename file Signed-off-by: georgi-l95 simplify docs Signed-off-by: georgi-l95 update order Signed-off-by: georgi-l95 --- simulator/build.gradle.kts | 36 ++++++++++++++++------------- simulator/docker/cleanup-docker.sh | 23 ------------------ simulator/docker/docker-compose.yml | 22 ++++++++++-------- simulator/docker/prepare-docker.sh | 19 +++++++-------- simulator/docker/update-env.sh | 25 ++++++++++++++++++++ simulator/docs/quickstart.md | 10 ++------ 6 files changed, 69 insertions(+), 66 deletions(-) delete mode 100755 simulator/docker/cleanup-docker.sh create mode 100755 simulator/docker/update-env.sh diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index c61974ac4..e77950601 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -94,22 +94,26 @@ tasks.named("processResources") { dependsOn(tasks.named("untarTestBlockStream")) tasks.named("sourcesJar") { dependsOn(tasks.named("untarTestBlockStream")) } -// Task to prepare and run Docker container -tasks.register("startDockerContainer") { - description = "Prepare and run the simulator containers in publisher and consumer mode" - group = "docker" - - doLast { - exec { commandLine("./docker/prepare-docker.sh") } - - exec { - workingDir("docker") - commandLine("sh", "-c", "docker compose -p simulator up --build -d") - } +// Vals +val dockerProjectRootDirectory: Directory = layout.projectDirectory.dir("docker") +val dockerBuildRootDirectory: Directory = layout.buildDirectory.dir("docker").get() + +// Docker related tasks +val copyDockerFolder: TaskProvider = + tasks.register("copyDockerFolder") { + description = "Copies the docker folder to the build root directory" + group = "docker" + + from(dockerProjectRootDirectory) + into(dockerBuildRootDirectory) + } - exec { commandLine("./docker/cleanup-docker.sh") } +val startDockerContainer: TaskProvider = + tasks.register("startDockerContainer") { + description = "Creates and starts the docker image of the Block Stream Simulator" + group = "docker" - println("โœ… Docker simulator is now running!") - println("๐Ÿงน Build artifacts have been cleaned up") + dependsOn(copyDockerFolder, tasks.assemble) + workingDir(dockerBuildRootDirectory) + commandLine("sh", "-c", "./prepare-docker.sh") } -} diff --git a/simulator/docker/cleanup-docker.sh b/simulator/docker/cleanup-docker.sh deleted file mode 100755 index fa6abf90b..000000000 --- a/simulator/docker/cleanup-docker.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -echo "๐Ÿงน Cleaning up Docker build artifacts..." - -# Get the script's directory -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Remove simulator tar file -echo "๐Ÿ—‘๏ธ Removing simulator distribution tar..." -rm -f "$SCRIPT_DIR"/simulator-*.tar - -# Remove block data tar -echo "๐Ÿ—‘๏ธ Removing block data tar..." -rm -f "$SCRIPT_DIR"/block-0.0.3.tar.gz - -# Remove logging properties -echo "๐Ÿ—‘๏ธ Removing logging properties..." -rm -f "$SCRIPT_DIR"/logging.properties - -echo "โœจ Cleanup completed successfully!" diff --git a/simulator/docker/docker-compose.yml b/simulator/docker/docker-compose.yml index c52d5d411..d9fae4fae 100644 --- a/simulator/docker/docker-compose.yml +++ b/simulator/docker/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: simulator-publisher: container_name: simulator-publisher @@ -9,11 +7,13 @@ services: image: hedera-block-simulator:latest networks: - block-node_default + env_file: + - .env environment: - - GRPC_SERVER_ADDRESS=block-node-server - - BLOCK_STREAM_SIMULATOR_MODE=PUBLISHER - - PROMETHEUS_ENDPOINT_ENABLED=true - - PROMETHEUS_ENDPOINT_PORT_NUMBER=9998 + - GRPC_SERVER_ADDRESS=${GRPC_SERVER_ADDRESS} + - BLOCK_STREAM_SIMULATOR_MODE=${PUBLISHER_BLOCK_STREAM_SIMULATOR_MODE} + - PROMETHEUS_ENDPOINT_ENABLED=${PROMETHEUS_ENDPOINT_ENABLED} + - PROMETHEUS_ENDPOINT_PORT_NUMBER=${PUBLISHER_PROMETHEUS_ENDPOINT_PORT_NUMBER} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9998/metrics"] interval: 3s @@ -28,11 +28,13 @@ services: image: hedera-block-simulator:latest networks: - block-node_default + env_file: + - .env environment: - - GRPC_SERVER_ADDRESS=block-node-server - - BLOCK_STREAM_SIMULATOR_MODE=CONSUMER - - PROMETHEUS_ENDPOINT_ENABLED=true - - PROMETHEUS_ENDPOINT_PORT_NUMBER=9997 + - GRPC_SERVER_ADDRESS=${GRPC_SERVER_ADDRESS} + - BLOCK_STREAM_SIMULATOR_MODE=${CONSUMER_BLOCK_STREAM_SIMULATOR_MODE} + - PROMETHEUS_ENDPOINT_ENABLED=${PROMETHEUS_ENDPOINT_ENABLED} + - PROMETHEUS_ENDPOINT_PORT_NUMBER=${CONSUMER_PROMETHEUS_ENDPOINT_PORT_NUMBER} depends_on: simulator-publisher: condition: service_healthy diff --git a/simulator/docker/prepare-docker.sh b/simulator/docker/prepare-docker.sh index b41ccf8b4..0d98ff814 100755 --- a/simulator/docker/prepare-docker.sh +++ b/simulator/docker/prepare-docker.sh @@ -7,26 +7,27 @@ echo "๐Ÿš€ Preparing Docker build environment..." # Get the script's directory SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT="$SCRIPT_DIR/../.." - -# Build new distribution -echo "๐Ÿ“ฆ Building simulator distribution..." -cd "$PROJECT_ROOT" -./gradlew :simulator:assemble +PROJECT_ROOT="$SCRIPT_DIR/../../.." # Create docker directory if it doesn't exist mkdir -p "$SCRIPT_DIR" # Copy simulator distribution echo "๐Ÿ“‹ Copying simulator distribution..." -cp simulator/build/distributions/simulator-*.tar "$SCRIPT_DIR/" +cp ../distributions/simulator-*.tar "$SCRIPT_DIR/" # Copy block data echo "๐Ÿ“‹ Copying block data..." -cp simulator/src/main/resources/block-0.0.3.tar.gz "$SCRIPT_DIR/" +cp ../../src/main/resources/block-0.0.3.tar.gz "$SCRIPT_DIR/" # Copy logging properties echo "๐Ÿ“‹ Copying logging properties..." -cp simulator/src/main/resources/logging.properties "$SCRIPT_DIR/logging.properties" +cp ../../src/main/resources/logging.properties "$SCRIPT_DIR/logging.properties" + +sh -c ./update-env.sh echo "โœ… Docker build environment prepared successfully!" + +docker compose -p simulator up --build -d + +echo "โœ… Docker images successfully built and started!" diff --git a/simulator/docker/update-env.sh b/simulator/docker/update-env.sh new file mode 100755 index 000000000..08e79dfd9 --- /dev/null +++ b/simulator/docker/update-env.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# This script creates a '.env' file that is used for docker-compose as input for environment variables +# for the simulator services. + +echo "Creating .env file for simulator services..." + +# Generate .env file with default values +cat > .env << EOL +GRPC_SERVER_ADDRESS=block-node-server +PROMETHEUS_ENDPOINT_ENABLED=true + +# For publisher service +PUBLISHER_BLOCK_STREAM_SIMULATOR_MODE=PUBLISHER +PUBLISHER_PROMETHEUS_ENDPOINT_PORT_NUMBER=9998 + +# For consumer service +CONSUMER_BLOCK_STREAM_SIMULATOR_MODE=CONSUMER +CONSUMER_PROMETHEUS_ENDPOINT_PORT_NUMBER=9997 +EOL + +# Output the values +echo ".env properties:" +cat .env +echo diff --git a/simulator/docs/quickstart.md b/simulator/docs/quickstart.md index df745addb..fa5a8a17b 100644 --- a/simulator/docs/quickstart.md +++ b/simulator/docs/quickstart.md @@ -66,19 +66,13 @@ get started with the application. The simulator can run in two modes (Publisher and Consumer) and provides metrics for both configurations. To view the metrics: -1. Start the block node server first: +1. Start the block node server and simulator first: ```bash ./gradlew startDockerContainer ``` -2. Start the simulator containers (both Publisher and Consumer): - - ```bash - ./gradlew startSimulatorDockerContainers - ``` - -3. Access the metrics: +2. Access the metrics: - Open Grafana at http://localhost:3000 - Navigate to Dashboards - You'll find two dashboards: From e2223a8a6d7004213d218433a44f7cb73fde4eba Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 19 Dec 2024 17:22:21 +0200 Subject: [PATCH 5/8] remove unneeded env variables from docker compose Signed-off-by: georgi-l95 --- simulator/build.gradle.kts | 9 +++++++++ simulator/docker/docker-compose.yml | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index e77950601..9887754d9 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -117,3 +117,12 @@ val startDockerContainer: TaskProvider = workingDir(dockerBuildRootDirectory) commandLine("sh", "-c", "./prepare-docker.sh") } + +tasks.register("stopDockerContainer") { + description = "Stops running docker containers of the Block Stream Simulator" + group = "docker" + + dependsOn(copyDockerFolder) + workingDir(dockerBuildRootDirectory) + commandLine("sh", "-c", "docker compose -p simulator stop") +} diff --git a/simulator/docker/docker-compose.yml b/simulator/docker/docker-compose.yml index d9fae4fae..5663bab05 100644 --- a/simulator/docker/docker-compose.yml +++ b/simulator/docker/docker-compose.yml @@ -10,9 +10,7 @@ services: env_file: - .env environment: - - GRPC_SERVER_ADDRESS=${GRPC_SERVER_ADDRESS} - BLOCK_STREAM_SIMULATOR_MODE=${PUBLISHER_BLOCK_STREAM_SIMULATOR_MODE} - - PROMETHEUS_ENDPOINT_ENABLED=${PROMETHEUS_ENDPOINT_ENABLED} - PROMETHEUS_ENDPOINT_PORT_NUMBER=${PUBLISHER_PROMETHEUS_ENDPOINT_PORT_NUMBER} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9998/metrics"] @@ -31,9 +29,7 @@ services: env_file: - .env environment: - - GRPC_SERVER_ADDRESS=${GRPC_SERVER_ADDRESS} - BLOCK_STREAM_SIMULATOR_MODE=${CONSUMER_BLOCK_STREAM_SIMULATOR_MODE} - - PROMETHEUS_ENDPOINT_ENABLED=${PROMETHEUS_ENDPOINT_ENABLED} - PROMETHEUS_ENDPOINT_PORT_NUMBER=${CONSUMER_PROMETHEUS_ENDPOINT_PORT_NUMBER} depends_on: simulator-publisher: From 6754763ab963feed662194ae64c178906d15ec0c Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 19 Dec 2024 23:23:46 +0200 Subject: [PATCH 6/8] address comments Signed-off-by: georgi-l95 --- server/build.gradle.kts | 6 ++--- simulator/build.gradle.kts | 39 ++++++++++++++++++++++++++++-- simulator/docker/prepare-docker.sh | 33 ------------------------- suites/build.gradle.kts | 4 +-- 4 files changed, 42 insertions(+), 40 deletions(-) delete mode 100755 simulator/docker/prepare-docker.sh diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 25592c617..186d5948c 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -79,11 +79,11 @@ val copyDockerFolder: TaskProvider = into(dockerBuildRootDirectory) } -// @todo(#343) - createProductionDotEnv is temporary and used by the suites, +// @todo(#343) - createDotEnv is temporary and used by the suites, // once the suites no longer rely on the .env file from the build root we // should remove this task -val createProductionDotEnv: TaskProvider = - tasks.register("createProductionDotEnv") { +val createDotEnv: TaskProvider = + tasks.register("createDotEnv") { description = "Creates the default dotenv file for the Block Node Server" group = "docker" diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index 9887754d9..0bf920a59 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -96,6 +96,8 @@ tasks.named("sourcesJar") { dependsOn(tasks.named("untarTestBlockStream")) } // Vals val dockerProjectRootDirectory: Directory = layout.projectDirectory.dir("docker") +var resourcesProjectRootDirectory: Directory = layout.projectDirectory.dir("src/main/resources") +var distributionBuildRootDirectory: Directory = layout.buildDirectory.dir("distributions").get() val dockerBuildRootDirectory: Directory = layout.buildDirectory.dir("docker").get() // Docker related tasks @@ -108,14 +110,47 @@ val copyDockerFolder: TaskProvider = into(dockerBuildRootDirectory) } +// Docker related tasks +val copyDependenciesFolders: TaskProvider = + tasks.register("copyDependenciesFolders") { + description = "Copies the docker folder to the build root directory" + group = "docker" + + dependsOn(copyDockerFolder, tasks.assemble) + from(resourcesProjectRootDirectory) + from(distributionBuildRootDirectory) + into(dockerBuildRootDirectory) + } + +val createDockerImage: TaskProvider = + tasks.register("createDockerImage") { + description = "Creates the docker image of the Block Stream Simulator" + group = "docker" + + dependsOn(copyDependenciesFolders, tasks.assemble) + workingDir(dockerBuildRootDirectory) + commandLine("sh", "-c", "docker buildx build -t hedera-block-simulator:latest .") + } + +val createDotEnv: TaskProvider = + tasks.register("createDotEnv") { + description = "Creates .env file with needed environment variables for the simulator" + group = "docker" + + dependsOn(createDockerImage, tasks.assemble) + workingDir(dockerBuildRootDirectory) + commandLine("sh", "-c", "./update-env.sh") + } + val startDockerContainer: TaskProvider = tasks.register("startDockerContainer") { description = "Creates and starts the docker image of the Block Stream Simulator" group = "docker" - dependsOn(copyDockerFolder, tasks.assemble) + dependsOn(createDotEnv, tasks.assemble) workingDir(dockerBuildRootDirectory) - commandLine("sh", "-c", "./prepare-docker.sh") + + commandLine("sh", "-c", "docker compose -p simulator up -d") } tasks.register("stopDockerContainer") { diff --git a/simulator/docker/prepare-docker.sh b/simulator/docker/prepare-docker.sh deleted file mode 100755 index 0d98ff814..000000000 --- a/simulator/docker/prepare-docker.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -echo "๐Ÿš€ Preparing Docker build environment..." - -# Get the script's directory -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT="$SCRIPT_DIR/../../.." - -# Create docker directory if it doesn't exist -mkdir -p "$SCRIPT_DIR" - -# Copy simulator distribution -echo "๐Ÿ“‹ Copying simulator distribution..." -cp ../distributions/simulator-*.tar "$SCRIPT_DIR/" - -# Copy block data -echo "๐Ÿ“‹ Copying block data..." -cp ../../src/main/resources/block-0.0.3.tar.gz "$SCRIPT_DIR/" - -# Copy logging properties -echo "๐Ÿ“‹ Copying logging properties..." -cp ../../src/main/resources/logging.properties "$SCRIPT_DIR/logging.properties" - -sh -c ./update-env.sh - -echo "โœ… Docker build environment prepared successfully!" - -docker compose -p simulator up --build -d - -echo "โœ… Docker images successfully built and started!" diff --git a/suites/build.gradle.kts b/suites/build.gradle.kts index 85af453d4..b3e80fc8d 100644 --- a/suites/build.gradle.kts +++ b/suites/build.gradle.kts @@ -43,8 +43,8 @@ tasks.register("runSuites") { group = "suites" modularity.inferModulePath = false - // @todo(#343) - :server:createProductionDotEnv should disappear - dependsOn(":server:createDockerImage", ":server:createProductionDotEnv") + // @todo(#343) - :server:createDotEnv should disappear + dependsOn(":server:createDockerImage", ":server:createDotEnv") useJUnitPlatform() testLogging { events("passed", "skipped", "failed") } From cbbf00a7dc74d4070179785f3f589b7943385a71 Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 19 Dec 2024 23:58:51 +0200 Subject: [PATCH 7/8] address comments Signed-off-by: georgi-l95 --- server/build.gradle.kts | 6 +++--- simulator/build.gradle.kts | 14 ++------------ suites/build.gradle.kts | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 186d5948c..25592c617 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -79,11 +79,11 @@ val copyDockerFolder: TaskProvider = into(dockerBuildRootDirectory) } -// @todo(#343) - createDotEnv is temporary and used by the suites, +// @todo(#343) - createProductionDotEnv is temporary and used by the suites, // once the suites no longer rely on the .env file from the build root we // should remove this task -val createDotEnv: TaskProvider = - tasks.register("createDotEnv") { +val createProductionDotEnv: TaskProvider = + tasks.register("createProductionDotEnv") { description = "Creates the default dotenv file for the Block Node Server" group = "docker" diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index 0bf920a59..a0e5e14bb 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -132,25 +132,15 @@ val createDockerImage: TaskProvider = commandLine("sh", "-c", "docker buildx build -t hedera-block-simulator:latest .") } -val createDotEnv: TaskProvider = - tasks.register("createDotEnv") { - description = "Creates .env file with needed environment variables for the simulator" - group = "docker" - - dependsOn(createDockerImage, tasks.assemble) - workingDir(dockerBuildRootDirectory) - commandLine("sh", "-c", "./update-env.sh") - } - val startDockerContainer: TaskProvider = tasks.register("startDockerContainer") { description = "Creates and starts the docker image of the Block Stream Simulator" group = "docker" - dependsOn(createDotEnv, tasks.assemble) + dependsOn(createDockerImage, tasks.assemble) workingDir(dockerBuildRootDirectory) - commandLine("sh", "-c", "docker compose -p simulator up -d") + commandLine("sh", "-c", "./update-env.sh && docker compose -p simulator up -d") } tasks.register("stopDockerContainer") { diff --git a/suites/build.gradle.kts b/suites/build.gradle.kts index b3e80fc8d..fc7bc4b27 100644 --- a/suites/build.gradle.kts +++ b/suites/build.gradle.kts @@ -44,7 +44,7 @@ tasks.register("runSuites") { modularity.inferModulePath = false // @todo(#343) - :server:createDotEnv should disappear - dependsOn(":server:createDockerImage", ":server:createDotEnv") + dependsOn(":server:createDockerImage", ":server:createProductionDotEnv") useJUnitPlatform() testLogging { events("passed", "skipped", "failed") } From 676cc9627bf183dadd6a6d437f508ab1eac643bc Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Fri, 20 Dec 2024 10:30:22 +0200 Subject: [PATCH 8/8] fix missed renaming Signed-off-by: georgi-l95 --- suites/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suites/build.gradle.kts b/suites/build.gradle.kts index fc7bc4b27..85af453d4 100644 --- a/suites/build.gradle.kts +++ b/suites/build.gradle.kts @@ -43,7 +43,7 @@ tasks.register("runSuites") { group = "suites" modularity.inferModulePath = false - // @todo(#343) - :server:createDotEnv should disappear + // @todo(#343) - :server:createProductionDotEnv should disappear dependsOn(":server:createDockerImage", ":server:createProductionDotEnv") useJUnitPlatform()