@@ -21,29 +21,31 @@ dependencies {
2121 restSpec project(' :rest-api-spec' )
2222}
2323
24- ext. expansions = { oss , local ->
24+ ext. expansions = { oss , ubi , local ->
2525 final String classifier = ' linux-x86_64'
2626 final String elasticsearch = oss ? " elasticsearch-oss-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz" : " elasticsearch-${ VersionProperties.elasticsearch} -${ classifier} .tar.gz"
2727 return [
28+ ' base_image' : ubi ? ' registry.access.redhat.com/ubi7/ubi-minimal:7.7' : ' centos:7' ,
2829 ' build_date' : project. ext. buildDate,
2930 ' elasticsearch' : elasticsearch,
3031 ' git_revision' : project. ext. gitRevision,
3132 ' license' : oss ? ' Apache-2.0' : ' Elastic-License' ,
33+ ' package_manager' : ubi ? ' microdnf' : ' yum' ,
3234 ' source_elasticsearch' : local ? " COPY $elasticsearch /opt/" : " RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${ elasticsearch} && cd -" ,
3335 ' version' : VersionProperties . elasticsearch
3436 ]
3537}
3638
37- private static String files (final boolean oss ) {
38- return " build/${ oss ? 'oss-' : ''} docker"
39+ private static String buildPath (final boolean oss , final boolean ubi ) {
40+ return " build/${ oss ? 'oss-' : ''}${ ubi ? 'ubi-' : '' } docker"
3941}
4042
41- private static String taskName (final String prefix , final boolean oss , final String suffix ) {
42- return " ${ prefix}${ oss ? 'Oss' : ''}${ suffix} "
43+ private static String taskName (final String prefix , final boolean oss , final boolean ubi , final String suffix ) {
44+ return " ${ prefix}${ oss ? 'Oss' : ''}${ ubi ? 'Ubi': '' }${ suffix} "
4345}
4446
4547project. ext {
46- dockerBuildContext = { boolean oss , boolean local ->
48+ dockerBuildContext = { boolean oss , boolean ubi , boolean local ->
4749 copySpec {
4850 into(' bin' ) {
4951 from project. projectDir. toPath(). resolve(" src/docker/bin" )
@@ -55,24 +57,26 @@ project.ext {
5557 * by creating config files in oss or default build-context sub-modules.
5658 */
5759 from project. projectDir. toPath(). resolve(" src/docker/config" )
58- from project. projectDir. toPath(). resolve(oss ? " oss-docker-build-context" : " docker-build-context" ). resolve(" src/docker/config" )
60+ if (oss) {
61+ from project. projectDir. toPath(). resolve(" src/docker/config/oss" )
62+ }
5963 }
6064
6165 from(project. projectDir. toPath(). resolve(" src/docker/Dockerfile" )) {
62- expand(expansions(oss, local))
66+ expand(expansions(oss, ubi, local))
6367 }
6468 }
6569 }
6670}
6771
68- void addCopyDockerContextTask (final boolean oss ) {
69- task(taskName(" copy" , oss, " DockerContext" ), type : Sync ) {
70- expansions(oss, true ). each { k , v ->
72+ void addCopyDockerContextTask (final boolean oss , final boolean ubi ) {
73+ task(taskName(" copy" , oss, ubi, " DockerContext" ), type : Sync ) {
74+ expansions(oss, ubi, true ). each { k , v ->
7175 inputs. property(k, { v. toString() })
7276 }
73- into files (oss)
77+ into buildPath (oss, ubi )
7478
75- with dockerBuildContext(oss, true )
79+ with dockerBuildContext(oss, ubi, true )
7680
7781 if (oss) {
7882 from configurations. ossDockerSource
@@ -144,42 +148,42 @@ task integTest(type: Test) {
144148
145149check. dependsOn integTest
146150
147- void addBuildDockerImage (final boolean oss ) {
148- final Task buildDockerImageTask = task(taskName(" build" , oss, " DockerImage" ), type : LoggedExec ) {
149- dependsOn taskName(" copy" , oss, " DockerContext" )
151+ void addBuildDockerImage (final boolean oss , final boolean ubi ) {
152+ final Task buildDockerImageTask = task(taskName(" build" , oss, ubi, " DockerImage" ), type : LoggedExec ) {
153+ dependsOn taskName(" copy" , oss, ubi, " DockerContext" )
150154 List<String > tags
151155 if (oss) {
152156 tags = [
153- " docker.elastic.co/elasticsearch/elasticsearch-oss:${ VersionProperties.elasticsearch} " ,
154- " elasticsearch-oss:test"
157+ " docker.elastic.co/elasticsearch/elasticsearch-oss:${ VersionProperties.elasticsearch}${ ubi ? '-ubi7' : '' } " ,
158+ " elasticsearch-oss:test${ ubi ? '-ubi7' : '' } "
155159 ]
156160 } else {
157161 tags = [
158- " elasticsearch:${ VersionProperties.elasticsearch} " ,
159- " docker.elastic.co/elasticsearch/elasticsearch:${ VersionProperties.elasticsearch} " ,
160- " docker.elastic.co/elasticsearch/elasticsearch-full:${ VersionProperties.elasticsearch} " ,
161- " elasticsearch:test" ,
162+ " elasticsearch:${ VersionProperties.elasticsearch}${ ubi ? '-ubi7' : '' } " ,
163+ " docker.elastic.co/elasticsearch/elasticsearch:${ VersionProperties.elasticsearch}${ ubi ? '-ubi7' : '' } " ,
164+ " docker.elastic.co/elasticsearch/elasticsearch-full:${ VersionProperties.elasticsearch}${ ubi ? '-ubi7' : '' } " ,
165+ " elasticsearch:test${ ubi ? '-ubi7' : '' } " ,
162166 ]
163167 }
164168 executable ' docker'
165- final List<String > dockerArgs = [' build' , files (oss), ' --pull' , ' --no-cache' ]
169+ final List<String > dockerArgs = [' build' , buildPath (oss, ubi ), ' --pull' , ' --no-cache' ]
166170 for (final String tag : tags) {
167171 dockerArgs. add(' --tag' )
168172 dockerArgs. add(tag)
169173 }
170174 args dockerArgs. toArray()
171175 }
176+ assemble. dependsOn(buildDockerImageTask)
172177 BuildPlugin . requireDocker(buildDockerImageTask)
173178}
174179
175180for (final boolean oss : [false , true ]) {
176- addCopyDockerContextTask(oss)
177- addBuildDockerImage(oss)
181+ for (final boolean ubi : [false , true ]) {
182+ addCopyDockerContextTask(oss, ubi)
183+ addBuildDockerImage(oss, ubi)
184+ }
178185}
179186
180- assemble. dependsOn " buildOssDockerImage"
181- assemble. dependsOn " buildDockerImage"
182-
183187// We build the images used in compose locally, but the pull command insists on using a repository
184188// thus we must disable it to prevent it from doing so.
185189// Everything will still be pulled since we will build the local images on a pull
0 commit comments