-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
139 lines (119 loc) · 4.31 KB
/
Copy pathbuild.gradle
File metadata and controls
139 lines (119 loc) · 4.31 KB
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
plugins {
id 'java'
// The following line allows to load io.gatling.gradle plugin and directly apply it
id 'io.gatling.gradle' version '3.15.1.1'
id 'com.google.cloud.tools.jib' version '3.5.4'
}
def modelVersion = '3.1'
dependencies {
gatling("org.galaxio:gatling-amqp-plugin_2.13:0.15.1")
gatling("io.github.cdimascio:dotenv-java:3.2.0")
gatling("com.hubsante:models:${modelVersion}")
}
gatling {
enterprise {
// Enterprise Cloud (https://cloud.gatling.io/) configuration reference: https://gatling.io/docs/gatling/reference/current/extensions/gradle_plugin/#working-with-gatling-enterprise-cloud
// Enterprise Self-Hosted configuration reference: https://gatling.io/docs/gatling/reference/current/extensions/gradle_plugin/#working-with-gatling-enterprise-self-hosted
}
}
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/ansforge/SAMU-Hub-Modeles")
credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN')
}
}
}
configurations.all {
resolutionStrategy {
// Force newer versions to fix security vulnerabilities
force 'commons-io:commons-io:2.22.0'
force 'org.apache.sshd:sshd-common:2.19.0'
force 'org.apache.sshd:sshd-core:2.19.0'
force 'org.apache.sshd:sshd-sftp:2.19.0'
}
}
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
def discoverGatlingSimulations = {
def classesDirs = sourceSets.gatling.output.classesDirs.files
def simulations = []
classesDirs.each { dir ->
if (!dir.exists()) return
fileTree(dir).matching { include "**/simulations/*Simulation.class" }.files.each { f ->
def relPath = f.absolutePath - (dir.absolutePath + File.separator)
def fqn = relPath
.replace(File.separatorChar, '.' as char)
.replaceAll(/\.class$/, '')
simulations << fqn
}
}
simulations.unique().sort()
}
tasks.register("gatlingRunAllParallel") {
group = "gatling"
description = "Run all Gatling simulations in parallel (one thread per simulation)."
dependsOn("gatlingClasses")
doLast {
def simulations = discoverGatlingSimulations()
if (simulations.isEmpty()) {
println "No simulations found."
return
}
println "Found simulations:"
simulations.each { println " - $it" }
def gatlingCpFiles = sourceSets.gatling.runtimeClasspath.files.toList()
def pool = Executors.newFixedThreadPool(simulations.size())
def failures = Collections.synchronizedList([])
simulations.each { simulation ->
pool.submit {
try {
def simulationClassName = simulation.toString().tokenize('.').last()
def reportDir = file("${layout.buildDirectory.asFile.get()}/reports/gatling/${simulationClassName}-${System.currentTimeMillis()}")
javaexec {
classpath files(gatlingCpFiles)
mainClass = "io.gatling.app.Gatling"
args = ["-s", simulation, "-rf", reportDir.absolutePath]
}
} catch (Throwable t) {
failures << "${simulation}: ${t.message}"
t.printStackTrace()
}
}
}
pool.shutdown()
pool.awaitTermination(2, TimeUnit.HOURS)
if (!failures.isEmpty()) {
throw new GradleException("Some simulations failed:\n" + failures.join("\n"))
}
}
}
jib {
from {
image = 'eclipse-temurin:21-jdk-alpine'
}
to {
image = project.findProperty('image') ?: 'ghcr.io/ansforge/tmc:latest'
tags = [project.findProperty('version') ?: 'latest']
}
container {
entrypoint = ['./gradlew']
args = ['gatlingRunAllParallel']
jvmFlags = ['-Xms512m', '-Xmx2048m']
workingDirectory = '/app'
}
extraDirectories {
paths {
path {
from = file('.')
into = '/app'
excludes = ['build/**', '.gradle/**', '.git/**', '*.log']
}
}
permissions = [
'/app/gradlew': '755'
]
}
}