@@ -17,34 +17,17 @@ dependencies {
17
17
ossDockerSource project(path : " :distribution:archives:oss-linux-tar" )
18
18
}
19
19
20
- ext. expansions = { oss ->
20
+ ext. expansions = { oss , local ->
21
21
final String classifier = ' linux-x86_64'
22
22
final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz"
23
23
return [
24
24
' elasticsearch' : elasticsearch,
25
25
' license' : oss ? ' Apache-2.0' : ' Elastic License' ,
26
- ' source_elasticsearch' : local() ? " COPY $elasticsearch /opt/" : " RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} && cd -" ,
26
+ ' source_elasticsearch' : local ? " COPY $elasticsearch /opt/" : " RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} && cd -" ,
27
27
' version' : VersionProperties . elasticsearch
28
28
]
29
29
}
30
30
31
- /*
32
- * We need to be able to render a Dockerfile that references the official artifacts on https://artifacts.elastic.co. For this, we use a
33
- * substitution in the Dockerfile template where we can either replace source_elasticsearch with a COPY from the Docker build context, or
34
- * a RUN curl command to retrieve the artifact from https://artifacts.elastic.co. The system property build.docker.source, which can be
35
- * either "local" (default) or "remote" controls which version of the Dockerfile is produced.
36
- */
37
- private static boolean local () {
38
- final String buildDockerSource = System . getProperty(" build.docker.source" )
39
- if (buildDockerSource == null || " local" . equals(buildDockerSource)) {
40
- return true
41
- } else if (" remote" . equals(buildDockerSource)) {
42
- return false
43
- } else {
44
- throw new IllegalArgumentException (" expected build.docker.source to be [local] or [remote] but was [" + buildDockerSource + " ]" )
45
- }
46
- }
47
-
48
31
private static String files (final boolean oss ) {
49
32
return " build/${ oss ? 'oss-' : ''} docker"
50
33
}
@@ -53,39 +36,38 @@ private static String taskName(final String prefix, final boolean oss, final Str
53
36
return " ${ prefix}${ oss ? 'Oss' : ''}${ suffix} "
54
37
}
55
38
56
- void addCopyDockerContextTask (final boolean oss ) {
57
- task(taskName(" copy" , oss, " DockerContext" ), type : Sync ) {
58
- into files(oss)
59
-
60
- into(' bin' ) {
61
- from ' src/docker/bin'
62
- }
63
-
64
- into(' config' ) {
65
- from ' src/docker/config'
66
- }
39
+ project. ext {
40
+ dockerBuildContext = { boolean oss , boolean local ->
41
+ copySpec {
42
+ into(' bin' ) {
43
+ from project. projectDir. toPath(). resolve(" src/docker/bin" )
44
+ }
67
45
68
- if (local()) {
69
- if (oss) {
70
- from configurations. ossDockerSource
71
- } else {
72
- from configurations. dockerSource
46
+ into(' config' ) {
47
+ from project. projectDir. toPath(). resolve(" src/docker/config" )
73
48
}
74
49
75
- from configurations. dockerPlugins
50
+ from(project. projectDir. toPath(). resolve(" src/docker/Dockerfile" )) {
51
+ MavenFilteringHack . filter(it, expansions(oss, local))
52
+ }
76
53
}
77
54
}
78
55
}
79
56
80
- void addCopyDockerfileTask (final boolean oss ) {
81
- task(taskName(" copy" , oss, " Dockerfile" ), type : Copy ) {
82
- dependsOn taskName(" copy" , oss, " DockerContext" )
83
- inputs. properties(expansions(oss)) // ensure task is run when ext.expansions is changed
57
+ void addCopyDockerContextTask (final boolean oss ) {
58
+ task(taskName(" copy" , oss, " DockerContext" ), type : Sync ) {
59
+ inputs. properties(expansions(oss, true ))
84
60
into files(oss)
85
61
86
- from(' src/docker/Dockerfile' ) {
87
- MavenFilteringHack . filter(it, expansions(oss))
62
+ with dockerBuildContext(oss, true )
63
+
64
+ if (oss) {
65
+ from configurations. ossDockerSource
66
+ } else {
67
+ from configurations. dockerSource
88
68
}
69
+
70
+ from configurations. dockerPlugins
89
71
}
90
72
}
91
73
@@ -104,7 +86,6 @@ check.dependsOn postProcessFixture
104
86
void addBuildDockerImage (final boolean oss ) {
105
87
final Task buildDockerImageTask = task(taskName(" build" , oss, " DockerImage" ), type : LoggedExec ) {
106
88
dependsOn taskName(" copy" , oss, " DockerContext" )
107
- dependsOn taskName(" copy" , oss, " Dockerfile" )
108
89
List<String > tags
109
90
if (oss) {
110
91
tags = [
@@ -132,7 +113,6 @@ void addBuildDockerImage(final boolean oss) {
132
113
133
114
for (final boolean oss : [false , true ]) {
134
115
addCopyDockerContextTask(oss)
135
- addCopyDockerfileTask(oss)
136
116
addBuildDockerImage(oss)
137
117
}
138
118
0 commit comments