-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce packaging tests for Docker #46599
Changes from 13 commits
6a1877d
519342f
1980219
4862f7b
dcf27b3
3cb1bfe
4423f72
563882e
fa01608
3797a3e
62d78ac
2139539
3ccccfe
f527808
f2b83d3
3b6deb8
e7aca88
2b79a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,7 +319,7 @@ private List<ElasticsearchDistribution> configureDistributions(Project project, | |
List<ElasticsearchDistribution> currentDistros = new ArrayList<>(); | ||
List<ElasticsearchDistribution> upgradeDistros = new ArrayList<>(); | ||
|
||
for (Type type : Arrays.asList(Type.DEB, Type.RPM)) { | ||
for (Type type : Arrays.asList(Type.DEB, Type.RPM, Type.DOCKER)) { | ||
for (Flavor flavor : Flavor.values()) { | ||
for (boolean bundledJdk : Arrays.asList(true, false)) { | ||
addDistro(distributions, type, null, flavor, bundledJdk, VersionProperties.getElasticsearch(), currentDistros); | ||
|
@@ -370,7 +370,8 @@ private static void addDistro(NamedDomainObjectContainer<ElasticsearchDistributi | |
if (type == Type.ARCHIVE) { | ||
d.setPlatform(platform); | ||
} | ||
d.setBundledJdk(bundledJdk); | ||
// We don't test Docker images with a non-bundled JDK | ||
d.setBundledJdk(type == Type.DOCKER || bundledJdk); | ||
d.setVersion(version); | ||
}); | ||
container.add(distro); | ||
|
@@ -382,10 +383,17 @@ private static boolean isWindows(Project project) { | |
} | ||
|
||
private static String distroId(Type type, Platform platform, Flavor flavor, boolean bundledJdk) { | ||
return flavor + "-" + (type == Type.ARCHIVE ? platform + "-" : "") + type + (bundledJdk ? "" : "-no-jdk"); | ||
// We don't test Docker images with a non-bundled JDK | ||
return flavor + "-" + (type == Type.ARCHIVE ? platform + "-" : "") + type + (bundledJdk || type == Type.DOCKER ? "" : "-no-jdk"); | ||
} | ||
|
||
private static String destructiveDistroTestTaskName(ElasticsearchDistribution distro) { | ||
return "destructiveDistroTest." + distroId(distro.getType(), distro.getPlatform(), distro.getFlavor(), distro.getBundledJdk()); | ||
Type type = distro.getType(); | ||
return "destructiveDistroTest." + distroId( | ||
type, | ||
distro.getPlatform(), | ||
distro.getFlavor(), | ||
// We don't test Docker images with a non-bundled JDK | ||
type == Type.DOCKER || distro.getBundledJdk()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary, see my previous comment about where we add the distros. We should never add a docker distro with bundledJdk=false |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,8 +93,8 @@ void setupDistributions(Project project) { | |
// for the distribution as a file, just depend on the artifact directly | ||
dependencies.add(distribution.configuration.getName(), dependencyNotation(project, distribution)); | ||
|
||
// no extraction allowed for rpm or deb | ||
if (distribution.getType() != Type.RPM && distribution.getType() != Type.DEB) { | ||
// no extraction allowed for rpm, deb or docker | ||
if (distribution.getType().shouldExtract()) { | ||
// for the distribution extracted, add a root level task that does the extraction, and depend on that | ||
// extracted configuration as an artifact consisting of the extracted distribution directory | ||
dependencies.add(distribution.getExtracted().configuration.getName(), | ||
|
@@ -221,7 +221,6 @@ private Object dependencyNotation(Project project, ElasticsearchDistribution dis | |
} | ||
|
||
private static Dependency projectDependency(Project project, String projectPath, String projectConfig) { | ||
|
||
if (project.findProject(projectPath) == null) { | ||
throw new GradleException("no project [" + projectPath + "], project names: " + project.getRootProject().getAllprojects()); | ||
} | ||
|
@@ -233,11 +232,20 @@ private static Dependency projectDependency(Project project, String projectPath, | |
|
||
private static String distributionProjectPath(ElasticsearchDistribution distribution) { | ||
String projectPath = ":distribution"; | ||
if (distribution.getType() == Type.INTEG_TEST_ZIP) { | ||
projectPath += ":archives:integ-test-zip"; | ||
} else { | ||
projectPath += distribution.getType() == Type.ARCHIVE ? ":archives:" : ":packages:"; | ||
projectPath += distributionProjectName(distribution); | ||
switch (distribution.getType()) { | ||
case INTEG_TEST_ZIP: | ||
projectPath += ":archives:integ-test-zip"; | ||
break; | ||
|
||
case DOCKER: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pugnascotia the download distribution plugin is meant to be used outside of our build, Alternatively @rjernst, it might be more straight forward and easier to maintain to split the download plugin into two. One that deals exclusively with versions that are an actual download, and restrict that to some distribution types and one that deals with unreleased versions, with the lather being applied only as part of our build. I don't necessarily see this as reason not to merge this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I feel that we should merge this and come back to some of these issues. At least we'll have something build upon. |
||
projectPath += ":docker:"; | ||
projectPath += distributionProjectName(distribution); | ||
break; | ||
|
||
default: | ||
projectPath += distribution.getType() == Type.ARCHIVE ? ":archives:" : ":packages:"; | ||
projectPath += distributionProjectName(distribution); | ||
break; | ||
} | ||
return projectPath; | ||
} | ||
|
@@ -250,9 +258,12 @@ private static String distributionProjectName(ElasticsearchDistribution distribu | |
if (distribution.getBundledJdk() == false) { | ||
projectName += "no-jdk-"; | ||
} | ||
|
||
if (distribution.getType() == Type.ARCHIVE) { | ||
Platform platform = distribution.getPlatform(); | ||
projectName += platform.toString() + (platform == Platform.WINDOWS ? "-zip" : "-tar"); | ||
} else if (distribution.getType() == Type.DOCKER) { | ||
projectName += "docker-export"; | ||
} else { | ||
projectName += distribution.getType(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,3 +186,37 @@ assemble.dependsOn "buildDockerImage" | |
if (tasks.findByName("composePull")) { | ||
tasks.composePull.enabled = false | ||
} | ||
|
||
/* | ||
* The export subprojects write out the generated Docker images to disk, so | ||
* that they can be easily reloaded, for example into a VM. | ||
*/ | ||
subprojects { Project subProject -> | ||
if (subProject.name.contains('docker-export')) { | ||
apply plugin: 'distribution' | ||
|
||
def oss = subProject.name.startsWith('oss') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use static types. It makes the code easier to reason about, eg String here. |
||
|
||
def exportTaskName = taskName("export", oss, "DockerImage") | ||
def buildTaskName = taskName("build", oss, "DockerImage") | ||
def tarFile = "${parent.projectDir}/build/elasticsearch${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}.docker.tar" | ||
|
||
final Task exportDockerImageTask = task(exportTaskName, type: LoggedExec) { | ||
executable 'docker' | ||
args "save", | ||
"-o", | ||
tarFile, | ||
"elasticsearch${oss ? '-oss' : ''}:test" | ||
} | ||
|
||
exportDockerImageTask.dependsOn(parent.tasks.getByName(buildTaskName)) | ||
|
||
artifacts.add('default', file(tarFile)) { | ||
type 'tar' | ||
name "elasticsearch${oss ? '-oss' : ''}" | ||
builtBy exportTaskName | ||
} | ||
|
||
assemble.dependsOn exportTaskName | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file is intentionally blank. All configuration of the | ||
// export is done in the parent project. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a project for the extraction ? Could it just be a task on parent ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to do with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the same pattern is used in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, it's a bit strange that this we have projects for export only here, but I'll defer to @rjernst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file is intentionally blank. All configuration of the | ||
// export is done in the parent project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled outside of addDistro, otherwise we are adding the same distribution twice? ie around line 325 where this method is called