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

feat: add docker configuration for the simulator #416

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 20 additions & 16 deletions simulator/build.gradle.kts
ata-nas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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<Copy> =
tasks.register<Copy>("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<Exec> =
tasks.register<Exec>("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")
}
ata-nas marked this conversation as resolved.
Show resolved Hide resolved
}
23 changes: 0 additions & 23 deletions simulator/docker/cleanup-docker.sh

This file was deleted.

22 changes: 12 additions & 10 deletions simulator/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

services:
simulator-publisher:
container_name: simulator-publisher
Expand All @@ -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:
ata-nas marked this conversation as resolved.
Show resolved Hide resolved
test: ["CMD", "curl", "-f", "http://localhost:9998/metrics"]
interval: 3s
Expand All @@ -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:
ata-nas marked this conversation as resolved.
Show resolved Hide resolved
simulator-publisher:
condition: service_healthy
Expand Down
19 changes: 10 additions & 9 deletions simulator/docker/prepare-docker.sh
ata-nas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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/../../.."
ata-nas marked this conversation as resolved.
Show resolved Hide resolved

# 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"
ata-nas marked this conversation as resolved.
Show resolved Hide resolved

sh -c ./update-env.sh

echo "✅ Docker build environment prepared successfully!"

docker compose -p simulator up --build -d
ata-nas marked this conversation as resolved.
Show resolved Hide resolved

echo "✅ Docker images successfully built and started!"
25 changes: 25 additions & 0 deletions simulator/docker/update-env.sh
Original file line number Diff line number Diff line change
@@ -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

ata-nas marked this conversation as resolved.
Show resolved Hide resolved
# Output the values
echo ".env properties:"
cat .env
echo
10 changes: 2 additions & 8 deletions simulator/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading