2021-04-09 15:28:18 -04:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* The OpenSearch Contributors require contributions made to
|
|
|
|
* this file be licensed under the Apache-2.0 license or a
|
|
|
|
* compatible open source license.
|
|
|
|
*
|
|
|
|
* Modifications Copyright OpenSearch Contributors. See
|
|
|
|
* GitHub history for details.
|
|
|
|
*/
|
|
|
|
|
2021-03-16 04:53:48 -04:00
|
|
|
import org.opensearch.gradle.Architecture
|
|
|
|
import org.opensearch.gradle.DockerBase
|
|
|
|
import org.opensearch.gradle.LoggedExec
|
|
|
|
import org.opensearch.gradle.VersionProperties
|
|
|
|
import org.opensearch.gradle.docker.DockerBuildTask
|
|
|
|
import org.opensearch.gradle.info.BuildParams
|
|
|
|
import org.opensearch.gradle.testfixtures.TestFixturesPlugin
|
2021-10-26 08:47:59 -04:00
|
|
|
import org.gradle.internal.os.OperatingSystem
|
|
|
|
|
2021-03-16 04:53:48 -04:00
|
|
|
apply plugin: 'opensearch.standalone-rest-test'
|
|
|
|
apply plugin: 'opensearch.test.fixtures'
|
|
|
|
apply plugin: 'opensearch.internal-distribution-download'
|
|
|
|
apply plugin: 'opensearch.rest-resources'
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-09-23 05:48:47 -04:00
|
|
|
testFixtures.useFixture()
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
configurations {
|
2021-04-26 12:40:09 -04:00
|
|
|
arm64DockerSource
|
2021-04-20 12:27:40 -04:00
|
|
|
dockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2021-04-26 12:40:09 -04:00
|
|
|
arm64DockerSource project(path: ":distribution:archives:linux-arm64-tar", configuration:"default")
|
2021-04-20 12:27:40 -04:00
|
|
|
dockerSource project(path: ":distribution:archives:linux-tar", configuration:"default")
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
ext.expansions = { Architecture architecture, DockerBase base, boolean local ->
|
2020-05-12 06:10:05 -04:00
|
|
|
String classifier
|
|
|
|
if (local) {
|
2021-04-26 12:40:09 -04:00
|
|
|
if (architecture == Architecture.ARM64) {
|
|
|
|
classifier = "linux-arm64"
|
2020-08-18 04:27:23 -04:00
|
|
|
} else if (architecture == Architecture.X64) {
|
2021-04-26 12:40:09 -04:00
|
|
|
classifier = "linux-x64"
|
2020-08-18 04:27:23 -04:00
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Unsupported architecture [" + architecture + "]")
|
2020-05-12 06:10:05 -04:00
|
|
|
}
|
|
|
|
} else {
|
2021-03-16 04:53:48 -04:00
|
|
|
/* When sourcing the OpenSearch build remotely, the same Dockerfile needs
|
2020-05-12 06:10:05 -04:00
|
|
|
* to be able to fetch the artifact for any supported platform. We can't make
|
|
|
|
* the decision here. Bash will interpolate the `arch` command for us. */
|
|
|
|
classifier = "linux-\$(arch)"
|
2020-03-23 14:49:42 -04:00
|
|
|
}
|
2020-05-12 06:10:05 -04:00
|
|
|
|
2021-09-21 19:43:35 -04:00
|
|
|
final String opensearch = "opensearch-min-${VersionProperties.getOpenSearch()}-${classifier}.tar.gz"
|
2020-05-12 06:10:05 -04:00
|
|
|
|
|
|
|
/* Both the following Dockerfile commands put the resulting artifact at
|
|
|
|
* the same location, regardless of classifier, so that the commands that
|
|
|
|
* follow in the Dockerfile don't have to know about the runtime
|
|
|
|
* architecture. */
|
2021-03-16 04:53:48 -04:00
|
|
|
String sourceOpenSearch
|
2020-05-12 06:10:05 -04:00
|
|
|
if (local) {
|
2021-03-16 04:53:48 -04:00
|
|
|
sourceOpenSearch = "COPY $opensearch /opt/opensearch.tar.gz"
|
2020-05-12 06:10:05 -04:00
|
|
|
} else {
|
2021-03-16 04:53:48 -04:00
|
|
|
//TODO - replace the URL for OpenSearch when available
|
|
|
|
sourceOpenSearch = """
|
2020-05-12 06:10:05 -04:00
|
|
|
RUN curl --retry 8 -S -L \\
|
2021-03-18 19:14:19 -04:00
|
|
|
--output /opt/opensearch.tar.gz \\
|
2021-03-20 03:26:48 -04:00
|
|
|
<artifacts_link_placeholder>
|
2020-05-12 06:10:05 -04:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:06:13 -05:00
|
|
|
return [
|
2020-08-18 04:27:23 -04:00
|
|
|
'base_image' : base.getImage(),
|
2019-11-01 14:33:11 -04:00
|
|
|
'build_date' : BuildParams.buildDate,
|
|
|
|
'git_revision' : BuildParams.gitRevision,
|
2021-01-30 01:23:18 -05:00
|
|
|
'license' : 'Apache-2.0',
|
2021-02-22 18:08:15 -05:00
|
|
|
'package_manager' : 'yum',
|
2021-03-16 04:53:48 -04:00
|
|
|
'source_opensearch' : sourceOpenSearch,
|
2020-08-18 04:27:23 -04:00
|
|
|
'docker_base' : base.name().toLowerCase(),
|
2021-03-18 19:14:19 -04:00
|
|
|
'version' : VersionProperties.getOpenSearch()
|
2018-12-06 17:06:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
private static String buildPath(Architecture architecture, DockerBase base) {
|
2020-08-18 04:27:23 -04:00
|
|
|
return 'build/' +
|
2021-04-26 12:40:09 -04:00
|
|
|
(architecture == Architecture.ARM64 ? 'arm64-' : '') +
|
2020-08-18 04:27:23 -04:00
|
|
|
'docker'
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
private static String taskName(String prefix, Architecture architecture, DockerBase base, String suffix) {
|
2020-08-18 04:27:23 -04:00
|
|
|
return prefix +
|
2021-04-26 12:40:09 -04:00
|
|
|
(architecture == Architecture.ARM64 ? 'Arm64' : '') +
|
2020-08-18 04:27:23 -04:00
|
|
|
suffix
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
project.ext {
|
2021-02-22 18:08:15 -05:00
|
|
|
dockerBuildContext = { Architecture architecture, DockerBase base, boolean local ->
|
2019-05-06 21:04:13 -04:00
|
|
|
copySpec {
|
|
|
|
into('bin') {
|
|
|
|
from project.projectDir.toPath().resolve("src/docker/bin")
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
into('config') {
|
2021-02-22 18:08:15 -05:00
|
|
|
from project.projectDir.toPath().resolve("src/docker/config")
|
2019-02-08 13:01:59 -05:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2019-05-06 21:04:13 -04:00
|
|
|
from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
|
2021-02-22 18:08:15 -05:00
|
|
|
expand(expansions(architecture, base, local))
|
2019-05-06 21:04:13 -04:00
|
|
|
}
|
2019-02-08 13:01:59 -05:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
void addCopyDockerContextTask(Architecture architecture, DockerBase base) {
|
|
|
|
if (base != DockerBase.CENTOS) {
|
2021-04-20 12:27:40 -04:00
|
|
|
throw new GradleException("The only allowed docker base image for builds is CENTOS")
|
2020-08-18 04:27:23 -04:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
tasks.register(taskName("copy", architecture, base, "DockerContext"), Sync) {
|
|
|
|
expansions(architecture, base, true).findAll { it.key != 'build_date' }.each { k, v ->
|
2019-08-08 20:07:41 -04:00
|
|
|
inputs.property(k, { v.toString() })
|
|
|
|
}
|
2021-02-22 18:08:15 -05:00
|
|
|
into buildPath(architecture, base)
|
2018-12-06 17:06:13 -05:00
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
with dockerBuildContext(architecture, base, true)
|
2019-05-06 21:04:13 -04:00
|
|
|
|
2021-04-26 12:40:09 -04:00
|
|
|
if (architecture == Architecture.ARM64) {
|
|
|
|
from configurations.arm64DockerSource
|
2019-05-06 21:04:13 -04:00
|
|
|
} else {
|
2021-04-20 12:27:40 -04:00
|
|
|
from configurations.dockerSource
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
def createAndSetWritable(Object... locations) {
|
2019-07-11 08:04:25 -04:00
|
|
|
locations.each { location ->
|
|
|
|
File file = file(location)
|
|
|
|
file.mkdirs()
|
|
|
|
file.setWritable(true, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:14:19 -04:00
|
|
|
|
2021-03-16 04:53:48 -04:00
|
|
|
opensearch_distributions {
|
2020-04-15 08:39:18 -04:00
|
|
|
Architecture.values().each { eachArchitecture ->
|
2021-04-26 12:40:09 -04:00
|
|
|
"docker${ eachArchitecture == Architecture.ARM64 ? '_arm64' : '' }" {
|
2021-02-22 18:08:15 -05:00
|
|
|
architecture = eachArchitecture
|
|
|
|
type = 'docker'
|
2021-03-16 04:53:48 -04:00
|
|
|
version = VersionProperties.getOpenSearch()
|
2021-02-22 18:08:15 -05:00
|
|
|
failIfUnavailable = false // This ensures we don't attempt to build images if docker is unavailable
|
2020-02-21 18:24:05 -05:00
|
|
|
}
|
2019-07-11 08:04:25 -04:00
|
|
|
}
|
2020-02-21 18:24:05 -05:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("preProcessFixture").configure {
|
2021-03-16 04:53:48 -04:00
|
|
|
dependsOn opensearch_distributions.docker
|
2021-12-18 10:57:04 -05:00
|
|
|
// always run the task, otherwise the folders won't be created
|
|
|
|
outputs.upToDateWhen {
|
|
|
|
false
|
|
|
|
}
|
2019-07-11 08:04:25 -04:00
|
|
|
doLast {
|
|
|
|
// tests expect to have an empty repo
|
|
|
|
project.delete(
|
2021-04-20 12:27:40 -04:00
|
|
|
"${buildDir}/repo"
|
2019-07-11 08:04:25 -04:00
|
|
|
)
|
|
|
|
createAndSetWritable(
|
2021-04-20 12:27:40 -04:00
|
|
|
"${buildDir}/repo",
|
|
|
|
"${buildDir}/logs/1",
|
|
|
|
"${buildDir}/logs/2"
|
2019-07-11 08:04:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("integTest", Test) {
|
2020-01-30 20:23:23 -05:00
|
|
|
outputs.doNotCacheIf('Build cache is disabled for Docker tests') { true }
|
2019-07-11 08:04:25 -04:00
|
|
|
maxParallelForks = '1'
|
|
|
|
include '**/*IT.class'
|
2019-01-24 10:26:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("check").configure {
|
|
|
|
dependsOn "integTest"
|
|
|
|
}
|
2019-01-24 10:26:42 -05:00
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
void addBuildDockerImage(Architecture architecture, DockerBase base) {
|
|
|
|
if (base != DockerBase.CENTOS) {
|
2021-04-20 12:27:40 -04:00
|
|
|
throw new GradleException("The only allowed docker base image for builds is CENTOS")
|
2020-08-18 04:27:23 -04:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
final TaskProvider<DockerBuildTask> buildDockerImageTask =
|
2021-02-22 18:08:15 -05:00
|
|
|
tasks.register(taskName("build", architecture, base, "DockerImage"), DockerBuildTask) {
|
2021-10-26 08:47:59 -04:00
|
|
|
onlyIf { Architecture.current() == architecture && !OperatingSystem.current().isWindows() }
|
2021-02-22 18:08:15 -05:00
|
|
|
TaskProvider<Sync> copyContextTask = tasks.named(taskName("copy", architecture, base, "DockerContext"))
|
2020-02-27 22:18:53 -05:00
|
|
|
dependsOn(copyContextTask)
|
|
|
|
dockerContext.fileProvider(copyContextTask.map { it.destinationDir })
|
2020-10-21 08:31:32 -04:00
|
|
|
baseImages = [ base.getImage() ]
|
2020-02-27 22:18:53 -05:00
|
|
|
|
2021-03-18 19:14:19 -04:00
|
|
|
String version = VersionProperties.getOpenSearch()
|
2019-11-14 06:01:23 -05:00
|
|
|
tags = [
|
2021-04-20 12:27:40 -04:00
|
|
|
"docker.opensearch.org/opensearch:${version}",
|
|
|
|
"opensearch:test"
|
2019-04-12 05:31:30 -04:00
|
|
|
]
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn(buildDockerImageTask)
|
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
for (final Architecture architecture : Architecture.values()) {
|
2021-04-20 12:27:40 -04:00
|
|
|
// We only create Docker images for the distribution on CentOS.
|
2020-08-18 04:27:23 -04:00
|
|
|
for (final DockerBase base : DockerBase.values()) {
|
2021-02-22 18:08:15 -05:00
|
|
|
if (base == DockerBase.CENTOS) {
|
|
|
|
addCopyDockerContextTask(architecture, base)
|
|
|
|
addBuildDockerImage(architecture, base)
|
2020-08-18 04:27:23 -04:00
|
|
|
}
|
2020-03-23 14:49:42 -04:00
|
|
|
}
|
2018-12-06 17:06:13 -05:00
|
|
|
}
|
|
|
|
|
2019-04-17 01:58:11 -04:00
|
|
|
// We build the images used in compose locally, but the pull command insists on using a repository
|
2019-11-14 06:01:23 -05:00
|
|
|
// thus we must disable it to prevent it from doing so.
|
2019-04-17 01:58:11 -04:00
|
|
|
// Everything will still be pulled since we will build the local images on a pull
|
2019-04-23 07:54:57 -04:00
|
|
|
if (tasks.findByName("composePull")) {
|
2019-11-14 06:01:23 -05:00
|
|
|
tasks.composePull.enabled = false
|
2019-04-23 07:54:57 -04:00
|
|
|
}
|
2019-11-05 10:17:59 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The export subprojects write out the generated Docker images to disk, so
|
2020-08-18 04:27:23 -04:00
|
|
|
* that they can be easily reloaded, for example into a VM for distribution testing
|
2019-11-05 10:17:59 -05:00
|
|
|
*/
|
|
|
|
subprojects { Project subProject ->
|
2020-04-15 08:39:18 -04:00
|
|
|
if (subProject.name.endsWith('-export')) {
|
2019-11-05 10:17:59 -05:00
|
|
|
apply plugin: 'distribution'
|
|
|
|
|
2021-04-26 12:40:09 -04:00
|
|
|
final Architecture architecture = subProject.name.contains('arm64-') ? Architecture.ARM64 : Architecture.X64
|
2021-02-22 18:08:15 -05:00
|
|
|
final DockerBase base = DockerBase.CENTOS
|
2020-08-18 04:27:23 -04:00
|
|
|
|
2021-04-26 12:40:09 -04:00
|
|
|
final String arch = architecture == Architecture.ARM64 ? '-arm64' : ''
|
2021-02-22 18:08:15 -05:00
|
|
|
final String extension = 'docker.tar'
|
2021-04-20 12:27:40 -04:00
|
|
|
final String artifactName = "opensearch${arch}_test"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2021-02-22 18:08:15 -05:00
|
|
|
final String exportTaskName = taskName("export", architecture, base, "DockerImage")
|
|
|
|
final String buildTaskName = taskName("build", architecture, base, "DockerImage")
|
2021-03-18 19:14:19 -04:00
|
|
|
final String tarFile = "${parent.projectDir}/build/${artifactName}_${VersionProperties.getOpenSearch()}.${extension}"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2020-08-18 04:27:23 -04:00
|
|
|
tasks.register(exportTaskName, LoggedExec) {
|
2020-04-24 11:47:24 -04:00
|
|
|
inputs.file("${parent.projectDir}/build/markers/${buildTaskName}.marker")
|
2019-11-05 10:17:59 -05:00
|
|
|
executable 'docker'
|
2019-11-27 14:19:34 -05:00
|
|
|
outputs.file(tarFile)
|
2019-11-05 10:17:59 -05:00
|
|
|
args "save",
|
|
|
|
"-o",
|
|
|
|
tarFile,
|
2021-04-20 12:27:40 -04:00
|
|
|
"opensearch:test"
|
2019-11-05 10:17:59 -05:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
dependsOn(parent.path + ":" + buildTaskName)
|
2021-10-26 08:47:59 -04:00
|
|
|
onlyIf { Architecture.current() == architecture && !OperatingSystem.current().isWindows()}
|
2020-07-31 07:09:04 -04:00
|
|
|
}
|
2020-04-15 08:39:18 -04:00
|
|
|
|
2019-11-05 10:17:59 -05:00
|
|
|
artifacts.add('default', file(tarFile)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
type 'tar'
|
2020-08-18 04:27:23 -04:00
|
|
|
name artifactName
|
2019-11-14 06:01:23 -05:00
|
|
|
builtBy exportTaskName
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn(exportTaskName)
|
|
|
|
}
|
2019-11-05 10:17:59 -05:00
|
|
|
}
|
|
|
|
}
|
2021-12-18 10:57:04 -05:00
|
|
|
|
|
|
|
tasks.named("composeUp").configure {
|
|
|
|
dependsOn preProcessFixture
|
|
|
|
}
|