build.gradle 6.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
buildscript {
	ext {
		springBootVersion = '1.5.9.RELEASE'
	}

	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
		classpath "com.moowork.gradle:gradle-node-plugin:1.2.0"
        classpath 'org.hidetake:gradle-ssh-plugin:2.9.0'
	}

	repositories {
13
14
        mavenLocal()
		maven {	url "https://plugins.gradle.org/m2/" }
15
16
17
18
	}
}

enum Environment{
19
    localdev, localtest, dev , test , prod
20
21
}

rajkumar's avatar
rajkumar committed
22
ext.version_base = '1.0.5'
23
ext.environment = project.hasProperty('env') ? env : Environment.dev.toString()
Josue Martinez Villacorta's avatar
Josue Martinez Villacorta committed
24
version = version_base + "-$ext.environment"
25
group = 'uk.ac.ebi.ena.webin-portal'
26

27
28
ext.sshKeyFile = file(hasProperty('sshKeyFile') ? sshKeyFile : "${System.properties['user.home']}/.ssh/id_rsa.ppk")

29
ext.gitlab_project_id ='977'
30

31
32
33
34
35
36
ext.envAngularBuildScriptMap = [
        'test'   : 'buildTest',
        'dev'    : 'buildDev',
        'prod'   : 'buildProd',
        'default': 'build'
]
Josue Martinez Villacorta's avatar
Josue Martinez Villacorta committed
37
38
39
printSetup()


40
41
42
43
def props = new Properties()
file('src/main/resources/application.properties').withInputStream {
    props.load(it)
}
44
45
ext.serverContextPath = removeLeadingSlash(props['server.contextPath'])
ext.serverPort = props['server.port']
46
47
48
49
50
51
52
53
54

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.moowork.node'
apply plugin: 'org.hidetake.ssh'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
55
sourceSets.main.resources.includes = [ "**/*.*" ]
56
57

repositories {
58
59
60
    mavenLocal()
    maven { url "https://gitlab.ebi.ac.uk/api/v4/groups/enasequence/-/packages/maven" }
    mavenCentral()
61
62
63
64
}

dependencies {
	compile('org.springframework.boot:spring-boot-starter-web')
65
    compile 'org.springframework.boot:spring-boot-starter-actuator'
66
67
68
69
	testCompile('org.springframework.boot:spring-boot-starter-test')
}

node {
rajkumar's avatar
rajkumar committed
70
    version = "10.9.0"
71
72
73
74
    download = true
    nodeModulesDir = file("frontend")
}

75
76
77
78
79
80
processResources {
    filesMatching('application*.properties') {
        expand(project.properties)
    }
}

81
82
83
84
85
86
87
88
89
jar {
    manifest {
        attributes(
                'Implementation-Title': project.name,
                'Implementation-Version': project.version,
                'Built-By': System.getProperty('user.name'),
                'Built-Date': new Date(),
                'Source-Compatibility': project.sourceCompatibility)
    }
90
91
}

92
93
94
task sourceJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
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

remotes {
    dev {
        host = 'ves-ebi-5b.ebi.ac.uk'
        user = 'ena_adm'
        identity = sshKeyFile
        knownHosts = allowAnyHosts
    }
    test {
        host = 'ves-ebi-5a'
        user = 'ena_adm'
        identity = sshKeyFile
        knownHosts = allowAnyHosts
    }
    prodA {
        host = 'ves-hx-5a'
        user = 'ena_adm'
        identity = sshKeyFile
        knownHosts = allowAnyHosts
    }
    prodB {
        host = 'ves-hx-5b'
        user = 'ena_adm'
        identity = sshKeyFile
        knownHosts = allowAnyHosts
    }
}

125

126
127
128
129
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
130
            artifact sourceJar
131
132
133
134
        }
    }
    repositories {
        maven {
135
            // Project specific maven repository in Gitlab.
Josue Martinez Villacorta's avatar
Josue Martinez Villacorta committed
136
            url "https://gitlab.ebi.ac.uk/api/v4/projects/${gitlab_project_id}/packages/maven"
137
138
139
            // Developer token in Gitlab.
            credentials(HttpHeaderCredentials) {
                name = "Private-Token"
rajkumar's avatar
rajkumar committed
140
                value = project.ext.properties.gitlab_private_token
141
142
143
            }
            authentication {
                header( HttpHeaderAuthentication )
144
145
146
147
148
149
            }
        }
    }
}


150
151
wrapper{
    gradleVersion = '5.2.1'
152
153
}

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
task buildClientWatch(type: NpmTask, dependsOn: 'npmInstall'){
            group = 'application'
            description = "Build and watches the client side assets for rebuilding"
            args = ['run','buildWatch']
        }

task buildClient(type:NpmTask, dependsOn:'npmInstall'){
            println 'buildClient script:' + getAngularBuildScript()
            group = 'build'
            description = "Compile client side folder for production"
            args = ['run', getAngularBuildScript()]
        }




170

171
def getEnvRemotes() {
172
    def hosts = []
173
    switch (environment){
174
175
        case "dev": hosts.add(remotes.dev) ; break
        case "test": hosts.add(remotes.test) ; break
176
        case "prod":
177
178
179
            hosts.add(remotes.prodA)
            hosts.add(remotes.prodB)
            break
180
    }
181
    return hosts
182
183
184
185
}


def getAngularBuildScript(){
186
187
    def script = envAngularBuildScriptMap[environment.toString()]
    if(script) return script
188
189
190
191
    else return envAngularBuildScriptMap['default']
}


192

193
task deploy() {
194
    doLast{
195
        ssh.run {
196
197
            println("execute" + "~/ena/generic-deploy.sh $project.group $project.name $version $environment $serverPort $serverContextPath")
            for (remote in getEnvRemotes()){
198
199
                println("Deploying into: " + remote)
                session(remote) {
200
                    execute "~/ena/generic-deploy.sh $project.group $project.name $version $environment $serverPort $serverContextPath"
201
                }
202
203
204
205
206
207
            }
        }
    }
}


208
209
210
211
task restartDev(){
    doLast{
        restart(remotes.dev)
    }
212
213
}

214
215
216
217
218
task restartTest(){
    doLast{
        restart(remotes.test)
    }
}
219

220
221
222
223
224
225
task restartProd(){
    doLast{
        restart(remotes.prodA)
        restart(remotes.prodB)
    }
}
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259


def restart(remote){
    ssh.run {
        session(remote) {
            println "Restarting app"
            def result = execute "monit restart $project.name"
            println result
        }
    }
}



task displayInfo(){
    doLast{
        displayInfo(remotes.dev)
        displayInfo(remotes.test)
        displayInfo(remotes.prodA)
        displayInfo(remotes.prodB)
    }
}

def displayInfo(remote){
    println ""
    println "Remote:$remote, host:$remote.host"
    println "Info and health status"
    doGet(getInfoURL(remote))
    doGet(getHealthURL(remote))
    println ""
}


260
def doGet(String url){
261
    try {
262
        println url
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
        println(new URL(url).text)
    }
    catch(all){
        print all.getMessage()
    }
}

def getInfoURL(remote){
    return getBaseURL(remote) + "/info"
}

def getHealthURL(remote){
    return getBaseURL(remote) + "/health"
}


def getBaseURL(remote){
    return "http://${remote.host}:${serverPort}/${serverContextPath}"
}


284
static def removeLeadingSlash(url){
285
286
    if(url.substring(0,1) == "/" )return url.substring(1)
    return url
287
288
}

289
290
291
292
293
// javascript unit testing
task testUnit(type: NpmTask) {
    args = ['run' , 'testHeadLess']
}
//include js unit tests into project build lifecycle
294

Josue Martinez Villacorta's avatar
Josue Martinez Villacorta committed
295
296
def printSetup(){
    println()
297
298
299
300
301
    println("ENVIRONMENT:" + ext.environment)
    println("VERSION:" + version)
    println("VERSION BASE:" + version_base)
    println("GROUP:" + group)
    println("KEY FILE::" + ext.sshKeyFile)
Josue Martinez Villacorta's avatar
Josue Martinez Villacorta committed
302
303
304
    println()
}

305
306
deploy.dependsOn(publish)
publish.dependsOn(assemble)
307
308
bootRepackage.dependsOn(buildClient)
bootRun.dependsOn(bootRepackage)
309
jar.dependsOn(buildClient)
310
compileJava.dependsOn(clean)
311
312
313
test.dependsOn testUnit