[backport 7.x]Move retrieval of Stack version from Gradle's configuration to execution (#13042) (#13066)

The Gradle's configuration of task should be as fast as possible and don't break the build.
This commit moves retrieval of Elastic Stack version from the remote registry to the execution phase of the tasks.
Also the tasks that depends on this has received the same change (downloadEs and check EsSHA), moving from configuration to execution phase.

Close #13030

(cherry picked from commit cef339ce57)
This commit is contained in:
Andrea Selva 2021-07-13 08:53:19 +02:00 committed by GitHub
parent 09bdd51b25
commit f33522f521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,6 +158,9 @@ tasks.register("configureArchitecture") {
tasks.register("configureArtifactInfo") { tasks.register("configureArtifactInfo") {
dependsOn configureArchitecture dependsOn configureArchitecture
description "Set the url to download stack artifacts for select stack version"
doLast {
def versionQualifier = System.getenv('VERSION_QUALIFIER') def versionQualifier = System.getenv('VERSION_QUALIFIER')
if (versionQualifier) { if (versionQualifier) {
version = "$version-$versionQualifier" version = "$version-$versionQualifier"
@ -179,6 +182,7 @@ tasks.register("configureArtifactInfo") {
project.ext.set("artifactApiVersionedBuildUrl", "${artifactVersionsApi}/${qualifiedVersion}/builds/${stackBuildVersion}") project.ext.set("artifactApiVersionedBuildUrl", "${artifactVersionsApi}/${qualifiedVersion}/builds/${stackBuildVersion}")
project.ext.set("stackArtifactSuffix", qualifiedVersion) project.ext.set("stackArtifactSuffix", qualifiedVersion)
}
} }
abstract class SignAliasDefinitionsTask extends DefaultTask { abstract class SignAliasDefinitionsTask extends DefaultTask {
@ -428,12 +432,15 @@ tasks.register("installIntegrationTestGems") {
} }
} }
tasks.register("downloadFilebeat", Download) { tasks.register("downloadFilebeat") {
dependsOn configureArtifactInfo dependsOn configureArtifactInfo
description "Download Filebeat Snapshot for current branch version: ${version}" description "Download Filebeat Snapshot for current branch version: ${version}"
project.ext.set("versionFound", true) project.ext.set("versionFound", true)
inputs.file("${projectDir}/versions.yml")
doLast {
download {
String downloadedFilebeatName = "filebeat-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("beatsArchitecture")}" String downloadedFilebeatName = "filebeat-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("beatsArchitecture")}"
project.ext.set("unpackedFilebeatName", downloadedFilebeatName) project.ext.set("unpackedFilebeatName", downloadedFilebeatName)
@ -445,14 +452,12 @@ tasks.register("downloadFilebeat", Download) {
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: buildUrls["package"]["url"]) project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: buildUrls["package"]["url"])
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz") project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
src project.ext.filebeatSnapshotUrl src project.ext.filebeatSnapshotUrl
onlyIfNewer true onlyIfNewer true
inputs.file("${projectDir}/versions.yml")
outputs.file(project.ext.filebeatDownloadLocation)
dest new File(project.ext.filebeatDownloadLocation) dest new File(project.ext.filebeatDownloadLocation)
retries 3 retries 3
doLast { }
System.out.println "Downloaded to ${project.ext.filebeatDownloadLocation}" System.out.println "Downloaded to ${project.ext.filebeatDownloadLocation}"
} }
} }
@ -461,11 +466,13 @@ tasks.register("deleteLocalFilebeat", Delete) {
delete ('./build/filebeat') delete ('./build/filebeat')
} }
tasks.register("copyFilebeat", Copy){ tasks.register("copyFilebeat") {
dependsOn = [downloadFilebeat, deleteLocalFilebeat] dependsOn = [downloadFilebeat, deleteLocalFilebeat]
doLast {
copy {
from tarTree(resources.gzip(project.ext.filebeatDownloadLocation)) from tarTree(resources.gzip(project.ext.filebeatDownloadLocation))
into "./build/" into "./build/"
doLast { }
file("./build/${project.ext.unpackedFilebeatName}").renameTo('./build/filebeat') file("./build/${project.ext.unpackedFilebeatName}").renameTo('./build/filebeat')
System.out.println "Unzipped ${project.ext.filebeatDownloadLocation} to ./build/filebeat" System.out.println "Unzipped ${project.ext.filebeatDownloadLocation} to ./build/filebeat"
System.out.println "Deleting ${project.ext.filebeatDownloadLocation}" System.out.println "Deleting ${project.ext.filebeatDownloadLocation}"
@ -478,8 +485,9 @@ tasks.register("checkEsSHA") {
description "Download ES version remote's fingerprint file" description "Download ES version remote's fingerprint file"
doLast {
String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}" String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}"
outputs.file("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512")
// find url of build artifact // find url of build artifact
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz" String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz"
@ -499,22 +507,26 @@ tasks.register("checkEsSHA") {
if (localESCalculatedSHA != remoteSHACode) { if (localESCalculatedSHA != remoteSHACode) {
println "ES package calculated fingerprint is different from remote, deleting local archive" println "ES package calculated fingerprint is different from remote, deleting local archive"
delete(localESArchive) delete(localESArchive)
delete(localESCalculatedSHA)
} }
} else { }/* else {
mkdir project.buildDir mkdir project.buildDir
// touch the SHA file else downloadEs task doesn't start, this file his input for the other task // touch the SHA file else downloadEs task doesn't start, this file his input for the other task
new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512").withWriter {w -> new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512").withWriter { w ->
w << "${downloadedElasticsearchName} not yet downloaded" w << "${downloadedElasticsearchName} not yet downloaded"
w.close() w.close()
} }
}*/
} }
} }
tasks.register("downloadEs", Download) { tasks.register("downloadEs") {
dependsOn = [configureArtifactInfo, checkEsSHA] dependsOn = [configureArtifactInfo, checkEsSHA]
description "Download ES Snapshot for current branch version: ${version}" description "Download ES Snapshot for current branch version: ${version}"
inputs.file("${projectDir}/versions.yml")
doLast {
download {
String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}" String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}"
project.ext.set("unpackedElasticsearchName", "elasticsearch-${project.ext.get("stackArtifactSuffix")}") project.ext.set("unpackedElasticsearchName", "elasticsearch-${project.ext.get("stackArtifactSuffix")}")
@ -529,12 +541,9 @@ tasks.register("downloadEs", Download) {
src project.ext.elasticsearchSnapshotURL src project.ext.elasticsearchSnapshotURL
onlyIfNewer true onlyIfNewer true
retries 3 retries 3
inputs.file("${projectDir}/versions.yml")
// inputs.file("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512")
outputs.file(project.ext.elasticsearchDownloadLocation)
dest new File(project.ext.elasticsearchDownloadLocation) dest new File(project.ext.elasticsearchDownloadLocation)
}
doLast {
System.out.println "Downloaded to ${project.ext.elasticsearchDownloadLocation}" System.out.println "Downloaded to ${project.ext.elasticsearchDownloadLocation}"
} }
} }
@ -544,15 +553,18 @@ tasks.register("deleteLocalEs", Delete) {
delete ('./build/elasticsearch') delete ('./build/elasticsearch')
} }
tasks.register("copyEs", Copy) { tasks.register("copyEs") {
dependsOn = [downloadEs, deleteLocalEs] dependsOn = [downloadEs, deleteLocalEs]
doLast {
println "copyEs executing.."
copy {
from tarTree(resources.gzip(project.ext.elasticsearchDownloadLocation)) from tarTree(resources.gzip(project.ext.elasticsearchDownloadLocation))
into "./build/" into "./build/"
doLast { }
file("./build/${project.ext.unpackedElasticsearchName}").renameTo('./build/elasticsearch') file("./build/${project.ext.unpackedElasticsearchName}").renameTo('./build/elasticsearch')
System.out.println "Unzipped ${project.ext.elasticsearchDownloadLocation} to ./build/elasticsearch" println "Unzipped ${project.ext.elasticsearchDownloadLocation} to ./build/elasticsearch"
System.out.println "Deleting ${project.ext.elasticsearchDownloadLocation}" println "Deleting ${project.ext.elasticsearchDownloadLocation}"
// delete(project.ext.elasticsearchDownloadLocation)
} }
} }