Introduce aarch64 Docker image (#53936)

This commit introduces the infrastructure needed to build a Docker image
for aarch64.
This commit is contained in:
Jason Tedor 2020-03-23 14:49:42 -04:00
parent bc2289c258
commit bf65bea6f4
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
8 changed files with 81 additions and 30 deletions

View File

@ -0,0 +1,11 @@
apply plugin: 'base'
task buildDockerBuildContext(type: Tar) {
extension = 'tar.gz'
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-aarch64"
with dockerBuildContext("aarch64", false, false)
}
assemble.dependsOn buildDockerBuildContext

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// export is done in the parent project.

View File

@ -0,0 +1,11 @@
apply plugin: 'base'
task buildOssDockerBuildContext(type: Tar) {
extension = 'tar.gz'
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-aarch64-oss"
with dockerBuildContext("aarch64", true, false)
}
assemble.dependsOn buildOssDockerBuildContext

View File

@ -0,0 +1,2 @@
// This file is intentionally blank. All configuration of the
// export is done in the parent project.

View File

@ -1,3 +1,4 @@
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.ElasticsearchDistribution.Flavor
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.VersionProperties
@ -13,19 +14,31 @@ testFixtures.useFixture()
configurations {
dockerPlugins
aarch64DockerSource
dockerSource
aarch64OssDockerSource
ossDockerSource
}
dependencies {
aarch64DockerSource project(path: ":distribution:archives:linux-aarch64-tar")
dockerSource project(path: ":distribution:archives:linux-tar")
aarch64OssDockerSource project(path: ":distribution:archives:oss-linux-aarch64-tar")
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
}
ext.expansions = { oss, local ->
final String classifier = 'linux-x86_64'
ext.expansions = { architecture, oss, local ->
switch (architecture) {
case "aarch64":
case "x64":
break;
default:
throw new IllegalArgumentException("unrecongized architecture [" + architecture + "], must be one of (aarch64|x64)")
}
final String classifier = "aarch64".equals(architecture) ? "linux-aarch64" : "linux-x86_64"
final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}-${classifier}.tar.gz"
return [
'base_image' : "aarch64".equals(architecture) ? "arm64v8/centos:7" : "centos:7",
'build_date' : BuildParams.buildDate,
'elasticsearch' : elasticsearch,
'git_revision' : BuildParams.gitRevision,
@ -35,16 +48,16 @@ ext.expansions = { oss, local ->
]
}
private static String buildPath(final boolean oss) {
return "build/${oss ? 'oss-' : ''}docker"
private static String buildPath(final String architecture, final boolean oss) {
return "build/${"aarch64".equals(architecture) ? 'aarch64-' : ''}${oss ? 'oss-' : ''}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 String architecture, final boolean oss, final String suffix) {
return "${prefix}${"aarch64".equals(architecture) ? 'Aarch64' : ''}${oss ? 'Oss' : ''}${suffix}"
}
project.ext {
dockerBuildContext = { boolean oss, boolean local ->
dockerBuildContext = { String architecture, boolean oss, boolean local ->
copySpec {
into('bin') {
from project.projectDir.toPath().resolve("src/docker/bin")
@ -62,25 +75,33 @@ project.ext {
}
from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
expand(expansions(oss, local))
expand(expansions(architecture, oss, local))
}
}
}
}
void addCopyDockerContextTask(final boolean oss) {
task(taskName("copy", oss, "DockerContext"), type: Sync) {
expansions(oss, true).findAll { it.key != 'build_date' }.each { k, v ->
void addCopyDockerContextTask(final String architecture, final boolean oss) {
task(taskName("copy", architecture, oss, "DockerContext"), type: Sync) {
expansions(architecture, oss, true).findAll { it.key != 'build_date' }.each { k, v ->
inputs.property(k, { v.toString() })
}
into buildPath(oss)
into buildPath(architecture, oss)
with dockerBuildContext(oss, true)
with dockerBuildContext(architecture, oss, true)
if (oss) {
from configurations.ossDockerSource
if ("aarch64".equals(architecture)) {
if (oss) {
from configurations.aarch64OssDockerSource
} else {
from configurations.aarch64DockerSource
}
} else {
from configurations.dockerSource
if (oss) {
from configurations.ossDockerSource
} else {
from configurations.dockerSource
}
}
from configurations.dockerPlugins
@ -149,9 +170,9 @@ task integTest(type: Test) {
check.dependsOn integTest
void addBuildDockerImage(final boolean oss) {
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: DockerBuildTask) {
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", oss, "DockerContext"))
void addBuildDockerImage(final String architecture, final boolean oss) {
final Task buildDockerImageTask = task(taskName("build", architecture, oss, "DockerImage"), type: DockerBuildTask) {
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, oss, "DockerContext"))
dependsOn(copyContextTask)
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
@ -170,11 +191,14 @@ void addBuildDockerImage(final boolean oss) {
}
}
assemble.dependsOn(buildDockerImageTask)
buildDockerImageTask.enabled = Architecture.current().name().toLowerCase().equals(architecture)
}
for (final boolean oss : [false, true]) {
addCopyDockerContextTask(oss)
addBuildDockerImage(oss)
for (final String architecture : ["aarch64", "x64"]) {
for (final boolean oss : [false, true]) {
addCopyDockerContextTask(architecture, oss)
addBuildDockerImage(architecture, oss)
}
}
// We build the images used in compose locally, but the pull command insists on using a repository
@ -192,11 +216,12 @@ subprojects { Project subProject ->
if (subProject.name.contains('docker-export')) {
apply plugin: 'distribution'
final String architecture = subProject.name.contains('aarch64-') ? 'aarch64' : 'x64'
final boolean oss = subProject.name.contains('oss-')
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", architecture, oss, "DockerImage")
def buildTaskName = taskName("build", architecture, oss, "DockerImage")
def tarFile = "${parent.projectDir}/build/elasticsearch${"aarch64".equals(architecture) ? '-aarch64' : ''}${oss ? '-oss' : ''}_test.${VersionProperties.elasticsearch}.docker.tar"
final Task exportDockerImageTask = task(exportTaskName, type: LoggedExec) {
executable 'docker'
@ -211,7 +236,7 @@ subprojects { Project subProject ->
artifacts.add('default', file(tarFile)) {
type 'tar'
name "elasticsearch${oss ? '-oss' : ''}"
name "elasticsearch${"aarch64".equals(architecture) ? '-aarch64' : ''}${oss ? '-oss' : ''}"
builtBy exportTaskName
}

View File

@ -5,7 +5,7 @@ task buildDockerBuildContext(type: Tar) {
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch"
with dockerBuildContext(false, false)
with dockerBuildContext("x64", false, false)
}
assemble.dependsOn buildDockerBuildContext

View File

@ -5,7 +5,7 @@ task buildOssDockerBuildContext(type: Tar) {
compression = Compression.GZIP
archiveClassifier = "docker-build-context"
archiveBaseName = "elasticsearch-oss"
with dockerBuildContext(true, false)
with dockerBuildContext("x64", true, false)
}
assemble.dependsOn buildOssDockerBuildContext

View File

@ -11,7 +11,7 @@
# 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 yum update --setopt=tsflags=nodocs -y && \
yum install --setopt=tsflags=nodocs -y gzip shadow-utils tar && \
@ -41,7 +41,7 @@ RUN chmod 0660 config/elasticsearch.yml config/log4j2.properties
# Add entrypoint
################################################################################
FROM centos:7
FROM ${base_image}
ENV ELASTIC_CONTAINER true