move download setup code inside the downloadEs task (#10549)

7.x clean backport of #10547
This commit is contained in:
Colin Surprenant 2019-03-13 18:04:24 -04:00 committed by GitHub
parent ebad88a358
commit f6933dbe9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -423,6 +423,9 @@ bootstrap.dependsOn installTestGems
runIntegrationTests.shouldRunAfter tasks.getByPath(":logstash-core:test") runIntegrationTests.shouldRunAfter tasks.getByPath(":logstash-core:test")
check.dependsOn runIntegrationTests check.dependsOn runIntegrationTests
task downloadEs(type: Download) {
description "Download ES Snapshot for current branch version: ${version}"
String artifactsVersionApi = "https://artifacts-api.elastic.co/v1/versions/" String artifactsVersionApi = "https://artifacts-api.elastic.co/v1/versions/"
String apiResponse = artifactsVersionApi.toURL().text String apiResponse = artifactsVersionApi.toURL().text
def dlVersions = new JsonSlurper().parseText(apiResponse) def dlVersions = new JsonSlurper().parseText(apiResponse)
@ -431,6 +434,9 @@ def dlVersions = new JsonSlurper().parseText(apiResponse)
// in the build invoked by the release manager it is '7.0.0-alpha1' etc. // in the build invoked by the release manager it is '7.0.0-alpha1' etc.
// the artifacts-api will return JSON like this: `{"versions":["5.6.13-SNAPSHOT","6.4.3-SNAPSHOT","6.5.0-SNAPSHOT","6.6.0-SNAPSHOT","7.0.0-alpha1-SNAPSHOT"]}` // the artifacts-api will return JSON like this: `{"versions":["5.6.13-SNAPSHOT","6.4.3-SNAPSHOT","6.5.0-SNAPSHOT","6.6.0-SNAPSHOT","7.0.0-alpha1-SNAPSHOT"]}`
String qualifiedVersion = dlVersions['versions'].grep(~/^${version}.*/)[0] String qualifiedVersion = dlVersions['versions'].grep(~/^${version}.*/)[0]
if (qualifiedVersion == "null") {
throw new GradleException("could not find the current artifact from the artifact-api for version: ${version}, api response was: ${apiResponse}")
}
String arch = "x86_64" String arch = "x86_64"
String osName = System.properties['os.name'] String osName = System.properties['os.name']
@ -444,7 +450,7 @@ if (osName ==~ /Mac OS X/) {
String architecture = "${osName}-${arch}" String architecture = "${osName}-${arch}"
String downloadedElasticsearchName = "elasticsearch-${qualifiedVersion}-${architecture}" String downloadedElasticsearchName = "elasticsearch-${qualifiedVersion}-${architecture}"
String unpackedElasticsearchName = "elasticsearch-${qualifiedVersion}" project.ext.set("unpackedElasticsearchName", "elasticsearch-${qualifiedVersion}")
// find latest reference to last build // find latest reference to last build
String buildsListApi = "https://artifacts-api.elastic.co/v1/versions/${qualifiedVersion}/builds/" String buildsListApi = "https://artifacts-api.elastic.co/v1/versions/${qualifiedVersion}/builds/"
@ -458,22 +464,15 @@ apiResponse = artifactApiUrl.toURL().text
def buildUrls = new JsonSlurper().parseText(apiResponse) def buildUrls = new JsonSlurper().parseText(apiResponse)
String elasticsearchSnapshotURL = System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: buildUrls["package"]["url"] String elasticsearchSnapshotURL = System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: buildUrls["package"]["url"]
String elasticsearchDownloadLocation = "${projectDir}/build/${downloadedElasticsearchName}.tar.gz" project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
task downloadEs(type: Download) {
description "Download ES Snapshot for current branch version: ${version}"
doFirst {
if (qualifiedVersion == "null") {
throw new GradleException("could not find the current artifact from the artifact-api for version: ${version}, api response was: ${apiResponse}")
}
}
src elasticsearchSnapshotURL src elasticsearchSnapshotURL
onlyIfNewer true onlyIfNewer true
inputs.file("${projectDir}/versions.yml") inputs.file("${projectDir}/versions.yml")
outputs.file(elasticsearchDownloadLocation) outputs.file(project.ext.elasticsearchDownloadLocation)
dest new File(elasticsearchDownloadLocation) dest new File(project.ext.elasticsearchDownloadLocation)
doLast { doLast {
System.out.println "Downloaded to ${elasticsearchDownloadLocation}" System.out.println "Downloaded to ${project.ext.elasticsearchDownloadLocation}"
} }
} }
@ -482,10 +481,10 @@ task deleteLocalEs(type: Delete) {
} }
task copyEs(type: Copy, dependsOn: [downloadEs, deleteLocalEs]) { task copyEs(type: Copy, dependsOn: [downloadEs, deleteLocalEs]) {
from tarTree(resources.gzip(elasticsearchDownloadLocation)) from tarTree(resources.gzip(project.ext.elasticsearchDownloadLocation))
into "./build/" into "./build/"
doLast { doLast {
file("./build/${unpackedElasticsearchName}").renameTo('./build/elasticsearch') file("./build/${project.ext.unpackedElasticsearchName}").renameTo('./build/elasticsearch')
} }
} }