@@ -18,15 +18,34 @@ dependencies {
1818}
1919
2020ext. expansions = { oss ->
21+ final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} .tar.gz"
2122 return [
22- ' elasticsearch' : oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} .tar.gz" ,
23- ' jdkUrl' : ' https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz' ,
24- ' jdkVersion' : ' 11.0.2' ,
25- ' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
26- ' version' : VersionProperties . elasticsearch
23+ ' elasticsearch' : elasticsearch,
24+ ' jdkUrl' : ' https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz' ,
25+ ' jdkVersion' : ' 11.0.2' ,
26+ ' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
27+ ' source_elasticsearch' : local() ? " COPY $elasticsearch /opt/" : " RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} && cd -" ,
28+ ' version' : VersionProperties . elasticsearch
2729 ]
2830}
2931
32+ /*
33+ * We need to be able to render a Dockerfile that references the official artifacts on https://artifacts.elastic.co. For this, we use a
34+ * substitution in the Dockerfile template where we can either replace source_elasticsearch with a COPY from the Docker build context, or
35+ * a RUN curl command to retrieve the artifact from https://artifacts.elastic.co. The system property build.docker.source, which can be
36+ * either "local" (default) or "remote" controls which version of the Dockerfile is produced.
37+ */
38+ private static boolean local () {
39+ final String buildDockerSource = System . getProperty(" build.docker.source" )
40+ if (buildDockerSource == null || " local" . equals(buildDockerSource)) {
41+ return true
42+ } else if (" remote" . equals(buildDockerSource)) {
43+ return false
44+ } else {
45+ throw new IllegalArgumentException (" expected build.docker.source to be [local] or [remote] but was [" + buildDockerSource + " ]" )
46+ }
47+ }
48+
3049private static String files (final boolean oss ) {
3150 return " build/${ oss ? 'oss-' : ''} docker"
3251}
@@ -47,20 +66,22 @@ void addCopyDockerContextTask(final boolean oss) {
4766 from ' src/docker/config'
4867 }
4968
50- if (oss) {
51- from configurations. ossDockerSource
52- } else {
53- from configurations. dockerSource
54- }
69+ if (local()) {
70+ if (oss) {
71+ from configurations. ossDockerSource
72+ } else {
73+ from configurations. dockerSource
74+ }
5575
56- from configurations. dockerPlugins
76+ from configurations. dockerPlugins
77+ }
5778 }
5879}
5980
6081void addCopyDockerfileTask (final boolean oss ) {
6182 task(taskName(" copy" , oss, " Dockerfile" ), type : Copy ) {
83+ dependsOn taskName(" copy" , oss, " DockerContext" )
6284 inputs. properties(expansions(oss)) // ensure task is run when ext.expansions is changed
63- mustRunAfter(taskName(" copy" , oss, " DockerContext" ))
6485 into files(oss)
6586
6687 from(' src/docker/Dockerfile' ) {
@@ -69,7 +90,6 @@ void addCopyDockerfileTask(final boolean oss) {
6990 }
7091}
7192
72-
7393preProcessFixture {
7494 dependsOn taskName(" copy" , true , " DockerContext" )
7595 dependsOn taskName(" copy" , true , " Dockerfile" )
@@ -87,7 +107,6 @@ check.dependsOn postProcessFixture
87107
88108void addBuildDockerImage (final boolean oss ) {
89109 final Task buildDockerImageTask = task(taskName(" build" , oss, " DockerImage" ), type : LoggedExec ) {
90- dependsOn taskName(" copy" , oss, " DockerContext" )
91110 dependsOn taskName(" copy" , oss, " Dockerfile" )
92111 List<String > tags
93112 if (oss) {
0 commit comments