Skip to content

Commit 596d1d1

Browse files
committed
Add minio support
1 parent 32e89b1 commit 596d1d1

File tree

1 file changed

+152
-1
lines changed

1 file changed

+152
-1
lines changed

plugins/repository-s3/build.gradle

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
import org.elasticsearch.gradle.LoggedExec
13
import org.elasticsearch.gradle.MavenFilteringHack
24
import org.elasticsearch.gradle.test.AntFixture
5+
import org.elasticsearch.gradle.test.ClusterConfiguration
6+
import org.elasticsearch.gradle.test.RestIntegTestTask
37

48
/*
59
* Licensed to Elasticsearch under one or more contributor
@@ -77,11 +81,158 @@ String s3BasePath = System.getenv("amazon_s3_base_path")
7781
if (!s3AccessKey && !s3SecretKey && !s3Bucket && !s3BasePath) {
7882
s3AccessKey = 's3_integration_test_access_key'
7983
s3SecretKey = 's3_integration_test_secret_key'
80-
s3Bucket = 'bucket_test'
84+
s3Bucket = 'bucket-test'
8185
s3BasePath = 'integration_test'
8286
useFixture = true
8387
}
8488

89+
final String minioVersion = 'RELEASE.2018-06-22T23-48-46Z'
90+
final String minioBinDir = "${buildDir}/minio/bin"
91+
final String minioDataDir = "${buildDir}/minio/data"
92+
final String minioAddress = "localhost:60920"
93+
94+
final String minioDistribution
95+
final String minioCheckSum
96+
if (Os.isFamily(Os.FAMILY_MAC)) {
97+
minioDistribution = 'darwin-amd64'
98+
minioCheckSum = '96b0bcb2f590e8e65fb83d5c3e221f9bd1106b49fa6f22c6b726b80b845d7c60'
99+
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
100+
minioDistribution = 'linux-amd64'
101+
minioCheckSum = '713dac7c105285eab3b92649be92b5e793b29d3525c7929fa7aaed99374fad99'
102+
} else {
103+
minioDistribution = null
104+
minioCheckSum = null
105+
}
106+
107+
buildscript {
108+
repositories {
109+
maven {
110+
url 'https://plugins.gradle.org/m2/'
111+
}
112+
}
113+
dependencies {
114+
classpath 'de.undercouch:gradle-download-task:3.4.3'
115+
}
116+
}
117+
118+
if (minioDistribution) {
119+
apply plugin: 'de.undercouch.download'
120+
121+
final String minioFileName = "minio.${minioVersion}"
122+
final String minioDownloadURL = "https://dl.minio.io/server/minio/release/${minioDistribution}/archive/${minioFileName}"
123+
final String minioFilePath = "${gradle.gradleUserHomeDir}/downloads/minio/${minioDistribution}/${minioFileName}"
124+
125+
task downloadMinio(type: Download) {
126+
src minioDownloadURL
127+
dest minioFilePath
128+
onlyIfModified true
129+
}
130+
131+
task verifyMinioChecksum(type: Verify, dependsOn: downloadMinio) {
132+
src minioFilePath
133+
algorithm 'SHA-256'
134+
checksum minioCheckSum
135+
}
136+
137+
task installMinio(type: Sync, dependsOn: verifyMinioChecksum) {
138+
from minioFilePath
139+
into minioBinDir
140+
fileMode 0755
141+
}
142+
143+
long minioPid
144+
145+
task startMinio {
146+
dependsOn installMinio
147+
doLast {
148+
new File("${minioDataDir}/${s3Bucket}").mkdirs()
149+
// we skip these tests on Windows so we do no need to worry about compatibility here
150+
final ProcessBuilder minio = new ProcessBuilder(
151+
"${minioBinDir}/${minioFileName}",
152+
"server",
153+
"--address",
154+
minioAddress,
155+
minioDataDir)
156+
minio.addShutdownHook { minio.destroy() }
157+
minio.environment().put('MINIO_ACCESS_KEY', s3AccessKey)
158+
minio.environment().put('MINIO_SECRET_KEY', s3SecretKey)
159+
minio.environment().put('MINIO_DOMAIN', 'localhost')
160+
final Process process = minio.start()
161+
minioPid = process.pid()
162+
163+
new BufferedReader(new InputStreamReader(process.getInputStream())).withReader { br ->
164+
String line
165+
int httpPort = 0
166+
while ((line = br.readLine()) != null) {
167+
logger.info(line)
168+
if (line.matches('.*Endpoint.*:\\d+$')) {
169+
assert httpPort == 0
170+
final int index = line.lastIndexOf(":")
171+
assert index >= 0
172+
httpPort = Integer.parseInt(line.substring(index + 1))
173+
174+
final File script = new File(project.buildDir, "minio/minio.killer.sh")
175+
script.setText(
176+
["function shutdown {",
177+
" kill ${minioPid}",
178+
"}",
179+
"trap shutdown EXIT",
180+
// will wait indefinitely for input, but we never pass input, and the pipe is only closed when the build dies
181+
"read line\n"].join('\n'), 'UTF-8')
182+
final ProcessBuilder killer = new ProcessBuilder("bash", script.absolutePath)
183+
killer.start()
184+
break
185+
}
186+
}
187+
188+
assert httpPort > 0
189+
}
190+
}
191+
}
192+
193+
task stopMinio(type: LoggedExec) {
194+
onlyIf { minioPid > 0 }
195+
196+
doFirst {
197+
logger.info("Shutting down minio with pid ${minioPid}")
198+
}
199+
200+
final Object pid = "${ -> minioPid }"
201+
202+
// we skip these tests on Windows so we do no need to worry about compatibility here
203+
executable = 'kill'
204+
args('-9', pid)
205+
}
206+
207+
RestIntegTestTask integTestMinio = project.tasks.create('integTestMinio', RestIntegTestTask.class) {
208+
description = "Runs REST tests using the Minio repository."
209+
}
210+
211+
// The following closure must execute before the afterEvaluate block in the constructor of the following integrationTest tasks:
212+
project.afterEvaluate {
213+
ClusterConfiguration cluster = project.extensions.getByName('integTestMinioCluster') as ClusterConfiguration
214+
cluster.dependsOn(project.bundlePlugin)
215+
cluster.keystoreSetting 's3.client.integration_test.access_key', s3AccessKey
216+
cluster.keystoreSetting 's3.client.integration_test.secret_key', s3SecretKey
217+
cluster.setting 's3.client.integration_test.endpoint', "http://${minioAddress}"
218+
219+
Task restIntegTestTask = project.tasks.getByName('integTestMinio')
220+
restIntegTestTask.clusterConfig.plugin(project.path)
221+
222+
// Default jvm arguments for all test clusters
223+
String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
224+
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
225+
" " + System.getProperty('tests.jvm.argline', '')
226+
227+
restIntegTestTask.clusterConfig.jvmArgs = jvmArgs
228+
}
229+
230+
integTestMinioRunner.dependsOn(startMinio)
231+
integTestMinioRunner.finalizedBy(stopMinio)
232+
233+
project.check.dependsOn(integTestMinio)
234+
}
235+
85236
/** A task to start the AmazonS3Fixture which emulates an S3 service **/
86237
task s3Fixture(type: AntFixture) {
87238
dependsOn testClasses

0 commit comments

Comments
 (0)