Skip to content

Commit 7f649d0

Browse files
authored
Enable Dockerfile from artifacts.elastic.co (#38552)
This commit enables the copyDockerfile task to render a Dockerfile that sources the Elasticsearch binary from artifacts.elastic.co. This is needed for reproducibility and transparency for the official Docker images in the Docker library.
1 parent ce5811e commit 7f649d0

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

distribution/docker/build.gradle

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,35 @@ dependencies {
1818
}
1919

2020
ext.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+
3150
private 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

6182
void 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-
7494
preProcessFixture {
7595
dependsOn taskName("copy", true, "DockerContext")
7696
dependsOn taskName("copy", true, "Dockerfile")

distribution/docker/src/docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ RUN groupadd -g 1000 elasticsearch && \
3030

3131
WORKDIR /usr/share/elasticsearch
3232

33-
COPY ${elasticsearch} /opt/
33+
${source_elasticsearch}
34+
3435
RUN tar zxf /opt/${elasticsearch} --strip-components=1
3536
RUN mkdir -p config data logs
3637
RUN chmod 0775 config data logs
3738
COPY config/elasticsearch.yml config/log4j2.properties config/
3839

39-
4040
################################################################################
4141
# Build stage 1 (the actual elasticsearch image):
4242
# Copy elasticsearch from stage 0

0 commit comments

Comments
 (0)