-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.gradle.kts
214 lines (192 loc) · 8.3 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import com.fasterxml.jackson.dataformat.toml.TomlMapper
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(libs.jackson.dataformat.toml)
}
}
plugins {
java
alias(libs.plugins.oci)
}
group = "com.hivemq.helmcharts"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
@Suppress("UnstableApiUsage")
testing {
suites {
val integrationTest by registering(JvmTestSuite::class) {
useJUnitJupiter(libs.versions.junit.jupiter)
dependencies {
// Custom Extension
implementation(libs.hivemq.extensionSdk)
implementation(libs.javassist)
implementation(libs.shrinkwrap.api)
runtimeOnly(libs.shrinkwrap.impl)
// Testcontainers
implementation(libs.testcontainers)
implementation(libs.testcontainers.k3s)
implementation(libs.testcontainers.hivemq)
implementation(libs.testcontainers.junitJupiter)
implementation(libs.testcontainers.selenium)
// Testing
implementation(libs.assertj)
implementation(libs.awaitility)
implementation(libs.selenium.remote.driver)
implementation(libs.selenium.java)
// Misc
implementation(libs.fabric8.kubernetes.client)
runtimeOnly(libs.bouncycastle.pkix)
runtimeOnly(libs.bouncycastle.prov)
implementation(libs.junit.platform.launcher)
implementation(libs.slf4j.api)
runtimeOnly(libs.logback.classic)
implementation(libs.rest.assured)
implementation(libs.hivemq.mqttClient)
implementation(libs.netty.codec.http)
}
targets.configureEach {
testTask {
testLogging {
events = setOf(
TestLogEvent.STARTED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.FAILED,
TestLogEvent.STANDARD_ERROR,
)
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
reports {
junitXml.isOutputPerTestCase = true
}
maxHeapSize = "3g"
doFirst {
// sets Docker image tags for the tests
val tomlFile = projectDir.resolve("gradle").resolve("docker.versions.toml")
val tomlDocker = TomlMapper().readTree(tomlFile).path("docker")
tomlDocker.fields().forEach { (key, value) ->
val tag = value.path("tag").asText()
if (tag.isNotEmpty()) {
println("Configuring test Docker image $key:$tag")
systemProperty("$key.tag", tag)
}
}
systemProperty("hivemq.tag", libs.versions.hivemq.platform.get())
val k8sVersionType = environment["K8S_VERSION_TYPE"] ?: "LATEST"
val key = if (k8sVersionType == "MINIMUM") "k3s-minimum" else "k3s-latest"
val tag = tomlDocker.path(key).path("tag").asText()
println("Configuring test Docker image k3s:$tag ($k8sVersionType)")
systemProperty("k3s.tag", tag)
systemProperty("k3s.version.type", k8sVersionType)
}
dependsOn(saveDockerImages)
inputs.files(
layout.buildDirectory.file("test-image-tars/hivemq-platform-operator-init.tar"),
layout.buildDirectory.file("test-image-tars/hivemq-platform-operator.tar"),
layout.buildDirectory.file("test-image-tars/hivemq-platform.tar"),
)
}
}
}
}
}
tasks.register("integrationTestPrepare") {
dependsOn(tasks.named("integrationTest").get().taskDependencies.getDependencies(null))
}
/* ******************** Docker Platform Operator Images ******************** */
oci {
registries {
dockerHub {
optionalCredentials()
}
}
}
val operatorImageLayoutForTesting by tasks.registering(oci.imagesLayoutTaskClass) {
from(oci.imageDependencies.create("operatorImageTarForTesting") {
runtime("com.hivemq:hivemq-platform-operator").name("hivemq/hivemq-platform-operator-test")
.tag("snapshot")
})
destinationDirectory = layout.buildDirectory.dir("test-image-tars")
classifier = "hivemq-platform-operator"
}
val operatorImageLayoutForTestingTar by tasks.existing(Tar::class) {
destinationDirectory = layout.buildDirectory.dir("test-image-tars")
archiveFileName = "hivemq-platform-operator.tar"
}
val initImageLayoutForTesting by tasks.registering(oci.imagesLayoutTaskClass) {
from(oci.imageDependencies.create("initImageTarForTesting") {
runtime("com.hivemq:hivemq-platform-operator-init").name("hivemq/hivemq-platform-operator-init-test")
.tag("snapshot")
})
destinationDirectory = layout.buildDirectory.dir("test-image-tars")
classifier = "hivemq-platform-operator-init"
}
val initImageLayoutForTestingTar by tasks.existing(Tar::class) {
destinationDirectory = layout.buildDirectory.dir("test-image-tars")
archiveFileName = "hivemq-platform-operator-init.tar"
}
val hivemqVersion = libs.versions.hivemq.platform.get()
val savePlatformDockerImage by tasks.registering(Exec::class) {
group = "container"
description = "Save HiveMQ Platform Docker image"
dependsOn(pullPlatformDockerImage)
val outputDir = layout.buildDirectory.dir("test-image-tars").get().asFile
doFirst {
if (!outputDir.exists()) {
outputDir.mkdirs()
}
}
workingDir(outputDir)
commandLine("docker", "save", "-o", "hivemq-platform.tar", "docker.io/hivemq/hivemq4:$hivemqVersion")
outputs.file(outputDir.resolve("hivemq-platform.tar"))
}
val pullPlatformDockerImage by tasks.registering(Exec::class) {
commandLine("docker", "pull", "docker.io/hivemq/hivemq4:$hivemqVersion")
}
val saveDockerImages by tasks.registering {
group = "container"
description = "Save all Platform Docker images"
dependsOn(operatorImageLayoutForTestingTar)
dependsOn(initImageLayoutForTestingTar)
dependsOn(savePlatformDockerImage)
}
/* ******************** update versions ******************** */
val updatePlatformVersion by tasks.registering {
group = "version"
val appVersion = project.properties["appVersion"]
if (appVersion != null) {
doLast {
val filesToUpdate = fileTree(projectDir).matching {
include("**/*.yml")
include("**/*.yaml")
include("**/*.json")
include("**/*.sh")
include("**/*.toml")
include("**/*.java")
// include test hivemq/mqtt-cli image to update, which is part of the hivemq-platform and hivemq-edge charts
}.plus(files("../charts/hivemq-platform/templates/tests/test-mqtt-cli.yml", "../charts/hivemq-edge/templates/tests/test-mqtt-cli.yml"))
filesToUpdate.forEach { file ->
val text = file.readText()
file.writeText(text.replace("""^hivemq-platform = \"(.*)\"$""".toRegex(RegexOption.MULTILINE)) {
"hivemq-platform = \"${appVersion}\""
}.replace("""(?i)(hivemq/hivemq4:)(\d+\.\d+\.\d+(-snapshot)?)$""".toRegex(RegexOption.MULTILINE)) {
"${it.groupValues[1]}${appVersion}${it.groupValues[3]}"
}.replace("""(?i)(hivemq/mqtt-cli:)(\d+\.\d+\.\d+(-snapshot)?)$""".toRegex(RegexOption.MULTILINE)) {
"${it.groupValues[1]}${appVersion}${it.groupValues[3]}"
})
}
}
}
}