forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
142 lines (119 loc) · 4.41 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 specific language governing permissions and
* limitations under the License.
*/
plugins {
id 'org.apache.beam.module'
// https://github.com/avast/gradle-docker-compose-plugin
id 'com.avast.gradle.docker-compose'
id 'org.ajoberstar.grgit'
}
ext {
cluster = 'metrics'
zone='us-central1-a'
projectName='apache-beam-testing'
kubeConfigPath = project.properties['KUBE_CONFIG_PATH'] ?: '/home/jenkins/.kube/config'
}
applyGroovyNature()
repositories { mavenCentral() }
dependencies {
testImplementation library.groovy.groovy_all
testImplementation library.java.junit
}
task testMetricsStack {
doLast {
// TODO(BEAM-5837): Add some actual validation of the metrics stack
println "Hello world!" }
}
// Create an empty file and set DOCKER_CONFIG to ignore bad config file on Jenkins nodes. BEAM-7405
task createEmptyConfig(type: Exec) {
outputs.file("${project.rootProject.buildDir}/config.json")
commandLine '/bin/sh', '-c', "echo '{}' > ${project.rootProject.buildDir}/config.json"
}
composeUp {
dependsOn "createEmptyConfig"
}
dockerCompose {
environment.put 'DOCKER_CONFIG', project.rootProject.buildDir
}
dockerCompose.isRequiredBy(testMetricsStack)
task getClusterCredentials(type: Exec) {
commandLine 'sh', '-c', "gcloud container clusters get-credentials ${cluster} --zone ${zone} --project ${projectName}"
}
task removeKubeConfig(type: Exec) {
commandLine 'sh', '-c', "rm ${kubeConfigPath}"
}
task validateK8sConfiguration(type: Exec) {
commandLine 'sh', '-c', 'kubectl --namespace default apply --dry-run=client -Rf kubernetes'
}
task validateConfiguration {
dependsOn getClusterCredentials
dependsOn validateK8sConfiguration
finalizedBy removeKubeConfig
}
task preCommit {
dependsOn validateConfiguration
dependsOn testMetricsStack
}
task checkLastCommitId {
doLast {
assert grgit : 'Cannot use outside of git repository'
def git = grgit.open(currentDir: project.rootDir)
def lastCommit = git.log(paths: ['.test-infra/metrics'], maxCommits: 1)[0]
project.ext.lastCommitId = lastCommit.abbreviatedId
}
}
// Checks if Grafana deployment needs to be updated and deploys changes, if necessary.
// Grafana's images tags keep track of the last commit ID in `.test-infra/metrics` path.
// The deployment needs to be updated if new commit appears.
task deploy {
dependsOn checkLastCommitId
doLast {
def stdout = new ByteArrayOutputStream()
exec {
executable 'sh'
args '-c', 'kubectl --namespace default get deployment beamgrafana -o jsonpath="{..image}"'
standardOutput = stdout
}
// All images have the same tag, it doesn't matter which we choose.
String image = (stdout.toString().split(' ') as List)[0]
String currentImageTag = (image.split(':') as List)[1]
println "Current image tag: ${currentImageTag}"
println "Last commit ID: ${lastCommitId}"
Boolean updateRequired = lastCommitId != currentImageTag
if (updateRequired) {
// Build new images and force Kubernetes to re-pull images for Grafana deployment.
exec {
commandLine './build_and_publish_containers.sh', 'true', "${project.lastCommitId}"
}
exec {
executable 'sh'
args '-c', "kubectl --namespace default set image deployment/beamgrafana \
beamgrafana=gcr.io/apache-beam-testing/beamgrafana:${project.lastCommitId} \
beammetricssyncjenkins=gcr.io/apache-beam-testing/beammetricssyncjenkins:${project.lastCommitId} \
beammetricssyncgithub=gcr.io/apache-beam-testing/beammetricssyncgithub:${project.lastCommitId}"
}
} else {
println 'Nothing to do, exiting.'
}
}
}
task checkProber(type: Test) {
include "**/ProberTests.class"
}
project.test {
exclude "**/ProberTests.class"
}