@@ -18,16 +18,35 @@ dependencies {
1818}
1919
2020ext. expansions = { oss ->
21- String classifier = ' linux-x86_64'
21+ final String classifier = ' linux-x86_64'
22+ final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz"
2223 return [
23- ' elasticsearch' : oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz" ,
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- ' version' : VersionProperties . elasticsearch
24+ ' elasticsearch' : elasticsearch,
25+ ' jdkUrl' : ' https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz' ,
26+ ' jdkVersion' : ' 11.0.2' ,
27+ ' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
28+ ' source_elasticsearch' : local() ? " COPY $elasticsearch /opt/" : " RUN curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} " ,
29+ ' version' : VersionProperties . elasticsearch
2830 ]
2931}
3032
33+ /*
34+ * We need to be able to render a Dockerfile that references the official artifacts on https://artifacts.elastic.co. For this, we use a
35+ * substitution in the Dockerfile template where we can either replace source_elasticsearch with a COPY from the Docker build context, or
36+ * a RUN curl command to retrieve the artifact from https://artifacts.elastic.co. The system property build.docker.source, which can be
37+ * either "local" (default) or "remote" controls which version of the Dockerfile is produced.
38+ */
39+ private static boolean local () {
40+ final String buildDockerSource = System . getProperty(" build.docker.source" )
41+ if (buildDockerSource == null || " local" . equals(buildDockerSource)) {
42+ return true
43+ } else if (" remote" . equals(buildDockerSource)) {
44+ return false
45+ } else {
46+ throw new IllegalArgumentException (" expected build.docker.source to be [local] or [remote] but was [" + buildDockerSource + " ]" )
47+ }
48+ }
49+
3150private static String files (final boolean oss ) {
3251 return " build/${ oss ? 'oss-' : ''} docker"
3352}
@@ -48,20 +67,22 @@ void addCopyDockerContextTask(final boolean oss) {
4867 from ' src/docker/config'
4968 }
5069
51- if (oss) {
52- from configurations. ossDockerSource
53- } else {
54- from configurations. dockerSource
55- }
70+ if (local()) {
71+ if (oss) {
72+ from configurations. ossDockerSource
73+ } else {
74+ from configurations. dockerSource
75+ }
5676
57- from configurations. dockerPlugins
77+ from configurations. dockerPlugins
78+ }
5879 }
5980}
6081
6182void addCopyDockerfileTask (final boolean oss ) {
6283 task(taskName(" copy" , oss, " Dockerfile" ), type : Copy ) {
84+ dependsOn taskName(" copy" , oss, " DockerContext" )
6385 inputs. properties(expansions(oss)) // ensure task is run when ext.expansions is changed
64- mustRunAfter(taskName(" copy" , oss, " DockerContext" ))
6586 into files(oss)
6687
6788 from(' src/docker/Dockerfile' ) {
@@ -70,7 +91,6 @@ void addCopyDockerfileTask(final boolean oss) {
7091 }
7192}
7293
73-
7494preProcessFixture {
7595 dependsOn taskName(" copy" , true , " DockerContext" )
7696 dependsOn taskName(" copy" , true , " Dockerfile" )
0 commit comments