2017-01-17 09:45:00 -05:00
description = 'Builds the Machine Learning Java classes and UI'
2016-09-16 12:30:45 -04:00
2016-10-31 09:05:32 -04:00
import org.gradle.plugins.ide.eclipse.model.SourceFolder
2016-11-17 09:07:20 -05:00
import org.elasticsearch.gradle.precommit.LicenseHeadersTask
2016-11-22 03:29:13 -05:00
import org.elasticsearch.gradle.VersionProperties
2017-02-07 07:22:34 -05:00
import com.bettercloud.vault.Vault
import com.bettercloud.vault.VaultConfig
import com.bettercloud.vault.response.LogicalResponse
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission
import java.nio.file.attribute.PosixFilePermissions
2017-01-20 10:11:21 -05:00
if ( project . projectDir . name ! = 'prelert-legacy' ) {
throw new GradleException ( 'You must checkout prelert-legacy in the following directory: <path to Elasticsearch checkout>/../elasticsearch-extra/prelert-legacy' )
}
2016-11-17 09:07:20 -05:00
2017-02-07 07:22:34 -05:00
buildscript {
repositories {
mavenCentral ( )
}
dependencies {
classpath group: 'com.bettercloud' , name: 'vault-java-driver' , version: "1.1.0"
}
}
// Vault auth to get keys for access to cpp artifacts
// first need to get an authentication token with vault
File githubToken = project . file ( 'github.token' )
2017-02-07 07:32:38 -05:00
final String VAULT_URL = 'https://secrets.elastic.co:8200'
2017-02-07 07:22:34 -05:00
final String VAULT_ROLE_ID = "8e90dd88-5a8e-9c12-0da9-5439f293ff97"
2017-02-07 07:28:00 -05:00
final String VAULT_SECRET_ID = System . env . VAULT_SECRET_ID
2017-02-07 07:22:34 -05:00
String authBody = null
2017-02-07 07:32:38 -05:00
URL vaultUrl = null
2017-02-07 07:22:34 -05:00
if ( githubToken . exists ( ) ) {
Set < PosixFilePermission > perms = Files . getPosixFilePermissions ( githubToken . toPath ( ) )
if ( perms . equals ( PosixFilePermissions . fromString ( "rw-------" ) ) = = false ) {
throw new GradleException ( 'github.token must have 600 permissions' )
}
2017-02-07 07:32:38 -05:00
vaultUrl = new URL ( VAULT_URL + '/v1/auth/github/login' )
2017-02-07 07:22:34 -05:00
authBody = "{\"token\": \"${githubToken.getText('UTF-8').trim()}\"}"
} else if ( VAULT_SECRET_ID ! = null ) {
2017-02-07 07:32:38 -05:00
vaultUrl = new URL ( VAULT_URL + '/v1/auth/approle/login' )
2017-02-07 07:22:34 -05:00
authBody = "{\"role_id\": \"${VAULT_ROLE_ID}\", \"secret_id\": \"${VAULT_SECRET_ID}\"}"
} else {
2017-02-07 07:32:38 -05:00
throw new GradleException ( 'Missing github.token file or VAULT_SECRET_ID environment variable, needed to authenticate with vault for secrets' )
2016-12-01 11:18:29 -05:00
}
2017-02-07 07:22:34 -05:00
HttpURLConnection vaultConn = ( HttpURLConnection ) vaultUrl . openConnection ( )
vaultConn . setRequestProperty ( 'Content-Type' , 'application/json' )
vaultConn . setRequestMethod ( 'PUT' )
vaultConn . setDoOutput ( true )
vaultConn . outputStream . withWriter ( 'UTF-8' ) { writer - >
writer . write ( authBody )
2016-12-01 11:18:29 -05:00
}
2017-02-07 07:22:34 -05:00
vaultConn . connect ( )
Object authResponse = new groovy . json . JsonSlurper ( ) . parseText ( vaultConn . content . text )
VaultConfig config = new VaultConfig ( VAULT_URL , authResponse . auth . client_token )
Vault vault = new Vault ( config )
LogicalResponse secret = vault . logical ( ) . read ( "aws-dev/creds/prelertartifacts" )
String mlAwsAccessKey = secret . data . get ( 'access_key' )
String mlAwsSecretKey = secret . data . get ( 'secret_key' )
2016-12-01 11:18:29 -05:00
2017-01-17 09:45:00 -05:00
String envCppLocalDists = System . env . CPP_LOCAL_DISTS
if ( envCppLocalDists ! = null ) {
project . ext . cppLocalDists = envCppLocalDists
} else if ( project . hasProperty ( "CPP_LOCAL_DISTS" ) ) {
project . ext . cppLocalDists = CPP_LOCAL_DISTS
2017-01-13 12:42:11 -05:00
} else {
2017-01-17 09:45:00 -05:00
project . ext . cppLocalDists = ''
2017-01-13 12:42:11 -05:00
}
2016-12-02 08:12:57 -05:00
allprojects {
2017-01-10 08:40:16 -05:00
group = 'org.elasticsearch.ml'
2016-11-17 09:07:20 -05:00
}
2016-09-16 12:30:45 -04:00
2016-11-22 03:29:13 -05:00
task bundlePack ( type: Zip ) {
2017-01-23 09:09:22 -05:00
onlyIf { project ( ':prelert-legacy:kibana' ) . bundlePlugin . enabled }
dependsOn ':prelert-legacy:elasticsearch:bundlePlugin'
dependsOn ':prelert-legacy:kibana:bundlePlugin'
from { zipTree ( project ( ':prelert-legacy:elasticsearch' ) . bundlePlugin . outputs . files . singleFile ) }
from { zipTree ( project ( ':prelert-legacy:kibana' ) . bundlePlugin . outputs . files . singleFile ) }
2016-11-22 03:29:13 -05:00
destinationDir file ( 'build/distributions' )
2017-01-19 11:14:08 -05:00
baseName = 'ml'
2017-01-20 10:11:21 -05:00
version = VersionProperties . elasticsearch
}
subprojects {
plugins . withType ( MavenPublishPlugin ) . whenPluginAdded {
publishing {
publications {
// add license information to generated poms
all {
pom . withXml { XmlProvider xml - >
Node node = xml . asNode ( )
Node license = node . appendNode ( 'licenses' ) . appendNode ( 'license' )
license . appendNode ( 'name' , 'Elastic Commercial Software End User License Agreement' )
license . appendNode ( 'url' , 'https://www.elastic.co/eula/' )
license . appendNode ( 'distribution' , 'repo' )
Node developer = node . appendNode ( 'developers' ) . appendNode ( 'developer' )
developer . appendNode ( 'name' , 'Elastic' )
developer . appendNode ( 'url' , 'http://www.elastic.co' )
}
}
}
}
}
2016-11-22 03:29:13 -05:00
}
task assemble ( dependsOn: bundlePack ) {
group = 'Build'
description = 'Assembles the outputs of this project.'
}
2017-01-24 09:48:03 -05:00
task build ( dependsOn: assemble ) {
group = 'Build'
description = 'Assembles and tests this project.'
}
2017-01-23 09:09:22 -05:00
task test ( dependsOn: [ ':prelert-legacy:elasticsearch:test' , ':prelert-legacy:kibana:test' ] ) {
2016-12-01 10:48:51 -05:00
group = 'Build'
description = 'Assembles and tests this project.'
}
2016-11-22 03:29:13 -05:00
task clean ( type: Delete ) {
group = 'Build'
description = 'Deletes the build directory'
delete 'build'
}
2016-09-16 12:30:45 -04:00
subprojects {
2017-01-20 10:11:21 -05:00
tasks . withType ( LicenseHeadersTask . class ) {
approvedLicenses = [ 'Elasticsearch Confidential' ]
additionalLicense 'ESCON' , 'Elasticsearch Confidential' , 'ELASTICSEARCH CONFIDENTIAL'
}
ext . projectSubstitutions + = [ "org.elasticsearch.plugin:ml-api:${version}" : ':prelert-legacy:elasticsearch' ]
}
allprojects {
repositories {
2016-11-07 04:27:22 -05:00
if ( System . getProperty ( "repos.mavenlocal" ) ! = null ) {
// with -Drepos.mavenlocal=true we can force checking the local .m2 repo which is useful for building against
// elasticsearch snapshots
mavenLocal ( )
}
2017-01-19 10:22:55 -05:00
maven {
url "s3://prelert-artifacts/maven"
credentials ( AwsCredentials ) {
2017-01-19 11:14:08 -05:00
accessKey "${mlAwsAccessKey}"
secretKey "${mlAwsSecretKey}"
2017-01-19 10:22:55 -05:00
}
}
2016-11-07 04:27:22 -05:00
mavenCentral ( )
maven {
name 'sonatype-snapshots'
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter ( )
2016-09-16 12:30:45 -04:00
}
2016-10-31 09:05:32 -04:00
}