Skip to content

Commit

Permalink
Build local unreleased bwc versions more efficient for tests (7.x bac…
Browse files Browse the repository at this point in the history
…kport) (#63188)

* Wire local unreleased bwc versions more efficient for tests (#62473)

For testing against the local distribution we already avoid the packaging/unpackaging 
cycle of es distributions when setting up test clusters. This PR adopts the usage of the
expanded created distributions for unreleased bwc versions (versions that are checkout 
from a branch and build from source in the :distribution:bwc:minor / :distribution:bwc:bugfix). 
This makes the setup of bwc based cross version tests a bit faster by avoiding 
the unpackaging overhead. We still assemble both in the bwcBuild tasks atm 
which will be addressed in a later issue.

This reworks the :distribution:bwc project:

- Convert all the custom logic from build script logic (groovy) into gradle binary plugins (java)
- Tried to make the bwc setup logic a bit more readable
- Add basic functional test coverage for the bwc logic this PR tweaked.
- Extracted a general internal BWC Git plugin out of the bwc setup plugin to improve maintenance 
and testability
- Changed the InternalDistributionPlugin to resolve the extracted distro instead on relying 
on unpacking the distribution archive

* Fix java8 incompatibility
* Fix extension calculation for 6.8.* distribution
  • Loading branch information
breskeby committed Oct 6, 2020
1 parent abf9b88 commit 8144106
Show file tree
Hide file tree
Showing 23 changed files with 1,118 additions and 379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ abstract class AbstractGradleFuncTest extends Specification {
}

GradleRunner gradleRunner(String... arguments) {
return gradleRunner(testProjectDir.root, arguments)
}

GradleRunner gradleRunner(File projectDir, String... arguments) {
GradleRunner.create()
.withDebug(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0)
.withProjectDir(testProjectDir.root)
.withProjectDir(projectDir)
.withArguments(arguments)
.withPluginClasspath()
.forwardOutput()
Expand Down Expand Up @@ -85,4 +89,31 @@ abstract class AbstractGradleFuncTest extends Specification {

return jarFile;
}

File internalBuild(File buildScript = buildFile) {
buildScript << """plugins {
id 'elasticsearch.global-build-info'
}
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.info.BuildParams
BuildParams.init { it.setIsInternal(true) }
import org.elasticsearch.gradle.BwcVersions
import org.elasticsearch.gradle.Version
Version currentVersion = Version.fromString("9.0.0")
BwcVersions versions = new BwcVersions(new TreeSet<>(
Arrays.asList(Version.fromString("8.0.0"), Version.fromString("8.0.1"), Version.fromString("8.1.0"), currentVersion)),
currentVersion)
BuildParams.init { it.setBwcVersions(versions) }
"""
}

void setupLocalGitRepo() {
"git init".execute(Collections.emptyList(), testProjectDir.root).waitFor()
"git add .".execute(Collections.emptyList(), testProjectDir.root).waitFor()
'git commit -m "Initial"'.execute(Collections.emptyList(), testProjectDir.root).waitFor()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.gradle.internal

import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome

class InternalBwcGitPluginFuncTest extends AbstractGradleFuncTest {

def setup() {
setupLocalGitRepo()
}

def "current repository can be cloned"() {
given:
internalBuild();
buildFile << """
import org.elasticsearch.gradle.Version;
apply plugin: org.elasticsearch.gradle.internal.InternalBwcGitPlugin
bwcGitConfig {
bwcVersion = project.provider { Version.fromString("7.10.0") }
bwcBranch = project.provider { "7.x" }
checkoutDir = project.provider{file("build/checkout")}
}
"""
when:
def result = gradleRunner("createClone", '--stacktrace').build()
then:
result.task(":createClone").outcome == TaskOutcome.SUCCESS
file("build/checkout/build.gradle").exists()
file("build/checkout/settings.gradle").exists()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.gradle.internal

import org.apache.commons.io.FileUtils
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder

class InternalDistributionBwcSetupPluginFuncTest extends AbstractGradleFuncTest {

@Rule
TemporaryFolder remoteRepoDirs = new TemporaryFolder()

File remoteGitRepo

def setup() {
remoteGitRepo = new File(setupGitRemote(), '.git')

"git clone ${remoteGitRepo.absolutePath}".execute(Collections.emptyList(), testProjectDir.root).waitFor()
File buildScript = new File(testProjectDir.root, 'remote/build.gradle')
internalBuild(buildScript)
buildScript << """
apply plugin: 'elasticsearch.internal-distribution-bwc-setup'
"""
}

def "builds distribution from branches via archives assemble"() {
when:
def result = gradleRunner(new File(testProjectDir.root, "remote"),
":distribution:bwc:bugfix:buildBwcDarwinTar",
":distribution:bwc:bugfix:buildBwcOssDarwinTar",
"-DtestRemoteRepo=" + remoteGitRepo,
"-Dbwc.remote=origin")
.build()
then:
result.task(":distribution:bwc:bugfix:buildBwcDarwinTar").outcome == TaskOutcome.SUCCESS
result.task(":distribution:bwc:bugfix:buildBwcOssDarwinTar").outcome == TaskOutcome.SUCCESS

and: "assemble task triggered"
result.output.contains("[8.0.1] > Task :distribution:archives:darwin-tar:assemble")
result.output.contains("[8.0.1] > Task :distribution:archives:oss-darwin-tar:assemble")
}

def "bwc distribution archives can be resolved as bwc project artifact"() {
setup:
new File(testProjectDir.root, 'remote/build.gradle') << """
configurations {
dists
}
dependencies {
dists project(path: ":distribution:bwc:bugfix", configuration:"darwin-tar")
}
tasks.register("resolveDistributionArchive") {
inputs.files(configurations.dists)
doLast {
configurations.dists.files.each {
println "distfile " + (it.absolutePath - project.rootDir.absolutePath)
}
}
}
"""
when:
def result = gradleRunner(new File(testProjectDir.root, "remote"),
":resolveDistributionArchive",
"-DtestRemoteRepo=" + remoteGitRepo,
"-Dbwc.remote=origin")
.build()
then:
result.task(":resolveDistributionArchive").outcome == TaskOutcome.SUCCESS
result.task(":distribution:bwc:bugfix:buildBwcDarwinTar").outcome == TaskOutcome.SUCCESS

and: "assemble task triggered"
result.output.contains("[8.0.1] > Task :distribution:archives:darwin-tar:assemble")
normalizedOutput(result.output)
.contains("distfile /distribution/bwc/bugfix/build/bwc/checkout-8.0/distribution/archives/darwin-tar/" +
"build/distributions/elasticsearch-8.0.1-SNAPSHOT-darwin-x86_64.tar.gz")
}

def "bwc expanded distribution folder can be resolved as bwc project artifact"() {
setup:
new File(testProjectDir.root, 'remote/build.gradle') << """
configurations {
expandedDist
}
dependencies {
expandedDist project(path: ":distribution:bwc:bugfix", configuration:"expanded-darwin-tar")
}
tasks.register("resolveExpandedDistribution") {
inputs.files(configurations.expandedDist)
doLast {
configurations.expandedDist.files.each {
println "distfile " + (it.absolutePath - project.rootDir.absolutePath)
}
}
}
"""
when:
def result = gradleRunner(new File(testProjectDir.root, "remote"),
":resolveExpandedDistribution",
"-DtestRemoteRepo=" + remoteGitRepo,
"-Dbwc.remote=origin")
.build()
then:
result.task(":resolveExpandedDistribution").outcome == TaskOutcome.SUCCESS
result.task(":distribution:bwc:bugfix:buildBwcDarwinTar").outcome == TaskOutcome.SUCCESS

and: "assemble task triggered"
result.output.contains("[8.0.1] > Task :distribution:archives:darwin-tar:assemble")
normalizedOutput(result.output)
.contains("distfile /distribution/bwc/bugfix/build/bwc/checkout-8.0/" +
"distribution/archives/darwin-tar/build/install")
}

File setupGitRemote() {
URL fakeRemote = getClass().getResource("fake_git/remote")
File workingRemoteGit = new File(remoteRepoDirs.root, 'remote')
FileUtils.copyDirectory(new File(fakeRemote.file), workingRemoteGit)
fakeRemote.file + "/.git"
gradleRunner(workingRemoteGit, "wrapper").build()
"git init".execute(Collections.emptyList(), workingRemoteGit).waitFor()
"git add .".execute(Collections.emptyList(), workingRemoteGit).waitFor()
'git commit -m"Initial"'.execute(Collections.emptyList(), workingRemoteGit).waitFor()
"git checkout -b origin/8.0".execute(Collections.emptyList(), workingRemoteGit).waitFor()
return workingRemoteGit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
def result = gradleRunner("setupDistro", '-g', testProjectDir.newFolder('GUH').path).build()

then:
result.task(":distribution:archives:linux-tar:buildExploded").outcome == TaskOutcome.SUCCESS
result.task(":distribution:archives:linux-tar:buildExpanded").outcome == TaskOutcome.SUCCESS
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated(distroVersion, "build/distro", 'current-marker.txt')
assertExtractedDistroIsCreated("build/distro", 'current-marker.txt')
}

def "resolves bwc versions from source"() {
def "resolves expanded bwc versions from source"() {
given:
internalBuild()
bwcMinorProjectSetup()
def distroVersion = "8.1.0"
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'
Expand All @@ -102,9 +101,10 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest

def result = gradleRunner("setupDistro").build()
then:
result.task(":distribution:bwc:minor:buildBwcTask").outcome == TaskOutcome.SUCCESS
result.task(":distribution:bwc:minor:buildBwcExpandedTask").outcome == TaskOutcome.SUCCESS
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated(distroVersion, "build/distro", 'bwc-marker.txt')
assertExtractedDistroIsCreated("distribution/bwc/minor/build/install/elastic-distro",
'bwc-marker.txt')
}

def "fails on resolving bwc versions with no bundled jdk"() {
Expand Down Expand Up @@ -134,28 +134,6 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
"without a bundled JDK is not supported.")
}

private File internalBuild() {
buildFile << """plugins {
id 'elasticsearch.global-build-info'
}
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.info.BuildParams
BuildParams.init { it.setIsInternal(true) }
import org.elasticsearch.gradle.BwcVersions
import org.elasticsearch.gradle.Version
Version currentVersion = Version.fromString("9.0.0")
BwcVersions versions = new BwcVersions(new TreeSet<>(
Arrays.asList(Version.fromString("8.0.0"), Version.fromString("8.0.1"), Version.fromString("8.1.0"), currentVersion)),
currentVersion)
BuildParams.init { it.setBwcVersions(versions) }
"""
}


private void bwcMinorProjectSetup() {
settingsFile << """
include ':distribution:bwc:minor'
Expand All @@ -164,6 +142,8 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=minor"
new File(bwcSubProjectFolder, 'build.gradle') << """
apply plugin:'base'
// packed distro
configurations.create("linux-tar")
tasks.register("buildBwcTask", Tar) {
from('bwc-marker.txt')
Expand All @@ -173,6 +153,19 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
artifacts {
it.add("linux-tar", buildBwcTask)
}
// expanded distro
configurations.create("expanded-linux-tar")
def expandedTask = tasks.register("buildBwcExpandedTask", Copy) {
from('bwc-marker.txt')
into('build/install/elastic-distro')
}
artifacts {
it.add("expanded-linux-tar", file('build/install')) {
builtBy expandedTask
type = 'directory'
}
}
"""
}

Expand All @@ -192,7 +185,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
archiveExtension = "tar.gz"
compression = Compression.GZIP
}
def buildExploded = tasks.register("buildExploded", Copy) {
def buildExpanded = tasks.register("buildExpanded", Copy) {
from('current-marker.txt')
into("build/local")
}
Expand All @@ -205,15 +198,14 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
}
artifacts {
it.add("default", buildTar)
it.add("extracted", buildExploded)
it.add("extracted", buildExpanded)
}
"""
buildFile << """
"""

}

boolean assertExtractedDistroIsCreated(String version, String relativeDistroPath, String markerFileName) {
boolean assertExtractedDistroIsCreated(String relativeDistroPath, String markerFileName) {
File extractedFolder = new File(testProjectDir.root, relativeDistroPath)
assert extractedFolder.exists()
assert new File(extractedFolder, markerFileName).exists()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
ES_BUILD_JAVA=openjdk14
ES_RUNTIME_JAVA=openjdk14
GRADLE_TASK=build

0 comments on commit 8144106

Please sign in to comment.