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") }