Skip to content

Commit

Permalink
addressing pr comment
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Nov 13, 2024
1 parent 66d7417 commit 10781af
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
${{ runner.os }}-gradle-
- name: Build And Run Smoke Tests Container
run: ${{ env.GRADLE_EXEC }} buildAndRunSmokeTestsContainer -x test
run: ${{ env.GRADLE_EXEC }} startDockerContainerSmokeTest

- name: Run Smoke Test
working-directory: server/src/test/resources/
Expand Down
120 changes: 62 additions & 58 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,96 +64,100 @@ tasks.register("bumpVersion") {
}

// Vals
val buildRootAbsolutePath: String =
layout.buildDirectory.get().asFile.toPath().toAbsolutePath().toString()
val buildRootEnvFileAbsolutePath: String = "$buildRootAbsolutePath/.env"
val dockerRootDirectory: Directory = layout.projectDirectory.dir("docker")
val dockerProjectRootDirectory: Directory = layout.projectDirectory.dir("docker")
val dockerBuildRootDirectory: Directory = layout.buildDirectory.dir("docker").get()

// Docker related tasks
val updateDockerEnv: TaskProvider<Exec> =
tasks.register<Exec>("updateDockerEnv") {
val copyDockerFolder: TaskProvider<Copy> =
tasks.register<Copy>("copyDockerFolder") {
description = "Copies the docker folder to the build root directory"
group = "docker"

from(dockerProjectRootDirectory)
into(dockerBuildRootDirectory)
}

val createDockerImage: TaskProvider<Exec> =
tasks.register<Exec>("createDockerImage") {
description =
"Creates the .env file in the docker folder that contains environment variables for docker"
"Creates the production docker image of the Block Node Server based on the current version"
group = "docker"

workingDir(dockerRootDirectory)
dependsOn(copyDockerFolder, tasks.assemble)
workingDir(dockerBuildRootDirectory)
commandLine(
"sh",
"-c",
"./update-env.sh $buildRootAbsolutePath ${project.version} false false"
"./update-env.sh ${project.version} false false && ./docker-build.sh ${project.version}"
)
}

val createDockerImage: TaskProvider<Exec> =
tasks.register<Exec>("createDockerImage") {
val createDockerImageDebug: TaskProvider<Exec> =
tasks.register<Exec>("createDockerImageDebug") {
description =
"Creates the docker image of the Block Node Server based on the current version"
"Creates the debug docker image of the Block Node Server based on the current version"
group = "docker"

dependsOn(updateDockerEnv, tasks.assemble)
workingDir(dockerRootDirectory)
commandLine("./docker-build.sh", project.version, layout.projectDirectory.dir("..").asFile)
dependsOn(copyDockerFolder, tasks.assemble)
workingDir(dockerBuildRootDirectory)
commandLine(
"sh",
"-c",
"./update-env.sh ${project.version} true false && ./docker-build.sh ${project.version}"
)
}

val createDockerImageSmokeTest: TaskProvider<Exec> =
tasks.register<Exec>("createDockerImageSmokeTest") {
description =
"Creates the smoke tests docker image of the Block Node Server based on the current version"
group = "docker"

dependsOn(copyDockerFolder, tasks.assemble)
workingDir(dockerBuildRootDirectory)
commandLine(
"sh",
"-c",
"./update-env.sh ${project.version} false true && ./docker-build.sh ${project.version}"
)
}

tasks.register<Exec>("startDockerContainer") {
description = "Starts the docker container of the Block Node Server of the current version"
description = "Starts the docker container of the Block Node Server for the current version"
group = "docker"

dependsOn(createDockerImage)
workingDir(dockerRootDirectory)
commandLine(
"sh",
"-c",
"docker compose --env-file $buildRootEnvFileAbsolutePath -p block-node up -d"
)
workingDir(dockerBuildRootDirectory)
commandLine("sh", "-c", "docker compose -p block-node up -d")
}

tasks.register<Exec>("startDockerDebugContainer") {
description = "Starts the docker container of the Block Node Server of the current version"
tasks.register<Exec>("startDockerContainerDebug") {
description = "Starts the docker debug container of the Block Node Server for the current version"
group = "docker"

dependsOn(createDockerImage)
workingDir(dockerRootDirectory)
dependsOn(createDockerImageDebug)
workingDir(dockerBuildRootDirectory)
commandLine("sh", "-c", "docker compose -p block-node up -d")
}

tasks.register<Exec>("startDockerContainerSmokeTest") {
description = "Starts the docker smoke test container of the Block Node Server for the current version"
group = "docker"

dependsOn(createDockerImageSmokeTest)
workingDir(dockerBuildRootDirectory)
commandLine(
"sh",
"-c",
"./update-env.sh $buildRootAbsolutePath ${project.version} true false && docker compose --env-file $buildRootEnvFileAbsolutePath -p block-node up -d"
"docker compose -p block-node up -d"
)
}

tasks.register<Exec>("stopDockerContainer") {
description = "Stops running docker containers of the Block Node Server"
group = "docker"

workingDir(dockerRootDirectory)
dependsOn(copyDockerFolder)
workingDir(dockerBuildRootDirectory)
commandLine("sh", "-c", "docker compose -p block-node stop")
}

tasks.register("buildAndRunSmokeTestsContainer") {
doFirst {
// ensure smoke test .env properties before creating the container
exec {
workingDir(dockerRootDirectory)
commandLine(
"sh",
"-c",
"./update-env.sh $buildRootAbsolutePath ${project.version} false true"
)
}
}

// build the project
dependsOn(tasks.build)

doLast {
// build and start smoke test container
exec {
workingDir(dockerRootDirectory)
commandLine(
"sh",
"-c",
"./docker-build.sh ${project.version} && docker compose --env-file $buildRootEnvFileAbsolutePath -p block-node up -d"
)
}
}
}
8 changes: 4 additions & 4 deletions server/docker/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ fi

VERSION=$1

echo "CREATING CONTAINER FOR VERSION ${VERSION}"
echo "Using project directory: ${2}"
echo "Building image [block-node-server:${VERSION}]"
echo

# run docker build
echo "Building image [block-node-server:${VERSION}]"
docker buildx build --load -t "block-node-server:${VERSION}" --build-context distributions=../build/distributions --build-arg VERSION="${VERSION}" . || exit "${?}"
docker buildx build --load -t "block-node-server:${VERSION}" --build-context distributions=../distributions --build-arg VERSION="${VERSION}" . || exit "${?}"

echo
echo "Image [block-node-server:${VERSION}] built successfully!"
2 changes: 1 addition & 1 deletion server/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
container_name: block-node-server
image: block-node-server:${VERSION}
env_file:
- ../build/.env
- .env
ports:
- "8080:8080"
- "5005:5005"
Expand Down
17 changes: 7 additions & 10 deletions server/docker/update-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
# This scripts create a '.env' file that is used for docker & docker-compose as an input of environment variables.
# This script is called by gradle and get the current project version as an input param

if [ $# -lt 2 ]; then
# <PROJECT_BUILD_ROOT> and <VERSION> are required!
echo "USAGE: $0 <PROJECT_BUILD_ROOT> <VERSION> [DEBUG] [SMOKE_TEST]"
if [ $# -lt 1 ]; then
# <VERSION> is required!
echo "USAGE: $0 <VERSION> [DEBUG] [SMOKE_TEST]"
exit 1
fi

project_build_root=$1
project_version=$2
project_version=$1
# determine if we should include debug opts
[ "$3" = true ] && is_debug=true || is_debug=false
[ "$2" = true ] && is_debug=true || is_debug=false
# determine if we should include smoke test env variables
[ "$4" = true ] && is_smoke_test=true || is_smoke_test=false

# work only inside the scope of the project build root
cd "$project_build_root" || exit 1
[ "$3" = true ] && is_smoke_test=true || is_smoke_test=false

echo "VERSION=$project_version" > .env
echo "REGISTRY_PREFIX=" >> .env
Expand All @@ -42,3 +38,4 @@ fi
# Output the values
echo ".env properties:"
cat .env
echo

0 comments on commit 10781af

Please sign in to comment.