-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
235 lines (196 loc) · 7.08 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
apply plugin: 'war'
apply plugin: 'org.hidetake.ssh'
project.ext.set("glueVersion", "1.0.17-maintenance_1.0")
remotes {
gluehome_aws {
host = '52.16.113.119'
user = 'ubuntu'
identity = file('/Users/joshsinger/.ssh/gluehome-aws.pem')
}
}
repositories {
mavenLocal()
}
configurations {
gluetoolsWebWar
gluetoolsWsWar
}
dependencies {
gluetoolsWebWar group: 'cvr.ac.uk', name: 'gluetools-web', version: project.glueVersion, transitive: false
gluetoolsWsWar group: 'cvr.ac.uk', name: 'gluetools-ws', version: project.glueVersion, transitive: false
}
buildscript {
repositories {
// for ssh-deploy stuff
jcenter()
}
dependencies {
classpath group: 'org.hidetake', name: 'gradle-ssh-plugin', version: '1.1.3'
classpath group: 'commons-io', name: 'commons-io', version: '1.3.2'
}
}
war {
webAppDirName = 'WebContent'
archiveName 'hevGlue.war'
}
task copyGluetoolsWebWar(type: Copy) {
from configurations.gluetoolsWebWar
into "$buildDir/runtimeWars"
rename('gluetools-web-'+project.glueVersion+'.war', 'gluetools-web.war')
}
task copyGluetoolsWsWar(type: Copy) {
from configurations.gluetoolsWsWar
into "$buildDir/runtimeWars"
rename('gluetools-ws-'+project.glueVersion+'.war', 'gluetools-ws.war')
}
task deployAll(dependsOn: ['deployGluetoolsWebWarGlueHomeAWS',
'deployGluetoolsWsWarGlueHomeAWS',
'deployHevGlueWarGlueHomeAWS',
'deployHevGlueGluetoolsWsContextXmlGlueHomeAWS',
'deployHevGlueConfigGlueHomeAWS',
'deployHevGlueDbToGlueHomeAWS'])
task deployGluetoolsWebWarGlueHomeAWS(type: DeployWarTask, dependsOn: 'copyGluetoolsWebWar') {
warFile = new File(buildDir, 'runtimeWars/gluetools-web.war')
remote = remotes.gluehome_aws
taskBuildDir = buildDir
warBaseName = org.apache.commons.io.FilenameUtils.getBaseName(warFile.name)
touchFile = new File(taskBuildDir.name, '/deploy.'+warBaseName+'.'+remote.name+'.touchfile')
inputs.file warFile
outputs.file touchFile
taskSsh = ssh
}
task deployGluetoolsWsWarGlueHomeAWS(type: DeployWarTask, dependsOn: 'copyGluetoolsWsWar') {
warFile = new File(buildDir, 'runtimeWars/gluetools-ws.war')
remote = remotes.gluehome_aws
taskBuildDir = buildDir
warBaseName = org.apache.commons.io.FilenameUtils.getBaseName(warFile.name)
touchFile = new File(taskBuildDir, '/deploy.'+warBaseName+'.'+remote.name+'.touchfile')
inputs.file warFile
outputs.file touchFile
taskSsh = ssh
}
task deployHevGlueWarGlueHomeAWS(type: DeployWarTask, dependsOn: war) {
warFile = new File(buildDir, '/libs/hevGlue.war')
remote = remotes.gluehome_aws
taskBuildDir = buildDir
warBaseName = org.apache.commons.io.FilenameUtils.getBaseName(warFile.name)
touchFile = new File(taskBuildDir, '/deploy.'+warBaseName+'.'+remote.name+'.touchfile')
inputs.file warFile
outputs.file touchFile
taskSsh = ssh
}
class DeployWarTask extends DefaultTask {
File warFile
org.hidetake.groovy.ssh.core.Remote remote
File taskBuildDir
String warBaseName
File touchFile
org.hidetake.groovy.ssh.core.Service taskSsh
@TaskAction
def deploy() {
println "Stopping Tomcat"
taskSsh.run {
session(remote) {
execute 'sudo service tomcat7 stop; sleep 10s'
execute 'while true; do tcresult="$(sudo service tomcat7 status)" ; if [[ $tcresult != *"Tomcat servlet engine is running"* ]] ; then break ; fi ; sleep 0.5 ; echo "Tomcat is still running" ; done'
execute 'sleep 5'
}
}
println "Uploading "+warFile
taskSsh.run {
session(remote) {
put from: warFile.absolutePath, into: '/tmp/'+warFile.name
execute 'sudo mkdir -p /var/lib/tomcat7/webapps_hev'
execute 'sudo chmod a+rwx /var/lib/tomcat7/webapps_hev'
execute 'sudo rm -rf /var/lib/tomcat7/webapps_hev/'+warBaseName
execute 'sudo rm -rf /var/lib/tomcat7/webapps_hev/'+warFile.name
execute 'sudo mv /tmp/'+warFile.name+' /var/lib/tomcat7/webapps_hev/'+warFile.name
execute 'sudo rm -rf /var/lib/tomcat7/work/Catalina/hev.glue.cvr.ac.uk/'+warBaseName
execute 'sudo rm -rf /var/cache/tomcat7/Catalina/hev.glue.cvr.ac.uk/'+warBaseName
}
}
println "Starting Tomcat"
taskSsh.run {
session(remote) {
execute 'sudo service tomcat7 start'
}
}
touchFile.delete()
taskBuildDir.mkdirs()
touchFile.createNewFile()
}
}
// config for HEV-GLUE gluetools-ws webapp
task deployHevGlueGluetoolsWsContextXmlGlueHomeAWS() {
ext.file = new File(projectDir, '/gluehome_aws/gluetools-ws-context.xml')
ext.touchfile = new File(buildDir, '/deployGlueWSConfigGlueHomeAWS.touchfile')
inputs.file file
outputs.file touchfile
doLast {
println "Uploading "+file.name
ssh.run {
session(remotes.gluehome_aws) {
put from: file.absolutePath, into: '/tmp/gluetools-ws.xml'
execute 'sudo service tomcat7 stop; sleep 10s'
execute 'sudo mkdir -p /var/lib/tomcat7/conf/Catalina/hev.glue.cvr.ac.uk'
execute 'sudo mv /tmp/gluetools-ws.xml /var/lib/tomcat7/conf/Catalina/hev.glue.cvr.ac.uk/gluetools-ws.xml'
execute 'sudo service tomcat7 start'
}
}
touchfile.delete()
buildDir.mkdirs()
touchfile.createNewFile()
}
}
// config for HEV-GLUE glue engine which tells it where to find its database.
task deployHevGlueConfigGlueHomeAWS {
ext.file = new File(projectDir, '/gluehome_aws/hev-glue-gluetools-config.xml')
ext.touchfile = new File(buildDir, '/deployHevGlueConfigGlueHomeAWS.touchfile')
inputs.file file
outputs.file touchfile
doLast {
println "Uploading "+file.name
ssh.run {
session(remotes.gluehome_aws) {
execute "sudo mkdir -p /opt/gluetools/conf"
put from: file, into: '/tmp'
execute "sudo mv /tmp/hev-glue-gluetools-config.xml /opt/gluetools/conf/"
}
}
touchfile.delete()
buildDir.mkdirs()
touchfile.createNewFile()
}
}
task initHevGlueDBGlueHomeAWS {
doLast {
ssh.run {
session(remotes.gluehome_aws) {
// create user gluetools with correct grants
execute "echo 'GRANT ALL ON HEV_GLUE.* TO \"hevglue\"@\"localhost\" identified by \"hevglue\";' | mysql -u root --password=root123"
// create HEV_GLUE database
execute "echo 'create database HEV_GLUE character set UTF8;' | mysql -u hevglue --password=hevglue"
}
}
}
}
task dumpHevGlueDB(type: Exec) {
standardOutput = new FileOutputStream(new File('/tmp/hev_glue.sql'))
commandLine '/usr/local/mysql/bin/mysqldump', '-u', 'hevglue', '--password=hevglue', 'HEV_GLUE'
}
task zipHevGlueDB(type: Exec, dependsOn: 'dumpHevGlueDB') {
commandLine '/usr/bin/gzip', '-f', '/tmp/hev_glue.sql'
}
task deployHevGlueDbToGlueHomeAWS(dependsOn: 'zipHevGlueDB') {
doLast {
println "Uploading HEV-GLUE DB"
ssh.run {
session(remotes.gluehome_aws) {
put from: '/tmp/hev_glue.sql.gz', into: '/tmp/hev_glue.sql.gz'
execute 'echo "drop database HEV_GLUE; create database HEV_GLUE character set UTF8;" | mysql -u hevglue --password=hevglue HEV_GLUE'
execute 'gunzip -c /tmp/hev_glue.sql.gz | mysql -u hevglue --password=hevglue HEV_GLUE'
execute 'rm /tmp/hev_glue.sql.gz'
}
}
}
}