Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@ dependencies {
restSpec project(':rest-api-spec')
}

ext.expansions = { oss, local ->
ext.expansions = { oss, ubi, local ->
final String classifier = 'linux-x86_64'
final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}-${classifier}.tar.gz"
return [
'base_image' : ubi ? 'registry.access.redhat.com/ubi7/ubi-minimal:7.7' : 'centos:7',
'build_date' : project.ext.buildDate,
'elasticsearch' : elasticsearch,
'git_revision' : project.ext.gitRevision,
'license' : oss ? 'Apache-2.0' : 'Elastic-License',
'package_manager' : ubi ? 'microdnf' : 'yum',
'source_elasticsearch': local ? "COPY $elasticsearch /opt/" : "RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${elasticsearch} && cd -",
'version' : VersionProperties.elasticsearch
]
}

private static String files(final boolean oss) {
return "build/${ oss ? 'oss-' : ''}docker"
private static String buildPath(final boolean oss, final boolean ubi) {
return "build/${ oss ? 'oss-' : ''}${ ubi ? 'ubi-' : ''}docker"
}

private static String taskName(final String prefix, final boolean oss, final String suffix) {
return "${prefix}${oss ? 'Oss' : ''}${suffix}"
private static String taskName(final String prefix, final boolean oss, final boolean ubi, final String suffix) {
return "${prefix}${oss ? 'Oss' : ''}${ubi ? 'Ubi': ''}${suffix}"
}

project.ext {
dockerBuildContext = { boolean oss, boolean local ->
dockerBuildContext = { boolean oss, boolean ubi, boolean local ->
copySpec {
into('bin') {
from project.projectDir.toPath().resolve("src/docker/bin")
Expand All @@ -55,24 +57,26 @@ project.ext {
* by creating config files in oss or default build-context sub-modules.
*/
from project.projectDir.toPath().resolve("src/docker/config")
from project.projectDir.toPath().resolve(oss ? "oss-docker-build-context" : "docker-build-context").resolve("src/docker/config")
if (oss) {
from project.projectDir.toPath().resolve("src/docker/config/oss")
}
}

from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
expand(expansions(oss, local))
expand(expansions(oss, ubi, local))
}
}
}
}

void addCopyDockerContextTask(final boolean oss) {
task(taskName("copy", oss, "DockerContext"), type: Sync) {
expansions(oss, true).each { k, v ->
void addCopyDockerContextTask(final boolean oss, final boolean ubi) {
task(taskName("copy", oss, ubi, "DockerContext"), type: Sync) {
expansions(oss, ubi, true).each { k, v ->
inputs.property(k, { v.toString() })
}
into files(oss)
into buildPath(oss, ubi)

with dockerBuildContext(oss, true)
with dockerBuildContext(oss, ubi, true)

if (oss) {
from configurations.ossDockerSource
Expand Down Expand Up @@ -144,42 +148,42 @@ task integTest(type: Test) {

check.dependsOn integTest

void addBuildDockerImage(final boolean oss) {
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
dependsOn taskName("copy", oss, "DockerContext")
void addBuildDockerImage(final boolean oss, final boolean ubi) {
final Task buildDockerImageTask = task(taskName("build", oss, ubi, "DockerImage"), type: LoggedExec) {
dependsOn taskName("copy", oss, ubi, "DockerContext")
List<String> tags
if (oss) {
tags = [
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}",
"elasticsearch-oss:test"
"docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}${ubi ? '-ubi7' : ''}",
"elasticsearch-oss:test${ubi ? '-ubi7' : ''}"
]
} else {
tags = [
"elasticsearch:${VersionProperties.elasticsearch}",
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}",
"elasticsearch:test",
"elasticsearch:${VersionProperties.elasticsearch}${ubi ? '-ubi7' : ''}",
"docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}${ubi ? '-ubi7' : ''}",
"docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}${ubi ? '-ubi7' : ''}",
"elasticsearch:test${ubi ? '-ubi7' : ''}",
]
}
executable 'docker'
final List<String> dockerArgs = ['build', files(oss), '--pull', '--no-cache']
final List<String> dockerArgs = ['build', buildPath(oss, ubi), '--pull', '--no-cache']
for (final String tag : tags) {
dockerArgs.add('--tag')
dockerArgs.add(tag)
}
args dockerArgs.toArray()
}
assemble.dependsOn(buildDockerImageTask)
BuildPlugin.requireDocker(buildDockerImageTask)
}

for (final boolean oss : [false, true]) {
addCopyDockerContextTask(oss)
addBuildDockerImage(oss)
for (final boolean ubi : [false, true]) {
addCopyDockerContextTask(oss, ubi)
addBuildDockerImage(oss, ubi)
}
}

assemble.dependsOn "buildOssDockerImage"
assemble.dependsOn "buildDockerImage"

// We build the images used in compose locally, but the pull command insists on using a repository
// thus we must disable it to prevent it from doing so.
// Everything will still be pulled since we will build the local images on a pull
Expand All @@ -195,25 +199,26 @@ subprojects { Project subProject ->
if (subProject.name.contains('docker-export')) {
apply plugin: 'distribution'

final boolean oss = subProject.name.startsWith('oss')
final boolean oss = subProject.name.contains('oss-')
final boolean ubi = subProject.name.contains('ubi-')

def exportTaskName = taskName("export", oss, "DockerImage")
def buildTaskName = taskName("build", oss, "DockerImage")
def tarFile = "${parent.projectDir}/build/elasticsearch${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}.docker.tar"
def exportTaskName = taskName("export", oss, ubi, "DockerImage")
def buildTaskName = taskName("build", oss, ubi, "DockerImage")
def tarFile = "${parent.projectDir}/build/elasticsearch${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}${ubi ? '-ubi7' : ''}.docker.tar"

final Task exportDockerImageTask = task(exportTaskName, type: LoggedExec) {
executable 'docker'
args "save",
"-o",
tarFile,
"elasticsearch${oss ? '-oss' : ''}:test"
"elasticsearch${oss ? '-oss' : ''}${ubi ? '-ubi7' : ''}:test"
}

exportDockerImageTask.dependsOn(parent.tasks.getByName(buildTaskName))

artifacts.add('default', file(tarFile)) {
type 'tar'
name "elasticsearch${oss ? '-oss' : ''}"
name "elasticsearch${oss ? '-oss' : ''}${ubi ? '-ubi7' : ''}"
builtBy exportTaskName
}

Expand Down
2 changes: 1 addition & 1 deletion distribution/docker/docker-build-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ task buildDockerBuildContext(type: Tar) {
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch"
with dockerBuildContext(false, false)
with dockerBuildContext(false, false, false)
}

assemble.dependsOn buildDockerBuildContext
2 changes: 1 addition & 1 deletion distribution/docker/oss-docker-build-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ task buildOssDockerBuildContext(type: Tar) {
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-oss"
with dockerBuildContext(true, false)
with dockerBuildContext(true, false, false)
}

assemble.dependsOn buildOssDockerBuildContext
11 changes: 11 additions & 0 deletions distribution/docker/oss-ubi-docker-build-context/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apply plugin: 'base'

task buildOssUbiDockerBuildContext(type: Tar) {
extension = 'tar.gz'
compression = Compression.GZIP
archiveClassifier = "oss-ubi-docker-build-context"
archiveBaseName = "elasticsearch"
with dockerBuildContext(true, true, false)
}

assemble.dependsOn buildOssUbiDockerBuildContext
2 changes: 2 additions & 0 deletions distribution/docker/oss-ubi-docker-export/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// export is done in the parent project.
15 changes: 10 additions & 5 deletions distribution/docker/src/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
# Set gid=0 and make group perms==owner perms
################################################################################

FROM centos:7 AS builder
FROM ${base_image} AS builder

RUN for iter in {1..10}; do ${package_manager} update --setopt=tsflags=nodocs -y && \
${package_manager} install --setopt=tsflags=nodocs -y gzip shadow-utils tar && \
${package_manager} clean all && exit_code=0 && break || exit_code=\$? && echo "${package_manager} error: retry \$iter in 10s" && sleep 10; done; \
(exit \$exit_code)

ENV PATH /usr/share/elasticsearch/bin:\$PATH

Expand All @@ -35,13 +40,13 @@ COPY config/elasticsearch.yml config/log4j2.properties config/
# Add entrypoint
################################################################################

FROM centos:7
FROM ${base_image}

ENV ELASTIC_CONTAINER true

RUN for iter in {1..10}; do yum update --setopt=tsflags=nodocs -y && \
yum install -y --setopt=tsflags=nodocs nc && \
yum clean all && exit_code=0 && break || exit_code=\$? && echo "yum error: retry \$iter in 10s" && sleep 10; done; \
RUN for iter in {1..10}; do ${package_manager} update --setopt=tsflags=nodocs -y && \
${package_manager} install --setopt=tsflags=nodocs -y nc shadow-utils && \
${package_manager} clean all && exit_code=0 && break || exit_code=\$? && echo "${package_manager} error: retry \$iter in 10s" && sleep 10; done; \
(exit \$exit_code)

RUN groupadd -g 1000 elasticsearch && \
Expand Down
11 changes: 11 additions & 0 deletions distribution/docker/ubi-docker-build-context/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apply plugin: 'base'

task buildUbiDockerBuildContext(type: Tar) {
extension = 'tar.gz'
compression = Compression.GZIP
archiveClassifier = "ubi-docker-build-context"
archiveBaseName = "elasticsearch"
with dockerBuildContext(false, true, false)
}

assemble.dependsOn buildUbiDockerBuildContext
2 changes: 2 additions & 0 deletions distribution/docker/ubi-docker-export/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// export is done in the parent project.