2019-08-05 06:46:02 -04:00
|
|
|
import com.bettercloud.vault.VaultConfig;
|
|
|
|
import com.bettercloud.vault.Vault;
|
|
|
|
|
|
|
|
initscript {
|
2019-11-14 06:01:23 -05:00
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
classpath 'com.bettercloud:vault-java-driver:4.1.0'
|
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
}
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
boolean USE_ARTIFACTORY = false
|
2019-09-25 07:33:26 -04:00
|
|
|
|
2019-09-30 18:05:07 -04:00
|
|
|
if (System.getenv('VAULT_ADDR') == null) {
|
2019-11-14 06:01:23 -05:00
|
|
|
throw new GradleException("You must set the VAULT_ADDR environment variable to use this init script.")
|
2019-09-30 18:05:07 -04:00
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
|
2019-09-30 18:05:07 -04:00
|
|
|
if (System.getenv('VAULT_ROLE_ID') == null && System.getenv('VAULT_SECRET_ID') == null && System.getenv('VAULT_TOKEN') == null) {
|
2019-11-14 06:01:23 -05:00
|
|
|
throw new GradleException("You must set either the VAULT_ROLE_ID and VAULT_SECRET_ID environment variables, " +
|
|
|
|
"or the VAULT_TOKEN environment variable to use this init script.")
|
2019-08-05 06:46:02 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 18:05:07 -04:00
|
|
|
final String vaultToken = System.getenv('VAULT_TOKEN') ?: new Vault(
|
2019-11-14 06:01:23 -05:00
|
|
|
new VaultConfig()
|
|
|
|
.address(System.env.VAULT_ADDR)
|
|
|
|
.engineVersion(1)
|
|
|
|
.build()
|
|
|
|
)
|
|
|
|
.withRetries(5, 1000)
|
|
|
|
.auth()
|
|
|
|
.loginByAppRole("approle", System.env.VAULT_ROLE_ID, System.env.VAULT_SECRET_ID)
|
|
|
|
.getAuthClientToken();
|
2019-08-05 06:46:02 -04:00
|
|
|
|
|
|
|
final Vault vault = new Vault(
|
2019-11-14 06:01:23 -05:00
|
|
|
new VaultConfig()
|
|
|
|
.address(System.env.VAULT_ADDR)
|
|
|
|
.engineVersion(1)
|
|
|
|
.token(vaultToken)
|
|
|
|
.build()
|
2019-08-05 06:46:02 -04:00
|
|
|
)
|
2019-11-14 06:01:23 -05:00
|
|
|
.withRetries(5, 1000)
|
2019-08-05 06:46:02 -04:00
|
|
|
|
|
|
|
|
2019-09-25 07:33:26 -04:00
|
|
|
if (USE_ARTIFACTORY) {
|
2019-11-14 06:01:23 -05:00
|
|
|
final Map<String, String> artifactoryCredentials = vault.logical()
|
|
|
|
.read("secret/elasticsearch-ci/artifactory.elstc.co")
|
|
|
|
.getData();
|
|
|
|
logger.info("Using elastic artifactory repos")
|
|
|
|
Closure configCache = {
|
|
|
|
return {
|
|
|
|
name "artifactory-gradle-release"
|
|
|
|
url "https://artifactory.elstc.co/artifactory/gradle-release"
|
|
|
|
credentials {
|
|
|
|
username artifactoryCredentials.get("username")
|
|
|
|
password artifactoryCredentials.get("token")
|
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
|
|
|
settingsEvaluated { settings ->
|
|
|
|
settings.pluginManagement {
|
|
|
|
repositories {
|
|
|
|
maven configCache()
|
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
|
|
|
projectsLoaded {
|
|
|
|
allprojects {
|
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
maven configCache()
|
2019-03-26 06:18:21 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
|
|
|
repositories {
|
|
|
|
maven configCache()
|
|
|
|
}
|
2019-03-26 06:18:21 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-09-25 07:33:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
projectsLoaded {
|
2019-11-14 06:01:23 -05:00
|
|
|
rootProject {
|
|
|
|
project.pluginManager.withPlugin('com.gradle.build-scan') {
|
|
|
|
buildScan.server = 'https://gradle-enterprise.elastic.co'
|
2019-08-06 15:05:32 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
}
|
|
|
|
|
2019-09-25 07:33:26 -04:00
|
|
|
|
2019-08-07 16:14:09 -04:00
|
|
|
final String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.url')
|
|
|
|
final boolean buildCachePush = Boolean.valueOf(System.getProperty('org.elasticsearch.build.cache.push', 'false'))
|
|
|
|
|
|
|
|
if (buildCacheUrl) {
|
2019-11-14 06:01:23 -05:00
|
|
|
final Map<String, String> buildCacheCredentials = vault.logical()
|
|
|
|
.read("secret/elasticsearch-ci/gradle-build-cache")
|
|
|
|
.getData();
|
|
|
|
gradle.settingsEvaluated { settings ->
|
|
|
|
settings.buildCache {
|
|
|
|
local {
|
|
|
|
// Disable the local build cache in CI since we use ephemeral workers and it incurs an IO penalty
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
remote(HttpBuildCache) {
|
|
|
|
url = buildCacheUrl
|
|
|
|
push = buildCachePush
|
|
|
|
credentials {
|
|
|
|
username = buildCacheCredentials.get("username")
|
|
|
|
password = buildCacheCredentials.get("password")
|
2019-03-26 06:18:21 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-03-26 06:18:21 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-03-26 06:18:21 -04:00
|
|
|
}
|
2019-08-05 06:46:02 -04:00
|
|
|
|