Skip to content

Commit 0fef750

Browse files
authored
Enable Dockerfile from artifacts.elastic.co 6.7 (#38587)
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 293ed6d commit 0fef750

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

distribution/docker/build.gradle

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

2020
ext.expansions = { oss ->
21+
final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}.tar.gz"
2122
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
2729
]
2830
}
2931

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+
3049
private static String files(final boolean oss) {
3150
return "build/${ oss ? 'oss-' : ''}docker"
3251
}
@@ -47,20 +66,22 @@ void addCopyDockerContextTask(final boolean oss) {
4766
from 'src/docker/config'
4867
}
4968

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+
}
5575

56-
from configurations.dockerPlugins
76+
from configurations.dockerPlugins
77+
}
5778
}
5879
}
5980

6081
void addCopyDockerfileTask(final boolean oss) {
6182
task(taskName("copy", oss, "Dockerfile"), type: Copy) {
83+
dependsOn taskName("copy", oss, "DockerContext")
6284
inputs.properties(expansions(oss)) // ensure task is run when ext.expansions is changed
63-
mustRunAfter(taskName("copy", oss, "DockerContext"))
6485
into files(oss)
6586

6687
from('src/docker/Dockerfile') {
@@ -69,7 +90,6 @@ void addCopyDockerfileTask(final boolean oss) {
6990
}
7091
}
7192

72-
7393
preProcessFixture {
7494
dependsOn taskName("copy", true, "DockerContext")
7595
dependsOn taskName("copy", true, "Dockerfile")
@@ -87,7 +107,6 @@ check.dependsOn postProcessFixture
87107

88108
void addBuildDockerImage(final boolean oss) {
89109
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
90-
dependsOn taskName("copy", oss, "DockerContext")
91110
dependsOn taskName("copy", oss, "Dockerfile")
92111
List<String> tags
93112
if (oss) {

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)