@@ -18,15 +18,34 @@ dependencies {
18
18
}
19
19
20
20
ext. expansions = { oss ->
21
+ final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} .tar.gz"
21
22
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
27
29
]
28
30
}
29
31
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
+
30
49
private static String files (final boolean oss ) {
31
50
return " build/${ oss ? 'oss-' : ''} docker"
32
51
}
@@ -47,20 +66,22 @@ void addCopyDockerContextTask(final boolean oss) {
47
66
from ' src/docker/config'
48
67
}
49
68
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
+ }
55
75
56
- from configurations. dockerPlugins
76
+ from configurations. dockerPlugins
77
+ }
57
78
}
58
79
}
59
80
60
81
void addCopyDockerfileTask (final boolean oss ) {
61
82
task(taskName(" copy" , oss, " Dockerfile" ), type : Copy ) {
83
+ dependsOn taskName(" copy" , oss, " DockerContext" )
62
84
inputs. properties(expansions(oss)) // ensure task is run when ext.expansions is changed
63
- mustRunAfter(taskName(" copy" , oss, " DockerContext" ))
64
85
into files(oss)
65
86
66
87
from(' src/docker/Dockerfile' ) {
@@ -69,7 +90,6 @@ void addCopyDockerfileTask(final boolean oss) {
69
90
}
70
91
}
71
92
72
-
73
93
preProcessFixture {
74
94
dependsOn taskName(" copy" , true , " DockerContext" )
75
95
dependsOn taskName(" copy" , true , " Dockerfile" )
@@ -87,7 +107,6 @@ check.dependsOn postProcessFixture
87
107
88
108
void addBuildDockerImage (final boolean oss ) {
89
109
final Task buildDockerImageTask = task(taskName(" build" , oss, " DockerImage" ), type : LoggedExec ) {
90
- dependsOn taskName(" copy" , oss, " DockerContext" )
91
110
dependsOn taskName(" copy" , oss, " Dockerfile" )
92
111
List<String > tags
93
112
if (oss) {
0 commit comments