From 2171b241f1e92c8d5cdfadf899bbc5a5f0e99dd0 Mon Sep 17 00:00:00 2001 From: Rory Hunter Date: Thu, 30 Jul 2020 16:19:34 +0100 Subject: [PATCH] Hack around gradle issues with configurations and project context --- distribution/docker/build.gradle | 22 ++++++++++++++----- .../docker/docker-build-context/build.gradle | 2 +- .../oss-docker-build-context/build.gradle | 2 +- .../ubi-docker-build-context/build.gradle | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/distribution/docker/build.gradle b/distribution/docker/build.gradle index be53ae88a5a91..f9f9ac5556d8a 100644 --- a/distribution/docker/build.gradle +++ b/distribution/docker/build.gradle @@ -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) { @@ -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) : '' ] } @@ -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 varExpansions = expansions(architecture, oss, ubi, local) + final Map varExpansions = expansions(architecture, oss, ubi, local, p) final Path projectDir = project.projectDir.toPath() if (ubi) { @@ -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) { @@ -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' diff --git a/distribution/docker/docker-build-context/build.gradle b/distribution/docker/docker-build-context/build.gradle index 15604ce94c04f..0bf27b43190c2 100644 --- a/distribution/docker/docker-build-context/build.gradle +++ b/distribution/docker/docker-build-context/build.gradle @@ -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 diff --git a/distribution/docker/oss-docker-build-context/build.gradle b/distribution/docker/oss-docker-build-context/build.gradle index 172bfe0c7e781..a77f4a78d875b 100644 --- a/distribution/docker/oss-docker-build-context/build.gradle +++ b/distribution/docker/oss-docker-build-context/build.gradle @@ -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 diff --git a/distribution/docker/ubi-docker-build-context/build.gradle b/distribution/docker/ubi-docker-build-context/build.gradle index 72b0845531e08..f59286dda0f62 100644 --- a/distribution/docker/ubi-docker-build-context/build.gradle +++ b/distribution/docker/ubi-docker-build-context/build.gradle @@ -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