From 5c618116148b891e148cee23f41722af2c5243e1 Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Thu, 1 Jun 2023 17:02:05 +0200 Subject: [PATCH] SONAR-19498 stop fetching ElasticSearch manually (and benefit from caching) --- .cirrus.yml | 2 -- build.gradle | 47 ++++++++++++++++++++++++---------- gradle.properties | 8 +----- sonar-application/build.gradle | 46 +++++++++++---------------------- 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 815f8fb7de4..25fe4ab5850 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -209,8 +209,6 @@ build_task: <<: *CONTAINER_TEMPLATE cpu: 7.5 memory: 8Gb - elasticsearch_distribution_cache: - folder: sonar-application/build/elasticsearch-**.tar.gz script: - ./private/cirrus/cirrus-build.sh <<: *DEFAULT_ARTIFACTS_TEMPLATE diff --git a/build.gradle b/build.gradle index c02e68d4177..24209940ff4 100644 --- a/build.gradle +++ b/build.gradle @@ -75,22 +75,41 @@ allprojects { repositories { def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource' + // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins) + // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties + def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '') + def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '') + maven { - // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins) - // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties - def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '') - def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '') - if (artifactoryUsername && artifactoryPassword) { - credentials { - username artifactoryUsername - password artifactoryPassword + if (artifactoryUsername && artifactoryPassword) { + credentials { + username artifactoryUsername + password artifactoryPassword + } + } else { + // Workaround for artifactory + // https://www.jfrog.com/jira/browse/RTFACT-13797 + repository = 'public' } - } else { - // Workaround for artifactory - // https://www.jfrog.com/jira/browse/RTFACT-13797 - repository = 'public' - } - url "https://repox.jfrog.io/repox/${repository}" + url "https://repox.jfrog.io/repox/${repository}" + } + ivy { + if (artifactoryUsername && artifactoryPassword) { + credentials { + username artifactoryUsername + password artifactoryPassword + } + } else { + // Workaround for artifactory + // https://www.jfrog.com/jira/browse/RTFACT-13797 + repository = 'public' + } + url "https://repox.jfrog.io/repox/sonarsource-bucket" + + patternLayout { + artifact '/[organisation]/[module]/[module]-[revision].[ext]' + } + metadataSources { artifact() } } } diff --git a/gradle.properties b/gradle.properties index 028afe00263..0839cc535e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,12 +6,6 @@ projectTitle=SonarQube org.gradle.jvmargs=-Xmx2048m org.gradle.caching=true org.gradle.vfs.watch=true -# https://www.elastic.co/downloads/elasticsearch-no-jdk -elasticsearchDownloadUrlPath=https://artifacts.elastic.co/downloads/elasticsearch/ -elasticsearchDownloadRepoxUrlPath=https://repox.jfrog.io/artifactory/sonarsource-bucket/sonarqube/elasticsearch/ -elasticsearchDownloadUrlFileNoJdk=elasticsearch-8.7.0-no-jdk-linux-x86_64.tar.gz -elasticsearchDownloadUrlFileJdk=elasticsearch-8.7.0-linux-x86_64.tar.gz -elasticsearchDownloadSha512NoJdk=155ff74d55ff4ec9abe04877fd9da50f7083e5dee6c80fc85d61819fa1ca3e22dfa70478ab0632d89f1ec10153cfb38361c88a9babf4a4900cfd2d0639346673 -elasticsearchDownloadSha512Jdk=7ac6ee5e2e2ccee1ebb20a1c94992b90e879b8b37273d59ae1496b1e8ae5499ae1b6ddce8cea7dda3b63e7e45352735b2bd3328ad0fdd6d6aadb020de21eb894 +elasticsearchVersion=8.7.0 projectType=application org.gradle.logging.level=info diff --git a/sonar-application/build.gradle b/sonar-application/build.gradle index ee3c8fc7c8d..ba920c13849 100644 --- a/sonar-application/build.gradle +++ b/sonar-application/build.gradle @@ -15,6 +15,7 @@ sonar { } configurations { + zipDist zip scanner web @@ -72,6 +73,15 @@ dependencies { jdbc_h2 'com.h2database:h2' jdbc_mssql 'com.microsoft.sqlserver:mssql-jdbc' jdbc_postgresql 'org.postgresql:postgresql' + + def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '') + def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '') + if (artifactoryUsername && artifactoryPassword) { + zipDist "sonarqube:elasticsearch:${elasticsearchVersion}-no-jdk-linux-x86_64@tar.gz" + } else { + zipDist "sonarqube:elasticsearch:${elasticsearchVersion}-linux-x86_64@tar.gz" + } + } // declare dependencies in configuration bundledPlugin to be packaged in lib/extensions @@ -90,40 +100,12 @@ task verifySonarProperties(type: Verify) { } } -def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '') -def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '') - -task verifyElasticSearchDownload(type: Verify) { - if (artifactoryUsername && artifactoryPassword) { - src new File(buildDir, "$elasticsearchDownloadUrlFileNoJdk") - algorithm 'SHA-512' - checksum elasticsearchDownloadSha512NoJdk - } else { - src new File(buildDir, "$elasticsearchDownloadUrlFileJdk") - algorithm 'SHA-512' - checksum elasticsearchDownloadSha512Jdk - } -} - -task downloadElasticSearch(type: Download) { - if (artifactoryUsername && artifactoryPassword) { - src "$elasticsearchDownloadRepoxUrlPath$elasticsearchDownloadUrlFileNoJdk" - username artifactoryUsername - password artifactoryPassword - dest "$buildDir/$elasticsearchDownloadUrlFileNoJdk" - } else { - src "$elasticsearchDownloadUrlPath$elasticsearchDownloadUrlFileJdk" - dest "$buildDir/$elasticsearchDownloadUrlFileJdk" - } - onlyIfModified true - finalizedBy verifyElasticSearchDownload -} downloadLicenses { dependencyConfiguration = 'appLicenses' } -task zip(type: Zip, dependsOn: [configurations.compileClasspath, downloadElasticSearch, verifyElasticSearchDownload]) { +task zip(type: Zip, dependsOn: [configurations.compileClasspath]) { duplicatesStrategy DuplicatesStrategy.EXCLUDE def archiveDir = "sonarqube-$project.version" @@ -147,8 +129,10 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, downloadElastic } } - - from(tarTree(downloadElasticSearch.dest)) { + ResolvedArtifact elasticSearchArtifact = configurations.zipDist.resolvedConfiguration.resolvedArtifacts.find { + it.moduleVersion.id.name == "elasticsearch" + } + from(tarTree(elasticSearchArtifact.file)) { eachFile { fcd -> def path = fcd.relativePath.segments - fcd.relativeSourcePath.segments + fcd.relativeSourcePath.segments.drop(1) fcd.relativePath = new RelativePath(true, *path) -- 2.39.5