Skip to content

Commit

Permalink
Hack around gradle issues with configurations and project context
Browse files Browse the repository at this point in the history
  • Loading branch information
pugnascotia committed Jul 30, 2020
1 parent ad9140f commit 2171b24
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
22 changes: 16 additions & 6 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
}

ext.expansions = { Architecture architecture, boolean oss, boolean ubi, boolean local ->
ext.expansions = { Architecture architecture, boolean oss, boolean ubi, boolean local, Project p ->
String classifier
if (local || ubi) {
switch (architecture) {
Expand Down Expand Up @@ -82,7 +82,7 @@ RUN curl --retry 8 -S -L \\
'license' : oss ? 'Apache-2.0' : 'Elastic-License',
'source_elasticsearch': sourceElasticsearch,
'version' : VersionProperties.elasticsearch,
'version_hash' : ubi ? getChecksum(configurations.dockerSource.singleFile) : ''
'version_hash' : ubi ? getChecksum(p.configurations.dockerSource.singleFile) : ''
]
}

Expand Down Expand Up @@ -122,9 +122,9 @@ private static String taskName(final String prefix, final Architecture architect
}

project.ext {
dockerBuildContext = { Architecture architecture, boolean oss, boolean ubi, boolean local ->
dockerBuildContext = { Architecture architecture, boolean oss, boolean ubi, boolean local, Project p ->
copySpec {
final Map<String,String> varExpansions = expansions(architecture, oss, ubi, local)
final Map<String,String> varExpansions = expansions(architecture, oss, ubi, local, p)
final Path projectDir = project.projectDir.toPath()

if (ubi) {
Expand Down Expand Up @@ -164,12 +164,12 @@ project.ext {

void addCopyDockerContextTask(final Architecture architecture, final boolean oss) {
task(taskName("copy", architecture, oss, "DockerContext"), type: Sync) {
expansions(architecture, oss, false, true).findAll { it.key != 'build_date' }.each { k, v ->
expansions(architecture, oss, false, true, project).findAll { it.key != 'build_date' }.each { k, v ->
inputs.property(k, { v.toString() })
}
into buildPath(architecture, oss)

with dockerBuildContext(architecture, oss, false, true)
with dockerBuildContext(architecture, oss, false, true, project)

if (architecture == Architecture.AARCH64) {
if (oss) {
Expand Down Expand Up @@ -300,6 +300,16 @@ if (tasks.findByName("composePull")) {
* that they can be easily reloaded, for example into a VM for distribution testing
*/
subprojects { Project subProject ->
if (subProject.name.endsWith('-context')) {
configurations {
dockerSource
}

dependencies {
dockerSource project(path: ":distribution:archives:linux-tar")
}
}

if (subProject.name.endsWith('-export')) {
apply plugin: 'distribution'

Expand Down
2 changes: 1 addition & 1 deletion distribution/docker/docker-build-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ task buildDockerBuildContext(type: Tar) {
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch"
// Non-local builds don't need to specify an architecture.
with dockerBuildContext(null, false, false, false)
with dockerBuildContext(null, false, false, false, project)
}

assemble.dependsOn buildDockerBuildContext
2 changes: 1 addition & 1 deletion distribution/docker/oss-docker-build-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ task buildOssDockerBuildContext(type: Tar) {
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-oss"
// Non-local builds don't need to specify an architecture.
with dockerBuildContext(null, true, false, false)
with dockerBuildContext(null, true, false, false, project)
}

assemble.dependsOn buildOssDockerBuildContext
2 changes: 1 addition & 1 deletion distribution/docker/ubi-docker-build-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ task buildUbiDockerBuildContext(type: Tar) {
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-ubi8"
with dockerBuildContext(Architecture.X64, false, true, false)
with dockerBuildContext(Architecture.X64, false, true, false, project)
}

assemble.dependsOn buildUbiDockerBuildContext

0 comments on commit 2171b24

Please sign in to comment.