-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
executable file
·201 lines (189 loc) · 7.65 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
import org.apache.tools.ant.filters.ReplaceTokens
import org.codehaus.groovy.runtime.GStringImpl
plugins {
id "org.sonarqube" version "2.7.1"
}
project.ext {
environment = getEnvProperty('env', 'docker') as Object
bundleDir = getEnvProperty('liferay.workspace.home.dir', project.projectDir.toString() + '/bundles')
liferayData = project.projectDir.toString() + '/docker/liferay/data'
liferayMount = project.projectDir.toString() + '/docker/liferay/mount/files'
dockerContainerPrefix = getEnvProperty('liferay.docker.container.prefix', 'oss')
dockerComposeFilePath = getEnvProperty('liferay.docker.compose.path', project.projectDir.toString() + '/docker/docker-compose.yml')
deployFolder = "${bundleDir}/deploy" as GStringImpl
bundleDirectories = [
file("$bundleDir/deploy"),
file("$bundleDir/osgi/deploy"),
file("$bundleDir/osgi/modules"),
file("$liferayData"),
file("$liferayMount")
]
Properties localProperties = new Properties()
localProperties.load(file("${project.projectDir.toString()}/gradle-local.properties").newDataInputStream())
dbName = getLocalProperty(localProperties,'dbName', 'liferay')
dbUser = getLocalProperty(localProperties,'dbUser', 'liferay')
dbPassword = getLocalProperty(localProperties,'dbPassword', 'liferay')
defaultLiferayAdminPassword = getLocalProperty(localProperties,'default.admin.password', 'test')
keyUrl = getLocalProperty(localProperties, 'KEYCLOAK_URL', '')
keyClient = getLocalProperty(localProperties, 'KEYCLOAK_CLIENTID', '')
keySecret = getLocalProperty(localProperties, 'KEYCLOAK_CLIENTSECRET', '')
emailUser = getLocalProperty(localProperties, 'EMAIL_USER', '')
emailPass = getLocalProperty(localProperties, 'EMAIL_PASSWORD','')
downloadUrl = getEnvProperty('DOWNLOAD_URL', '')
downloadName = getEnvProperty('DOWNLOAD_APPNAME', '')
downloadUser = getEnvProperty('DOWNLOAD_APPUSER', '')
downloadPass = getEnvProperty('DOWNLOAD_APPPW', '')
ipgeolocationApiUrl = getEnvProperty('IPGEOLOCATION_APIURL', '')
ipgeolocationApiKey = getEnvProperty('IPGEOLOCATION_APIKEY', '')
sendinblueApiKey = getEnvProperty('SENDINBLUE_API_KEY', '')
sendinblueApiUrl = getEnvProperty('SENDINBLUE_API_URL', '')
sendinblueFolderId = getEnvProperty('SENDINBLUE_FOLDER', '')
licenseUrl = getEnvProperty('LICENSE_URL', '')
licenseUser = getEnvProperty('LICENSE_USER', '')
licensePass = getEnvProperty('LICENSE_PASSWORD', '')
}
task startContainers(
description: 'Start all docker containers',
group: 'docker'
) {
doLast {
exec {
executable 'docker-compose'
args('-p', dockerContainerPrefix, '-f', dockerComposeFilePath, 'up', '--build', '--force-recreate', '-d')
environment('LIFERAY_BUNDLE_DIR', bundleDir)
}
}
}
task startLiferay(
'description': 'Start Liferay stack',
'group': 'docker'
) {
doLast {
delete "$bundleDir"
delete "$liferayMount"
bundleDirectories.forEach {
if (!it.exists()) {
it.mkdirs()
}
}
copy {
from("$projectDir/configs/$environment/")
into("$liferayMount")
include("*.properties")
filter(ReplaceTokens, tokens: [
'MYSQL_DATABASE' : dbName,
'MYSQL_USER' : dbUser,
'MYSQL_PASSWORD' : dbPassword,
'DEFAULT_ADMIN_PASSWORD': defaultLiferayAdminPassword,
'KEYCLOAK_URL' : keyUrl,
'KEYCLOAK_CLIENTID' : keyClient,
'KEYCLOAK_CLIENTSECRET' : keySecret,
'EMAIL_USER' : emailUser,
'EMAIL_PASSWORD' : emailPass,
'DOWNLOAD_URL' : downloadUrl,
'DOWNLOAD_APPNAME' : downloadName,
'DOWNLOAD_APPUSER' : downloadUser,
'DOWNLOAD_APPPW' : downloadPass,
'IPGEOLOCATION_APIURL' : ipgeolocationApiUrl,
'IPGEOLOCATION_APIKEY' : ipgeolocationApiKey,
'SENDINBLUE_API_KEY' : sendinblueApiKey,
'SENDINBLUE_API_URL' : sendinblueApiUrl,
'SENDINBLUE_FOLDER' : sendinblueFolderId,
'LICENSE_URL' : licenseUrl,
'LICENSE_USER' : licenseUser,
'LICENSE_PASSWORD' : licensePass
])
}
copy {
from("$projectDir/configs/$environment/") {
exclude "osgi", "**.properties", "config"
}
into("$liferayMount")
}
copy {
from("$projectDir/configs/common/")
into("$liferayMount/osgi/configs/")
include "**/**"
}
copy {
from("$projectDir/configs/$environment/osgi/configs/")
into("$liferayMount/osgi/configs")
include "*.config"
}
copy {
from("$projectDir/configs/$environment/osgi/modules/")
into("$liferayMount/osgi/modules")
include "*.xml"
}
copy {
from projectDir
into deployFolder
include "license.xml"
}
}
finalizedBy startContainers
}
task stopLiferay(
'description': 'Stop all containers',
'group': 'docker'
) {
doLast {
exec {
executable 'docker-compose'
args('-p', dockerContainerPrefix, '-f', dockerComposeFilePath, 'down', '--rmi', 'local')
}
print "stop"
}
}
task dumpDB(
description: 'Dump the database into the file system.',
group: 'docker'
) {
doLast {
exec {
executable 'docker'
args('exec', '-t', "${dockerContainerPrefix}-mariadb", 'mysqldump', "-u${dbUser}", "-p${dbPassword}",
'--extended-insert=FALSE', '--no-autocommit', '--opt', "${dbName}")
standardOutput new FileOutputStream("${projectDir}/docker/mariadb/docker-entrypoint-initdb.d/${dbName}.sql")
}
exec {
executable 'bash'
args('-c', "sed -i'' -e '1d' ${projectDir}/docker/mariadb/docker-entrypoint-initdb.d/${dbName}.sql")
}
delete("${projectDir}/docker/mariadb/docker-entrypoint-initdb.d/${dbName}.sql-e")
}
}
task geoipDownload{
group = 'Deltares'
description = 'Downloads GeoIp2-Lite database'
doLast {
def bundlePath = ('/liferay/home/geoip2/')
def geoLiteTar = ('GeoLite2-City.tar.gz')
def f = new File(bundlePath + geoLiteTar)
if (!f.exists()) {
new URL('https://geolite.maxmind.com/download/geoip/database/' + geoLiteTar).withInputStream{ i -> f.withOutputStream{ it << i }}
}
copy {
from (tarTree(resources.gzip(bundlePath + geoLiteTar))) {
include "**/*.mmdb"
eachFile { fcd ->
fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1))
}
includeEmptyDirs = false
}
into bundlePath
}
}
}
def getEnvProperty(String propertyName, String defaultValue) {
if (project.hasProperty(propertyName)) {
return project.getProperty(propertyName) ?: defaultValue
}
return defaultValue
}
def getLocalProperty(Properties properties, String propertyName, String defaultValue) {
if (properties.containsKey(propertyName)) {
return properties.get(propertyName) ?: defaultValue
}
return getEnvProperty(propertyName, defaultValue)
}