@@ -19,17 +19,38 @@ dependencies {
1919}
2020
2121ext. expansions = { oss ->
22+ final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} .tar.gz"
23+ final String ingestGeoip = " ingest-geoip-${ VersionProperties.elasticsearch} .zip"
24+ final String ingestUserAgent = " ingest-user-agent-${ VersionProperties.elasticsearch} .zip"
2225 return [
23- ' elasticsearch' : oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} .tar.gz" ,
24- ' jdkUrl' : ' https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz' ,
25- ' jdkVersion' : ' 11.0.1' ,
26- ' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
27- ' ingest-geoip' : " ingest-geoip-${ VersionProperties.elasticsearch} .zip" ,
28- ' ingest-user-agent' : " ingest-user-agent-${ VersionProperties.elasticsearch} .zip" ,
29- ' version' : VersionProperties . elasticsearch
26+ ' elasticsearch' : elasticsearch,
27+ ' jdkUrl' : ' https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz' ,
28+ ' jdkVersion' : ' 11.0.1' ,
29+ ' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
30+ ' source_elasticsearch' : local() ? " COPY $elasticsearch $ingestGeoip $ingestUserAgent /opt/" : " RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} && cd -" ,
31+ ' ingest-geoip-plugin' : local() ? " file:///opt/$ingestGeoip " : " ingest-geoip" ,
32+ ' ingest-user-agent-plugin' : local() ? " file:///opt/$ingestUserAgent " : " ingest-user-agent" ,
33+ ' version' : VersionProperties . elasticsearch
3034 ]
3135}
3236
37+ /*
38+ * We need to be able to render a Dockerfile that references the official artifacts on https://artifacts.elastic.co. For this, we use a
39+ * substitution in the Dockerfile template where we can either replace source_elasticsearch with a COPY from the Docker build context, or
40+ * a RUN curl command to retrieve the artifact from https://artifacts.elastic.co. The system property build.docker.source, which can be
41+ * either "local" (default) or "remote" controls which version of the Dockerfile is produced.
42+ */
43+ private static boolean local () {
44+ final String buildDockerSource = System . getProperty(" build.docker.source" )
45+ if (buildDockerSource == null || " local" . equals(buildDockerSource)) {
46+ return true
47+ } else if (" remote" . equals(buildDockerSource)) {
48+ return false
49+ } else {
50+ throw new IllegalArgumentException (" expected build.docker.source to be [local] or [remote] but was [" + buildDockerSource + " ]" )
51+ }
52+ }
53+
3354private static String files (final boolean oss ) {
3455 return " build/${ oss ? 'oss-' : ''} docker"
3556}
@@ -50,19 +71,21 @@ void addCopyDockerContextTask(final boolean oss) {
5071 from ' src/docker/config'
5172 }
5273
53- if (oss) {
54- from configurations. ossDockerSource
55- } else {
56- from configurations. dockerSource
57- }
74+ if (local()) {
75+ if (oss) {
76+ from configurations. ossDockerSource
77+ } else {
78+ from configurations. dockerSource
79+ }
5880
59- from configurations. dockerPlugins
81+ from configurations. dockerPlugins
82+ }
6083 }
6184}
6285
6386void addCopyDockerfileTask (final boolean oss ) {
6487 task(taskName(" copy" , oss, " Dockerfile" ), type : Copy ) {
65- mustRunAfter( taskName(" copy" , oss, " DockerContext" ) )
88+ dependsOn taskName(" copy" , oss, " DockerContext" )
6689 into files(oss)
6790
6891 from(' src/docker/Dockerfile' ) {
@@ -73,7 +96,6 @@ void addCopyDockerfileTask(final boolean oss) {
7396
7497void addBuildDockerImage (final boolean oss ) {
7598 final Task buildDockerImageTask = task(taskName(" build" , oss, " DockerImage" ), type : LoggedExec ) {
76- dependsOn taskName(" copy" , oss, " DockerContext" )
7799 dependsOn taskName(" copy" , oss, " Dockerfile" )
78100 List<String > tags
79101 if (oss) {
0 commit comments