"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/distribution/docker/build.gradle" (29 Dec 2021, 3973 Bytes) of package /linux/www/elasticsearch-6.8.23-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Java source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import org.elasticsearch.gradle.BuildPlugin
    2 import org.elasticsearch.gradle.LoggedExec
    3 import org.elasticsearch.gradle.MavenFilteringHack
    4 import org.elasticsearch.gradle.VersionProperties
    5 
    6 apply plugin: 'base'
    7 apply plugin: 'elasticsearch.test.fixtures'
    8 
    9 configurations {
   10   dockerPlugins
   11   dockerSource
   12   ossDockerSource
   13 }
   14 
   15 dependencies {
   16   dockerSource project(path: ":distribution:archives:tar")
   17   ossDockerSource project(path: ":distribution:archives:oss-tar")
   18 }
   19 
   20 ext.expansions = { oss, local ->
   21   final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}.tar.gz"
   22   return [
   23     'build_date'          : project.buildDate,
   24     'elasticsearch'       : elasticsearch,
   25     'git_revision'        : project.gitRevision,
   26     'jdkUrl'              : 'https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.1%2B9/OpenJDK15U-jdk_x64_linux_hotspot_15.0.1_9.tar.gz',
   27     'jdkVersion'          : '15.0.1+9',
   28     'license'             : oss ? 'Apache-2.0' : 'Elastic-License',
   29     'source_elasticsearch': local ? "COPY $elasticsearch /opt/" : "RUN cd /opt && curl --retry 8 -s -L -O https://artifacts-no-kpi.elastic.co/downloads/elasticsearch/${elasticsearch} && cd -",
   30     'version'             : VersionProperties.elasticsearch
   31   ]
   32 }
   33 
   34 private static String files(final boolean oss) {
   35   return "build/${ oss ? 'oss-' : ''}docker"
   36 }
   37 
   38 private static String taskName(final String prefix, final boolean oss, final String suffix) {
   39   return "${prefix}${oss ? 'Oss' : ''}${suffix}"
   40 }
   41 
   42 project.ext {
   43   dockerBuildContext = { boolean oss, boolean local ->
   44     copySpec {
   45       into('bin') {
   46         from project.projectDir.toPath().resolve("src/docker/bin")
   47       }
   48 
   49       into('config') {
   50         from project.projectDir.toPath().resolve("src/docker/config")
   51       }
   52 
   53       from(project.projectDir.toPath().resolve("src/docker/Dockerfile")) {
   54         MavenFilteringHack.filter(it, expansions(oss, local))
   55       }
   56     }
   57   }
   58 }
   59 
   60 void addCopyDockerContextTask(final boolean oss) {
   61   task(taskName("copy", oss, "DockerContext"), type: Sync) {
   62     inputs.properties(expansions(oss, true))
   63     into files(oss)
   64 
   65     with dockerBuildContext(oss, true)
   66 
   67     if (oss) {
   68       from configurations.ossDockerSource
   69     } else {
   70       from configurations.dockerSource
   71     }
   72 
   73     from configurations.dockerPlugins
   74   }
   75 }
   76 
   77 preProcessFixture {
   78   dependsOn taskName("copy", true, "DockerContext")
   79   dependsOn taskName("copy", false, "DockerContext")
   80 }
   81 
   82 postProcessFixture.doLast {
   83   println "docker default distro is on port: ${ext."test.fixtures.elasticsearch-default.tcp.9200"}, " +
   84           "oss is on: ${ext."test.fixtures.elasticsearch-oss.tcp.9200"}"
   85 }
   86 
   87 // TODO: Add some actual tests, this will just check that the TPC port in the container is up
   88 check.dependsOn postProcessFixture
   89 
   90 void addBuildDockerImage(final boolean oss) {
   91   final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
   92     dependsOn taskName("copy", oss, "DockerContext")
   93     List<String> tags
   94     if (oss) {
   95       tags = [ "docker.elastic.co/elasticsearch/elasticsearch-oss:${VersionProperties.elasticsearch}" ]
   96     } else {
   97       tags = [
   98         "elasticsearch:${VersionProperties.elasticsearch}",
   99         "docker.elastic.co/elasticsearch/elasticsearch:${VersionProperties.elasticsearch}",
  100         "docker.elastic.co/elasticsearch/elasticsearch-full:${VersionProperties.elasticsearch}"
  101       ]
  102     }
  103     executable 'docker'
  104     final List<String> dockerArgs = ['build', files(oss), '--pull', '--no-cache']
  105     for (final String tag : tags) {
  106       dockerArgs.add('--tag')
  107       dockerArgs.add(tag)
  108     }
  109     args dockerArgs.toArray()
  110   }
  111   BuildPlugin.requireDocker(buildDockerImageTask)
  112 }
  113 
  114 for (final boolean oss : [false, true]) {
  115   addCopyDockerContextTask(oss)
  116   addBuildDockerImage(oss)
  117 }
  118 
  119 assemble.dependsOn "buildOssDockerImage"
  120 assemble.dependsOn "buildDockerImage"