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

Build scripts updated and refactored #225

Merged
merged 9 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ repositories {
mavenLocal()
jcenter()
gradlePluginPortal()
maven { url = uri("https://plugins.gradle.org/m2") }
maven { url = uri("http://dl.bintray.com/cognifide/maven-public") }
maven { url = uri("https://dl.bintray.com/neva-dev/maven-public") }
maven {
url = uri("https://plugins.gradle.org/m2")
url = uri("http://dl.bintray.com/cognifide/maven-public")
url = uri("https://dl.bintray.com/neva-dev/maven-public")
}
Comment on lines +9 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets group them together

}

dependencies {
implementation("com.moowork.gradle:gradle-node-plugin:1.2.0")
Copy link
Contributor Author

@szymon-owczarzak szymon-owczarzak Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating node causes a lot of problems... i left it un-updated

implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
implementation("com.bmuschko:gradle-docker-plugin:4.10.0")
implementation("net.researchgate:gradle-release:2.6.0")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle-release No longer in use

implementation("io.knotx:knotx-gradle-plugins:0.1.2")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61")
implementation("com.bmuschko:gradle-docker-plugin:6.1.2")
implementation("io.knotx:knotx-gradle-plugins:0.1.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BoardsAndWidgetsController : AbstractVerticle() {

private fun prepareConfig() = mapOf<String, (JsonObject) -> String>(
"update" to { body -> update(body) },
"get" to { body -> boardsConfigService.loadBoardsConfig().toString() }
"get" to { _ -> boardsConfigService.loadBoardsConfig().toString() }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detekt fix

)

private fun update(body: JsonObject): String {
Expand Down
8 changes: 4 additions & 4 deletions cogboard-webapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.moowork.gradle.node.NodeExtension
import com.moowork.gradle.node.npm.NpmTask

plugins {
Expand All @@ -8,7 +7,7 @@ plugins {
id("com.bmuschko.docker-remote-api")
}

configure<NodeExtension> {
node {
version = "10.16.0"
download = true
}
Expand All @@ -24,10 +23,11 @@ tasks {
inputs.dir("public")
outputs.dir(buildDir)
}
register<DockerBuildImage> ("buildImage") {

register<DockerBuildImage>("buildImage") {
group = "docker"
inputDir.set(file("$projectDir"))
tags.add("${rootProject.property("docker.web.image.name")}:$version")
images.add("${rootProject.property("docker.web.image.name")}:$version")
dependsOn("buildReactApp")
}
}
178 changes: 89 additions & 89 deletions gradle/docker.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerRemoveImage

val projectDir = rootProject.projectDir.absolutePath.replace("\\", "/");
val dockerImageRef = "$buildDir/.docker/buildImage-imageId.txt"
val dockerContainerName = project.property("docker.app.container.name")?.toString() ?: "cogboard"
val dockerImageName = project.property("docker.app.image.name")?.toString() ?: "cogboard/cogboard-app"
val mountDir = "${rootProject.projectDir.absolutePath.replace("\\", "/")}/mnt"
val cypressContentPath = "${rootProject.projectDir.absolutePath.replace("\\", "/")}/cogboard-app/src/main/resources/cypressData/config.json"
val defaultCypressTestsDir = "${rootProject.projectDir.absolutePath.replace("\\", "/")}/functional/cypress-tests"
val functionalTestsPath = System.getProperty("functionalTestPath")?:defaultCypressTestsDir
val cypressEnvCode = System.getProperty("cypressEnv")?:"local"
val cypressConfigPath = "cypress/config/" + cypressEnvCode + ".json"
val mountDir = "$projectDir/mnt"
val cypressContentPath = "$projectDir/cogboard-app/src/main/resources/cypressData/config.json"
val defaultCypressTestsDir = "$projectDir/functional/cypress-tests"
val functionalTestsPath = System.getProperty("functionalTestPath") ?: defaultCypressTestsDir
val cypressEnvCode = System.getProperty("cypressEnv") ?: "local"
val cypressConfigPath = "cypress/config/$cypressEnvCode.json"
val network = "${project.name}-local_cognet"
val wsPort = project.property("ws.port")
val appPort = project.property("app.port")
Expand All @@ -33,106 +34,105 @@ logger.lifecycle(">> dockerContainerName: $dockerContainerName")
logger.lifecycle(">> dockerImageName: $dockerImageName")
logger.lifecycle(">> mountDir: $mountDir")
logger.lifecycle(">> functionalTestsPath: $functionalTestsPath")
logger.lifecycle(">> cypressConfigPath: $cypressConfigPath")

tasks {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task registration is now grouped in { ... }


task("cogboard-is-running") {
dependsOn("build")
doLast {
logger.lifecycle("Running docker image")
exec {
commandLine(
"docker", "run", "--rm",
"-p$appPort:8092", // main app port
"-p1$appPort:18092", // remote debug port
"-p$wsPort:$wsPort", // web socket port
"--name", dockerContainerName,
"-v", "$mountDir:/data", // docker volume
dockerImageName
)
register<DockerRemoveImage>("removeImage") {
group = "docker"

onlyIf { File(dockerImageRef).exists() }

targetImageId(if (File(dockerImageRef).exists()) File(dockerImageRef).readText() else "")
onError {
if (!this.message!!.contains("No such image"))
throw this
}
}
}

tasks.register<DockerRemoveImage>("removeImage") {
group = "docker"

onlyIf { File(dockerImageRef).exists() }
register<DockerBuildImage>("buildImage") {
group = "docker"

targetImageId(if (File(dockerImageRef).exists()) File(dockerImageRef).readText() else "")
onError {
if (!this.message!!.contains("No such image"))
throw this
inputDir.set(file("$buildDir"))
images.add("$dockerImageName:$version")
dependsOn("prepareDocker", "build")
}
}

tasks.register<DockerBuildImage> ("buildImage") {
group = "docker"
inputDir.set(file("$buildDir"))
tags.add("$dockerImageName:$version")
dependsOn("prepareDocker", "build")
}

tasks.register<Exec>("updateLocal") {
group = "docker"
commandLine = listOf("docker", "service", "update", "--force", "${project.name}-local_cogboard")
}
register<Exec>("updateLocal") {
group = "docker"
commandLine = listOf("docker", "service", "update", "--force", "${project.name}-local_cogboard")
}

tasks.register<Exec>("updateMocks") {
group = "docker"
commandLine = listOf("docker", "service", "update", "--force", "${project.name}-local_api-mocks")
}
register<Exec>("updateMocks") {
group = "docker"
commandLine = listOf("docker", "service", "update", "--force", "${project.name}-local_api-mocks")
}

tasks.register<Exec>("initSwarm") {
group = "swarm"
commandLine = listOf("docker", "swarm", "init")
isIgnoreExitValue = true
}
register<Exec>("initSwarm") {
group = "swarm"
commandLine = listOf("docker", "swarm", "init")
isIgnoreExitValue = true
}

tasks.register<Exec>("awaitLocalStackUndeployed") {
commandLine = listOf("docker", "network", "inspect", network)
isIgnoreExitValue = true
errorOutput = java.io.ByteArrayOutputStream()
doLast {
if (errorOutput.toString().contains("Error: No such network")) {
//we are happy, since this network is down we can proceed
} else {
Thread.sleep(15 * 1000) // let's wait for better times
register<Exec>("awaitLocalStackUndeployed") {
commandLine = listOf("docker", "network", "inspect", network)
isIgnoreExitValue = true
errorOutput = java.io.ByteArrayOutputStream()
doLast {
if (errorOutput.toString().contains("Error: No such network")) {
//we are happy, since this network is down we can proceed
} else {
Thread.sleep(15 * 1000) // let's wait for better times
}
}
mustRunAfter("build")
}
mustRunAfter("build")
}

tasks.register<Exec>("deployLocal") {
environment = mapOf("COGBOARD_VERSION" to version)
group = "swarm"
commandLine = listOf("docker", "stack", "deploy", "-c", "${project.name}-local-compose.yml", "${project.name}-local")
dependsOn("initSwarm", "buildImage", "awaitLocalStackUndeployed")
mustRunAfter("undeployLocal")
}

tasks.register<Exec>("undeployLocal") {
group = "swarm"
commandLine = listOf("docker", "stack", "rm", "${project.name}-local")
dependsOn("initSwarm")
}
register<Exec>("deployLocal") {
environment = mapOf("COGBOARD_VERSION" to version)
group = "swarm"
commandLine = listOf("docker", "stack", "deploy", "-c", "${project.name}-local-compose.yml", "${project.name}-local")
dependsOn("initSwarm", "buildImage", "awaitLocalStackUndeployed")
mustRunAfter("undeployLocal")
}

tasks.register("redeployLocal") {
group = "swarm"
dependsOn("undeployLocal", "deployLocal")
}
register<Exec>("undeployLocal") {
group = "swarm"
commandLine = listOf("docker", "stack", "rm", "${project.name}-local")
dependsOn("initSwarm")
}

tasks.register<Exec>("functionalTests") {
group = "docker-functional-tests"
commandLine = listOf("docker", "run", "-v","$functionalTestsPath:/e2e","-w","/e2e","--network=$network", "cypress/included:3.8.0", "--browser", "chrome", "--config-file", "$cypressConfigPath")
register("redeployLocal") {
group = "swarm"
dependsOn("undeployLocal", "deployLocal")
}

dependsOn("redeployLocal", "copyCypressContent" )
doFirst {
logger.lifecycle("Running functional tests from $functionalTestsPath with base network: $network")
register<Exec>("functionalTests") {
group = "Docker Functional Tests"
commandLine = listOf(
"docker", "run",
"-v", "$functionalTestsPath:/e2e",
"-w", "/e2e",
"--network=$network",
"cypress/included:3.8.0",
"--browser", "chrome",
"--config-file", cypressConfigPath
)

dependsOn("redeployLocal", "copyCypressContent")
doFirst {
logger.lifecycle("Running functional tests from $functionalTestsPath with base network: $network")
}
}
}

tasks.register<Exec>("copyCypressContent") {
group = "docker-functional-tests"
commandLine = listOf("sh", "scripts/copyCypressContent.sh", "$cypressContentPath", "$mountDir")
mustRunAfter("redeployLocal")
Comment on lines -134 to -137
Copy link
Contributor Author

@szymon-owczarzak szymon-owczarzak Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staszke - We have better approach for copying files - lets use the old way without unnecessary script that will not work when you don't have shell sh installed on your system.

register<Copy>("copyCypressContent") {
group = "Docker Functional Tests"

from(cypressContentPath)
into(mountDir)
doLast {
logger.lifecycle(">> Automated testing data has been successfully copied")
}
mustRunAfter("redeployLocal")
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 0 additions & 2 deletions scripts/copyCypressContent.sh

This file was deleted.