From d654cecc4a73b89d815474207d4a2631df10c9cb Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Thu, 19 Dec 2024 14:40:33 +0200 Subject: [PATCH] address comments Signed-off-by: georgi-l95 --- simulator/build.gradle.kts | 36 ++++++++++++++++------------- simulator/docker/cleanup-docker.sh | 23 ------------------ simulator/docker/docker-compose.yml | 20 +++++++++------- simulator/docker/prepare-docker.sh | 17 +++++++------- 4 files changed, 40 insertions(+), 56 deletions(-) delete mode 100755 simulator/docker/cleanup-docker.sh diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index 3e383f12..212a49b3 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -92,22 +92,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 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 fa6abf90..00000000 --- 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 c52d5d41..d2248891 100644 --- a/simulator/docker/docker-compose.yml +++ b/simulator/docker/docker-compose.yml @@ -9,11 +9,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 +30,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 b41ccf8b..792db42d 100755 --- a/simulator/docker/prepare-docker.sh +++ b/simulator/docker/prepare-docker.sh @@ -7,26 +7,25 @@ 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" echo "โœ… Docker build environment prepared successfully!" + +docker compose -p simulator up --build -d + +echo "โœ… Docker images successfully built and started!" \ No newline at end of file