Skip to content

Commit dc30a25

Browse files
authored
Enable Dockerfile from artifacts.elastic.co (#38585)
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 0b0af8c commit dc30a25

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

distribution/docker/build.gradle

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,38 @@ dependencies {
1919
}
2020

2121
ext.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+
3354
private 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

6386
void 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

7497
void 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) {

distribution/docker/src/docker/Dockerfile

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

3131
WORKDIR /usr/share/elasticsearch
3232

33-
COPY ${elasticsearch} ${ingest-geoip} ${ingest-user-agent} /opt/
33+
${source_elasticsearch}
34+
3435
RUN tar zxf /opt/${elasticsearch} --strip-components=1
35-
RUN elasticsearch-plugin install --batch file:///opt/${ingest-geoip}
36-
RUN elasticsearch-plugin install --batch file:///opt/${ingest-user-agent}
36+
RUN elasticsearch-plugin install --batch ${ingest-geoip-plugin}
37+
RUN elasticsearch-plugin install --batch ${ingest-user-agent-plugin}
3738
RUN mkdir -p config data logs
3839
RUN chmod 0775 config data logs
3940
COPY config/elasticsearch.yml config/log4j2.properties config/
4041

41-
4242
################################################################################
4343
# Build stage 1 (the actual elasticsearch image):
4444
# Copy elasticsearch from stage 0

0 commit comments

Comments
 (0)