2018-02-14 01:49:53 -05:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
*/
|
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
2018-02-14 01:49:53 -05:00
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Deb and rpm configuration *
|
|
|
|
*****************************************************************************
|
|
|
|
*
|
2018-02-21 20:46:40 -05:00
|
|
|
* The general strategy here is to build a directory on disk that contains
|
|
|
|
* stuff that needs to be copied into the distributions. This is
|
2018-02-14 01:49:53 -05:00
|
|
|
* important for two reasons:
|
|
|
|
* 1. ospackage wants to copy the directory permissions that it sees off of the
|
|
|
|
* filesystem. If you ask it to create a directory that doesn't already
|
|
|
|
* exist on disk it petulantly creates it with 0755 permissions, no matter
|
|
|
|
* how hard you try to convince it otherwise.
|
|
|
|
* 2. Convincing ospackage to pick up an empty directory as part of a set of
|
|
|
|
* directories on disk is reasonably easy. Convincing it to just create an
|
|
|
|
* empty directory requires more wits than I have.
|
|
|
|
* 3. ospackage really wants to suck up some of the debian control scripts
|
|
|
|
* directly from the filesystem. It doesn't want to process them through
|
|
|
|
* MavenFilteringHack or any other copy-style action.
|
|
|
|
*
|
|
|
|
* The following commands are useful when it comes to check the user/group
|
|
|
|
* and files permissions set within the RPM and DEB packages:
|
|
|
|
*
|
|
|
|
* rpm -qlp --dump path/to/elasticsearch.rpm
|
|
|
|
* dpkg -c path/to/elasticsearch.deb
|
|
|
|
*/
|
|
|
|
|
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
url "https://plugins.gradle.org/m2/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dependencies {
|
2018-02-21 20:46:40 -05:00
|
|
|
classpath 'com.netflix.nebula:gradle-ospackage-plugin:4.7.1'
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
void addProcessFilesTask(String type, boolean oss) {
|
|
|
|
String packagingFiles = "build/packaging/${ oss ? 'oss-' : ''}${type}"
|
2018-02-21 20:46:40 -05:00
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
task("process${oss ? 'Oss' : ''}${type.capitalize()}Files", type: Copy) {
|
2018-02-14 01:49:53 -05:00
|
|
|
into packagingFiles
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
with copySpec {
|
|
|
|
from 'src/common'
|
|
|
|
from "src/${type}"
|
|
|
|
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss))
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
2018-02-14 01:49:53 -05:00
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
into('config') {
|
|
|
|
with configFiles(type, oss)
|
|
|
|
}
|
2018-03-19 15:13:31 -04:00
|
|
|
MavenFilteringHack.filter(it, expansionsForDistribution(type, oss))
|
2018-02-14 01:49:53 -05:00
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
doLast {
|
|
|
|
// create empty dirs, we set the permissions when configuring the packages
|
|
|
|
mkdir "${packagingFiles}/var/run/elasticsearch"
|
|
|
|
mkdir "${packagingFiles}/var/log/elasticsearch"
|
|
|
|
mkdir "${packagingFiles}/var/lib/elasticsearch"
|
|
|
|
mkdir "${packagingFiles}/usr/share/elasticsearch/plugins"
|
|
|
|
}
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
addProcessFilesTask('deb', true)
|
|
|
|
addProcessFilesTask('deb', false)
|
|
|
|
addProcessFilesTask('rpm', true)
|
|
|
|
addProcessFilesTask('rpm', false)
|
2018-02-14 01:49:53 -05:00
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
// Common configuration that is package dependent. This can't go in ospackage
|
|
|
|
// since we have different templated files that need to be consumed, but the structure
|
|
|
|
// is the same
|
2018-02-23 11:03:17 -05:00
|
|
|
Closure commonPackageConfig(String type, boolean oss) {
|
2018-02-21 20:46:40 -05:00
|
|
|
return {
|
2018-02-23 11:03:17 -05:00
|
|
|
dependsOn "process${oss ? 'Oss' : ''}${type.capitalize()}Files"
|
|
|
|
packageName "elasticsearch${oss ? '-oss' : ''}"
|
2018-02-21 20:46:40 -05:00
|
|
|
// Follow elasticsearch's file naming convention
|
2018-02-23 11:03:17 -05:00
|
|
|
archiveName "${packageName}-${project.version}.${type}"
|
2018-02-14 01:49:53 -05:00
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
String prefix = "${oss ? 'oss-' : ''}${type}"
|
|
|
|
destinationDir = file("${prefix}/build/distributions")
|
|
|
|
String packagingFiles = "build/packaging/${prefix}"
|
2018-02-14 01:49:53 -05:00
|
|
|
|
|
|
|
String scripts = "${packagingFiles}/scripts"
|
|
|
|
preInstall file("${scripts}/preinst")
|
|
|
|
postInstall file("${scripts}/postinst")
|
|
|
|
preUninstall file("${scripts}/prerm")
|
|
|
|
postUninstall file("${scripts}/postrm")
|
2018-03-17 07:48:40 -04:00
|
|
|
if (type == 'rpm') {
|
|
|
|
postTrans file("${scripts}/posttrans")
|
|
|
|
}
|
2018-02-14 01:49:53 -05:00
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
// top level "into" directive is not inherited from ospackage for some reason, so we must
|
|
|
|
// specify it again explicitly for copying common files
|
|
|
|
into('/usr/share/elasticsearch') {
|
|
|
|
into('bin') {
|
2018-02-23 11:03:17 -05:00
|
|
|
with binFiles(type, oss)
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
|
|
|
with copySpec {
|
|
|
|
with commonFiles
|
|
|
|
if (type == 'deb') {
|
|
|
|
// Deb gets a copyright file instead.
|
|
|
|
exclude 'LICENSE.txt'
|
|
|
|
}
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
into('modules') {
|
|
|
|
with copySpec {
|
|
|
|
with modulesFiles(oss)
|
|
|
|
// we need to specify every intermediate directory, but modules could have sub directories
|
|
|
|
// and there might not be any files as direct children of intermediates (eg platform)
|
|
|
|
// so we must iterate through the parents, but duplicate calls with the same path
|
|
|
|
// are ok (they don't show up in the built packages)
|
|
|
|
eachFile { FileCopyDetails fcp ->
|
|
|
|
String[] segments = fcp.relativePath.segments
|
|
|
|
for (int i = segments.length - 2; i > 0 && segments[i] != 'modules'; --i) {
|
|
|
|
directory('/' + segments[0..i].join('/'), 0755)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
// ========= config files =========
|
2018-02-14 01:49:53 -05:00
|
|
|
configurationFile '/etc/elasticsearch/elasticsearch.yml'
|
|
|
|
configurationFile '/etc/elasticsearch/jvm.options'
|
|
|
|
configurationFile '/etc/elasticsearch/log4j2.properties'
|
|
|
|
into('/etc/elasticsearch') {
|
2018-02-23 11:03:17 -05:00
|
|
|
dirMode 0750
|
2018-02-14 01:49:53 -05:00
|
|
|
fileMode 0660
|
|
|
|
permissionGroup 'elasticsearch'
|
|
|
|
includeEmptyDirs true
|
|
|
|
createDirectoryEntry true
|
|
|
|
fileType CONFIG | NOREPLACE
|
2018-02-21 20:46:40 -05:00
|
|
|
from "${packagingFiles}/config"
|
|
|
|
}
|
2018-03-19 15:13:31 -04:00
|
|
|
String envFile = expansionsForDistribution(type, false)['path.env']
|
2018-02-21 20:46:40 -05:00
|
|
|
configurationFile envFile
|
|
|
|
into(new File(envFile).getParent()) {
|
|
|
|
fileType CONFIG | NOREPLACE
|
|
|
|
fileMode 0660
|
|
|
|
from "${packagingFiles}/env/elasticsearch"
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
// ========= systemd =========
|
|
|
|
configurationFile '/usr/lib/systemd/system/elasticsearch.service'
|
2018-02-14 01:49:53 -05:00
|
|
|
into('/usr/lib/tmpfiles.d') {
|
|
|
|
from "${packagingFiles}/systemd/elasticsearch.conf"
|
|
|
|
}
|
|
|
|
into('/usr/lib/systemd/system') {
|
|
|
|
fileType CONFIG | NOREPLACE
|
|
|
|
from "${packagingFiles}/systemd/elasticsearch.service"
|
|
|
|
}
|
|
|
|
into('/usr/lib/sysctl.d') {
|
|
|
|
fileType CONFIG | NOREPLACE
|
|
|
|
from "${packagingFiles}/systemd/sysctl/elasticsearch.conf"
|
|
|
|
}
|
2018-02-21 20:46:40 -05:00
|
|
|
|
|
|
|
// ========= sysV init =========
|
2018-02-14 01:49:53 -05:00
|
|
|
configurationFile '/etc/init.d/elasticsearch'
|
|
|
|
into('/etc/init.d') {
|
|
|
|
fileMode 0750
|
|
|
|
fileType CONFIG | NOREPLACE
|
|
|
|
from "${packagingFiles}/init.d/elasticsearch"
|
|
|
|
}
|
|
|
|
|
2018-02-21 20:46:40 -05:00
|
|
|
// ========= empty dirs =========
|
|
|
|
// NOTE: these are created under packagingFiles as empty, but the permissions are set here
|
|
|
|
Closure copyEmptyDir = { path, u, g, mode ->
|
|
|
|
File file = new File(path)
|
|
|
|
into(file.parent) {
|
2018-02-22 14:30:49 -05:00
|
|
|
from "${packagingFiles}/${file.parent}"
|
2018-02-21 20:46:40 -05:00
|
|
|
include file.name
|
2018-02-14 01:49:53 -05:00
|
|
|
includeEmptyDirs true
|
|
|
|
createDirectoryEntry true
|
|
|
|
user u
|
|
|
|
permissionGroup g
|
|
|
|
dirMode mode
|
|
|
|
}
|
|
|
|
}
|
2018-02-21 20:46:40 -05:00
|
|
|
copyEmptyDir('/var/run/elasticsearch', 'elasticsearch', 'elasticsearch', 0755)
|
|
|
|
copyEmptyDir('/var/log/elasticsearch', 'elasticsearch', 'elasticsearch', 0750)
|
|
|
|
copyEmptyDir('/var/lib/elasticsearch', 'elasticsearch', 'elasticsearch', 0750)
|
|
|
|
copyEmptyDir('/usr/share/elasticsearch/plugins', 'root', 'root', 0755)
|
2018-03-22 18:20:46 -04:00
|
|
|
|
|
|
|
// the oss package conflicts with the default distribution and vice versa
|
|
|
|
conflicts('elasticsearch' + (oss ? '' : '-oss'))
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
apply plugin: 'nebula.ospackage-base'
|
|
|
|
|
|
|
|
// this is package indepdendent configuration
|
|
|
|
ospackage {
|
|
|
|
maintainer 'Elasticsearch Team <info@elastic.co>'
|
|
|
|
summary '''
|
|
|
|
Elasticsearch is a distributed RESTful search engine built for the cloud.
|
|
|
|
Reference documentation can be found at
|
|
|
|
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
|
|
|
|
and the 'Elasticsearch: The Definitive Guide' book can be found at
|
|
|
|
https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
|
|
|
|
'''.stripIndent().replace('\n', ' ').trim()
|
|
|
|
url 'https://www.elastic.co/'
|
|
|
|
|
|
|
|
// signing setup
|
|
|
|
if (project.hasProperty('signing.password') && System.getProperty('build.snapshot', 'true') == 'false') {
|
|
|
|
signingKeyId = project.hasProperty('signing.keyId') ? project.property('signing.keyId') : 'D88E42B4'
|
|
|
|
signingKeyPassphrase = project.property('signing.password')
|
|
|
|
signingKeyRingFile = project.hasProperty('signing.secretKeyRingFile') ?
|
|
|
|
project.file(project.property('signing.secretKeyRingFile')) :
|
|
|
|
new File(new File(System.getProperty('user.home'), '.gnupg'), 'secring.gpg')
|
|
|
|
}
|
|
|
|
|
|
|
|
requires('coreutils')
|
|
|
|
|
|
|
|
fileMode 0644
|
|
|
|
dirMode 0755
|
|
|
|
user 'root'
|
|
|
|
permissionGroup 'root'
|
|
|
|
|
|
|
|
into '/usr/share/elasticsearch'
|
|
|
|
with libFiles
|
|
|
|
with noticeFile
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
Closure commonDebConfig(boolean oss) {
|
|
|
|
return {
|
|
|
|
configure(commonPackageConfig('deb', oss))
|
2018-02-21 20:46:40 -05:00
|
|
|
|
2018-04-09 18:20:01 -04:00
|
|
|
if (oss) {
|
|
|
|
license 'ASL 2.0'
|
|
|
|
} else {
|
|
|
|
license 'Elastic License'
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
version = project.version
|
|
|
|
packageGroup 'web'
|
|
|
|
requires 'bash'
|
|
|
|
requires 'libc6'
|
|
|
|
requires 'adduser'
|
2018-02-21 20:46:40 -05:00
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
into('/usr/share/lintian/overrides') {
|
|
|
|
from('src/deb/lintian/elasticsearch')
|
|
|
|
}
|
|
|
|
into('/usr/share/doc/elasticsearch') {
|
|
|
|
from 'src/deb/copyright'
|
|
|
|
fileMode 0644
|
|
|
|
}
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
task buildDeb(type: Deb) {
|
|
|
|
configure(commonDebConfig(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
task buildOssDeb(type: Deb) {
|
|
|
|
configure(commonDebConfig(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
Closure commonRpmConfig(boolean oss) {
|
|
|
|
return {
|
|
|
|
configure(commonPackageConfig('rpm', oss))
|
|
|
|
|
2018-04-09 18:20:01 -04:00
|
|
|
if (oss) {
|
|
|
|
license 'ASL-2.0'
|
|
|
|
} else {
|
|
|
|
license 'Elastic-License'
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
packageGroup 'Application/Internet'
|
|
|
|
requires '/bin/bash'
|
|
|
|
|
|
|
|
prefix '/usr'
|
|
|
|
packager 'Elasticsearch'
|
|
|
|
version = project.version.replace('-', '_')
|
|
|
|
release = '1'
|
|
|
|
arch 'NOARCH'
|
|
|
|
os 'LINUX'
|
|
|
|
distribution 'Elasticsearch'
|
|
|
|
vendor 'Elasticsearch'
|
|
|
|
// TODO ospackage doesn't support icon but we used to have one
|
|
|
|
|
|
|
|
// without this the rpm will have parent dirs of any files we copy in, eg /etc/elasticsearch
|
|
|
|
addParentDirs false
|
|
|
|
|
|
|
|
// Declare the folders so that the RPM package manager removes
|
|
|
|
// them when upgrading or removing the package
|
|
|
|
directory('/usr/share/elasticsearch/bin', 0755)
|
|
|
|
directory('/usr/share/elasticsearch/lib', 0755)
|
|
|
|
directory('/usr/share/elasticsearch/modules', 0755)
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task buildRpm(type: Rpm) {
|
2018-02-23 11:03:17 -05:00
|
|
|
configure(commonRpmConfig(false))
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
task buildOssRpm(type: Rpm) {
|
|
|
|
configure(commonRpmConfig(true))
|
2018-02-21 20:46:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This configures the default artifact for the distribution specific
|
|
|
|
// subprojects. We have subprojects because Gradle project substitutions
|
|
|
|
// can only bind to the default configuration of a project
|
|
|
|
subprojects {
|
|
|
|
apply plugin: 'distribution'
|
|
|
|
|
|
|
|
String buildTask = "build${it.name.replaceAll(/-[a-z]/) { it.substring(1).toUpperCase() }.capitalize()}"
|
|
|
|
ext.buildDist = parent.tasks.getByName(buildTask)
|
|
|
|
artifacts {
|
|
|
|
'default' buildDist
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
// sanity checks if a archives can be extracted
|
|
|
|
File extractionDir = new File(buildDir, 'extracted')
|
|
|
|
task testExtraction(type: LoggedExec) {
|
|
|
|
dependsOn buildDist
|
|
|
|
doFirst {
|
|
|
|
project.delete(extractionDir)
|
|
|
|
extractionDir.mkdirs()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (project.name.contains('deb')) {
|
|
|
|
testExtraction {
|
|
|
|
onlyIf { new File('/bin/dpkg-deb').exists() || new File('/usr/bin/dpkg-deb').exists() || new File('/usr/local/bin/dpkg-deb').exists() }
|
|
|
|
Closure debFilter = { f -> f.name.endsWith('.deb') }
|
|
|
|
commandLine 'dpkg-deb', '-x', "${-> buildDist.outputs.files.filter(debFilter).singleFile}", extractionDir
|
|
|
|
}
|
|
|
|
} else { // rpm
|
|
|
|
testExtraction {
|
|
|
|
onlyIf { new File('/bin/rpm').exists() || new File('/usr/bin/rpm').exists() || new File('/usr/local/bin/rpm').exists() }
|
|
|
|
final File rpmDatabase = new File(extractionDir, 'rpm-database')
|
|
|
|
final File rpmExtracted = new File(extractionDir, 'rpm-extracted')
|
|
|
|
commandLine 'rpm',
|
|
|
|
'--badreloc',
|
|
|
|
'--nodeps',
|
|
|
|
'--noscripts',
|
|
|
|
'--notriggers',
|
|
|
|
'--dbpath',
|
|
|
|
rpmDatabase,
|
|
|
|
'--relocate',
|
|
|
|
"/=${rpmExtracted}",
|
|
|
|
'-i',
|
|
|
|
"${-> buildDist.outputs.files.singleFile}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
check.dependsOn testExtraction
|
|
|
|
}
|